diff options
Diffstat (limited to 'testapp/exam')
-rw-r--r-- | testapp/exam/forms.py | 24 | ||||
-rw-r--r-- | testapp/exam/views.py | 12 |
2 files changed, 23 insertions, 13 deletions
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)) |