summaryrefslogtreecommitdiff
path: root/testapp
diff options
context:
space:
mode:
authorprathamesh2014-06-26 15:09:42 +0530
committerprathamesh2014-06-26 15:09:42 +0530
commit7155dd407f48293d46b0fb45e7d2354bd0982f76 (patch)
treef2e06d29f0b8e90164c4758edb3016682c778e5b /testapp
parent5409b03f915c4569ccb17974e6c09660fa32d8bf (diff)
downloadonline_test-7155dd407f48293d46b0fb45e7d2354bd0982f76.tar.gz
online_test-7155dd407f48293d46b0fb45e7d2354bd0982f76.tar.bz2
online_test-7155dd407f48293d46b0fb45e7d2354bd0982f76.zip
Changes made to quiz form to accept prerequisite quiz.
Diffstat (limited to 'testapp')
-rw-r--r--testapp/exam/forms.py30
-rw-r--r--testapp/exam/views.py10
2 files changed, 22 insertions, 18 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py
index 1f1a2af..a8e3ae7 100644
--- a/testapp/exam/forms.py
+++ b/testapp/exam/forms.py
@@ -27,14 +27,10 @@ QUESTION_TYPES = (
("mcq", "Multiple Choice"),
("code", "Code"),
)
-QUIZZES =[('select', 'Select a prerequisite quiz')]
-quizzes = Quiz.objects.all()
-QUIZZES = QUIZZES+[(quiz.id, quiz) for quiz in quizzes]
UNAME_CHARS = letters + "._" + digits
PWD_CHARS = letters + punctuation + digits
-
class UserRegisterForm(forms.Form):
"""A Class to create new form for User's Registration.
It has the various fields and functions required to register
@@ -130,16 +126,24 @@ class QuizForm(forms.Form):
"""Creates a form to add or edit a Quiz.
It has the related fields and functions required."""
+ def __init__(self, *args, **kwargs):
+ super(QuizForm, self).__init__(*args, **kwargs)
+ self.QUIZZES = [('', 'Select a prerequisite quiz')]
+ self.QUIZZES = self.QUIZZES + \
+ list(Quiz.objects.values_list('id','description'))
+ self.fields['prerequisite'] = forms.CharField(required=False,
+ widget=forms.Select(choices=self.QUIZZES))
+
+
start_date = forms.DateField(initial=datetime.date.today)
- duration = forms.IntegerField()
+ duration = forms.IntegerField(help_text='Will be taken in minutes')
active = forms.BooleanField(required=False)
description = forms.CharField(max_length=256, widget=forms.Textarea\
(attrs={'cols': 20, 'rows': 1}))
pass_criteria = forms.FloatField(initial=40,
help_text='Will be taken as percentage')
language = forms.CharField(widget=forms.Select(choices=LANGUAGES))
- prerequisite = forms.CharField(required=False,
- widget=forms.Select(choices=QUIZZES))
+
def save(self):
start_date = self.cleaned_data["start_date"]
@@ -149,8 +153,6 @@ class QuizForm(forms.Form):
pass_criteria = self.cleaned_data["pass_criteria"]
language = self.cleaned_data["language"]
prerequisite = self.cleaned_data["prerequisite"]
-
-
new_quiz = Quiz()
new_quiz.start_date = start_date
new_quiz.duration = duration
@@ -158,8 +160,7 @@ class QuizForm(forms.Form):
new_quiz.description = description
new_quiz.pass_criteria = pass_criteria
new_quiz.language = language
- if isinstance(prerequisite, int):
- new_quiz.prerequisite_id = prerequisite
+ new_quiz.prerequisite_id = prerequisite
new_quiz.save()
@@ -207,10 +208,3 @@ class QuestionForm(forms.Form):
new_question.active = active
new_question.snippet = snippet
new_question.save()
-
-
- class RandomQuestionForm(forms.Form):
- question_type = forms.CharField(max_length=8, widget=forms.Select\
- (choices=QUESTION_TYPES))
- shuffle_questions = forms.BooleanField(required=False)
-
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 7353d82..33bafe6 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -188,6 +188,8 @@ def edit_quiz(request):
duration = request.POST.getlist('duration')
active = request.POST.getlist('active')
description = request.POST.getlist('description')
+ language = request.POST.getlist('language')
+ prerequisite = request.POST.getlist('prerequisite')
for j, quiz_id in enumerate(quiz_list):
quiz = Quiz.objects.get(id=quiz_id)
@@ -195,6 +197,8 @@ def edit_quiz(request):
quiz.duration = duration[j]
quiz.active = active[j]
quiz.description = description[j]
+ quiz.language = language[j]
+ quiz.prerequisite = prerequisite[j]
quiz.save()
return my_redirect("/exam/manage/showquiz/")
@@ -322,6 +326,8 @@ def add_quiz(request, quiz_id=None):
d.duration = form['duration'].data
d.active = form['active'].data
d.description = form['description'].data
+ d.language = form['language'].data
+ d.prerequisite = form['prerequisite'].data
d.save()
quiz = Quiz.objects.get(id=quiz_id)
return my_redirect("/exam/manage/showquiz")
@@ -342,6 +348,8 @@ def add_quiz(request, quiz_id=None):
form.initial['duration'] = d.duration
form.initial['description'] = d.description
form.initial['active'] = d.active
+ form.initial['language'] = d.language
+ form.initial['prerequisite'] = d.prerequisite_id
return my_render_to_response('exam/add_quiz.html',
{'form': form},
context_instance=ci)
@@ -910,6 +918,8 @@ def show_all_quiz(request):
form.initial['duration'] = d.duration
form.initial['active'] = d.active
form.initial['description'] = d.description
+ form.initial['language'] = d.language
+ form.initial['prerequisite'] = d.prerequisite.description
forms.append(form)
return my_render_to_response('exam/edit_quiz.html',
{'forms': forms, 'data': data},