From 467adb5d403e7dd29a83f44d06c80cdca8b4e7a1 Mon Sep 17 00:00:00 2001 From: jayparikh111 Date: Thu, 16 Feb 2012 15:37:20 +0530 Subject: Form to add New Quiz --- testapp/exam/forms.py | 24 +++++++++++++++++++----- testapp/exam/views.py | 12 ++++-------- testapp/templates/exam/add_question.html | 1 + testapp/templates/exam/add_quiz.html | 3 ++- 4 files changed, 26 insertions(+), 14 deletions(-) (limited to 'testapp') diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py index 6d431e7..a09118c 100644 --- a/testapp/exam/forms.py +++ b/testapp/exam/forms.py @@ -1,9 +1,10 @@ from django import forms -from exam.models import Profile +from exam.models import Profile,Quiz from django.contrib.auth import authenticate from django.contrib.auth.models import User + from string import letters, punctuation, digits import datetime @@ -104,10 +105,23 @@ class UserLoginForm(forms.Form): return user class QuizForm(forms.Form): - start_date = forms.DateField(initial=datetime.date.today) - duration = forms.IntegerField() - active = forms.BooleanField(required = False) - description = forms.CharField(max_length=256, widget=forms.Textarea(attrs={'cols':20,'rows':2})) + start_date = forms.DateField(initial=datetime.date.today) + duration = forms.IntegerField() + active = forms.BooleanField(required = False) + description = forms.CharField(max_length=256, widget=forms.Textarea(attrs={'cols':20,'rows':2})) + + def save(self): + start_date = self.cleaned_data["start_date"] + duration = self.cleaned_data["duration"] + active = self.cleaned_data['active'] + description = self.cleaned_data["description"] + + new_quiz = Quiz() + new_quiz.start_date=start_date + new_quiz.duration=duration + new_quiz.active=active + new_quiz.description=description + new_quiz.save(); class AddQuestionForm(forms.Form): summary = forms.CharField(max_length = 128) diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 23534f5..1c5d2e5 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -109,24 +109,20 @@ def add_question(request): context_instance=RequestContext(request)) def add_quiz(request): - if request.method == "POST": form = QuizForm(request.POST) if form.is_valid(): data = form.cleaned_data - u_name, pwd = form.save() - - new_user = authenticate(username = u_name, password = pwd) - login(request, new_user) - return my_redirect("/exam/manage/add_quiz") + form.save() + return my_redirect("/exam/manage/addquiz") else: - return my_render_to_response('exam/add_quiz.html', + return my_render_to_response('exam/addquiz.html', {'form':form}, context_instance=RequestContext(request)) else: form = QuizForm() - return my_render_to_response('exam/add_quiz.html', + return my_render_to_response('exam/addquiz.html', {'form':form}, context_instance=RequestContext(request)) diff --git a/testapp/templates/exam/add_question.html b/testapp/templates/exam/add_question.html index a0ba14d..ae86ed1 100644 --- a/testapp/templates/exam/add_question.html +++ b/testapp/templates/exam/add_question.html @@ -21,6 +21,7 @@ table th, table td { {{ form.as_table }}