Exemplo n.º 1
0
def createBook(request):
	try:
		user_id = request.session['current_user']
		user = User.objects.get(pk=user_id)
	except:
		return HttpResponseRedirect(reverse('exchange.views.login'))

	if not user.contact:
		return render_to_response('exchange/contactForm.html')
	
	if request.POST:
		book_form = BookForm(request.POST)
		if book_form.is_valid():
			book_form=BookForm(data=request.POST)
			book = book_form.save()
			book.user = user
			book.save()
			return HttpResponseRedirect('/')
	book_form = BookForm()
	request_form = RequestForm()
	return render_to_response('exchange/bookForm.html',{'book_form':book_form,'request_form':request_form,'user':user})
Exemplo n.º 2
0
def editBook(request, book_id):
	try:
		user_id = request.session['current_user']
		user = User.objects.get(pk=user_id)
	except:
		user = ""
	try:
		book = Book.objects.get(id=book_id)
	except Book.DoesNotExist:
		raise Http404("The textbook does not exist!")
	if book.user == user:
		if request.POST:
			book_form = BookForm(request.POST,instance=book)
			if book_form.is_valid():
				book = book_form.save()
				book.save()
				return HttpResponseRedirect(reverse('exchange.views.viewBook',args=[book.id]))
		else:
			book_form = BookForm(instance=book)
	else:
		return render_to_response('exchange/bi.html')
	return render_to_response('exchange/editBook.html',{'book_form':book_form,'book':book})