コード例 #1
0
ファイル: views.py プロジェクト: zeizyy/textbook-exchange
def createRequest(request):
	user_id = request.session['current_user']
	user = User.objects.get(pk=user_id)
	if request.POST:
		request_form = RequestForm(request.POST)
		if request_form.is_valid():
			request_form=RequestForm(data=request.POST)
			request = request_form.save()
			request.user = user
			request.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})
コード例 #2
0
ファイル: views.py プロジェクト: zeizyy/textbook-exchange
def editRequest(request, request_id):
	try:
		user_id = request.session['current_user']
		user = User.objects.get(pk=user_id)
	except:
		user = ""
	try:
		requests = Request.objects.get(id=request_id)
	except Request.DoesNotExist:
		raise Http404("The request does not exist!")
	if requests.user == user:
		if request.POST:
			request_form = RequestForm(request.POST,instance=requests)
			if request_form.is_valid():
				requests = request_form.save()
				requests.save()
				return HttpResponseRedirect(reverse('exchange.views.viewRequest',args=[requests.id]))
		else:
			request_form = RequestForm(instance=requests)
	else:
		return render_to_response('exchange/bi.html')
	return render_to_response('exchange/editRequest.html',{'request_form':request_form,'request':requests})