예제 #1
0
파일: views.py 프로젝트: ethernetdan/sinq
def question_edit(request, question_id):
	try:
		question = Question.objects.get(id=question_id)
	except:
		raise Http404

	if request.method == 'POST':
		form = QuestionForm(request.POST)
		if form.is_valid():
			# Update question properties
			question.text = request.POST['question_text']
			question.save()

			return HttpResponseRedirect(reverse('sinq3.views.question_view', args=(question.id,)))
	else:
		form = QuestionForm() # An empty, unbound form

	return render_to_response(
			'questions/question_edit.html',
			{
				'question': question,
				'form': form
			},
			context_instance=RequestContext(request)
		)
예제 #2
0
파일: views.py 프로젝트: ethernetdan/sinq
def question_create(request):
	if request.method == 'POST':
		form = QuestionForm(request.POST, request.FILES)
		if form.is_valid():
			# Create new question image and store in DB
			question_text = request.POST['question_text']

			question = Question(text = question_text)
			question.save()

			return HttpResponseRedirect(reverse('sinq3.views.question_view', args=(question.id,)))
	else:
		form = QuestionForm() # An empty, unbound form

	return render_to_response(
			'questions/question_create.html',
			{
				'form': form
			},
			context_instance=RequestContext(request)
		)