12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- from django.shortcuts import render
- from django.http import HttpResponse, HttpResponseRedirect
- from .models import Book, User
- from .forms import NewBookForm, BookManageForm
- # Create your views here.
- def index(request):
- book = Book
- filter_rule = ''
- try:
- filter_rule = 'category=' + request.GET['category']
- except:
- None
- try:
- filter_rule = filter_rule + ','+ 'status=' + request.GET['status']
- except:
- None
- if filter_rule == '':
- book_list = Book.getList(book)
- else:
- book_list = Book.search_filter(book, filter_rule)
- return render(request, 'library/index.html', {'book_list': book_list})
- def newbook(request):
- if request.method == 'POST':
- newBookForm = NewBookForm(request.POST)
- if newBookForm.is_valid():
- book = Book
- book.name = newBookForm.cleaned_data['name'].strip()
- book.category = newBookForm.cleaned_data['category'].strip()
- book.description = newBookForm.cleaned_data['description'].strip()
- book.create_new(book)
- return render(request, 'library/directPage.html', {'alertMsg': '新书添加成功。', 'dirLink': '/cq/library'})
- else:
- return render(request, 'library/newbook.html', {'new_book_form':NewBookForm})
- else:
- return render(request, 'library/newbook.html', {'new_book_form': NewBookForm})
- def newuser(request):
- return render(request, 'library/newuser.html')
- def bookmanage(request):
- if request.method == 'POST':
- bookManageForm = BookManageForm(request.POST)
- if bookManageForm.is_valid():
- book = Book
- book.ID = bookManageForm.cleaned_data['ID']
- book.name = bookManageForm.cleaned_data['name'].strip()
- book.category = bookManageForm.cleaned_data['category'].strip()
- book.description = bookManageForm.cleaned_data['description'].strip()
- book.writer = bookManageForm.cleaned_data['writer'].strip()
- book.serial_number = 'YYSCDJWXYS' + str(bookManageForm.cleaned_data['serial_number']).zfill(4)
- if bookManageForm.cleaned_data['borrower'].strip() == '':
- book.status = '在库'
- book.borrower = ''
- book.borrower_phone = None
- else:
- book.status = '外借'
- book.borrower = bookManageForm.cleaned_data['borrower'].strip()
- book.borrower_phone = bookManageForm.cleaned_data['borrower_phone']
- import datetime
- book.borrow_time = datetime.date.today()
- book.update(book)
- return render(request, 'library/directPage.html', {'alertMsg': '书籍管理成功。', 'dirLink': '/cq/library'})
- else:
- return render(request, 'library/bookmanage.html', {'book_manage_form': BookManageForm})
- else:
- book = Book
- book.ID = request.GET['ID']
- book = Book.search_by_ID(book)
- bookManageForm = BookManageForm(initial={'ID':book[0].ID, 'name':book[0].name, 'description':book[0].description, 'category':book[0].category,
- 'borrower':book[0].borrower, 'borrower_phone':book[0].borrower_phone, 'writer':book[0].writer, 'serial_number':int(book[0].serial_number[-4:])})
- return render(request, 'library/bookmanage.html', {'book_manage_form': bookManageForm})
- def intro(request):
- return render(request, 'library/intro.html')
|