summaryrefslogtreecommitdiff
path: root/yaksh/forms.py
diff options
context:
space:
mode:
authorprathamesh2017-09-01 17:22:29 +0530
committerprathamesh2017-09-01 17:22:29 +0530
commit1e3bb9e325214be0105f8b907badc84b2dbbeb91 (patch)
tree3327924e1879524909d5f1603dfe7d3dbda4c05a /yaksh/forms.py
parente2c65655dcdc5558cfb4ab668c3012024d27ac75 (diff)
parent9e0f737c25a5156aa884d27357af0aef1145c4b7 (diff)
downloadonline_test-1e3bb9e325214be0105f8b907badc84b2dbbeb91.tar.gz
online_test-1e3bb9e325214be0105f8b907badc84b2dbbeb91.tar.bz2
online_test-1e3bb9e325214be0105f8b907badc84b2dbbeb91.zip
Merge branch 'master' of https://github.com/FOSSEE/online_test into improve-code-server
Conflicts Resolved: yaksh/templates/yaksh/question.html
Diffstat (limited to 'yaksh/forms.py')
-rw-r--r--yaksh/forms.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py
index 3459be9..2740497 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -181,9 +181,13 @@ class QuizForm(forms.ModelForm):
user = kwargs.pop('user')
course_id = kwargs.pop('course')
super(QuizForm, self).__init__(*args, **kwargs)
- self.fields['prerequisite'] = forms.ModelChoiceField(
- queryset=Quiz.objects.filter(course__id=course_id,
- is_trial=False))
+
+ prerequisite_list = Quiz.objects.filter(
+ course__id=course_id,
+ is_trial=False
+ ).exclude(id=self.instance.id)
+
+ self.fields['prerequisite'] = forms.ModelChoiceField(prerequisite_list)
self.fields['prerequisite'].required = False
self.fields['course'] = forms.ModelChoiceField(
queryset=Course.objects.filter(id=course_id), empty_label=None)
@@ -240,6 +244,13 @@ class QuizForm(forms.ModelForm):
</p>
""")
+ def clean_prerequisite(self):
+ prereq = self.cleaned_data['prerequisite']
+ if prereq and prereq.prerequisite:
+ if prereq.prerequisite.id == self.instance.id:
+ raise forms.ValidationError("Please set another prerequisite quiz")
+ return prereq
+
class Meta:
model = Quiz
exclude = ["is_trial"]