summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjayparikh1112012-02-16 15:37:20 +0530
committerjayparikh1112012-02-16 15:37:20 +0530
commit467adb5d403e7dd29a83f44d06c80cdca8b4e7a1 (patch)
treede464b59f977a212f233be4d39c9ff5e175631a9
parentc20539ed5f879c945cc89323e00daad96047d247 (diff)
downloadonline_test-467adb5d403e7dd29a83f44d06c80cdca8b4e7a1.tar.gz
online_test-467adb5d403e7dd29a83f44d06c80cdca8b4e7a1.tar.bz2
online_test-467adb5d403e7dd29a83f44d06c80cdca8b4e7a1.zip
Form to add New Quiz
-rw-r--r--testapp/exam/forms.py24
-rw-r--r--testapp/exam/views.py12
-rw-r--r--testapp/templates/exam/add_question.html1
-rw-r--r--testapp/templates/exam/add_quiz.html3
4 files changed, 26 insertions, 14 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))
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 }}
</table>
<center><button class="btn" type="submit" name="savequestion">Save</button>
+<button class="btn" type="reset" name="reset">Clear</button> </center>
</form>
{% endblock %}
diff --git a/testapp/templates/exam/add_quiz.html b/testapp/templates/exam/add_quiz.html
index a412ecc..80a52ed 100644
--- a/testapp/templates/exam/add_quiz.html
+++ b/testapp/templates/exam/add_quiz.html
@@ -22,6 +22,7 @@ table th, table td {
{{ form.as_table }}
</table>
</center>
-<center><button class="btn" type="submit" name="save">Save</button></center>
+<center><button class="btn" type="submit" name="save">Save</button>
+<button class="btn" type="reset" name="reset">Clear</button> </center>
</form>
{% endblock %}