summaryrefslogtreecommitdiff
path: root/testapp/exam/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'testapp/exam/forms.py')
-rw-r--r--testapp/exam/forms.py46
1 files changed, 29 insertions, 17 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py
index 1f12a3b..93584a6 100644
--- a/testapp/exam/forms.py
+++ b/testapp/exam/forms.py
@@ -1,5 +1,5 @@
from django import forms
-from testapp.exam.models import Profile, Quiz, Question
+from exam.models import Profile, Quiz, Question, TestCase
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
@@ -8,6 +8,7 @@ from taggit.forms import TagField
from taggit_autocomplete_modified.managers import TaggableManagerAutocomplete
from taggit_autocomplete_modified.widgets import TagAutocomplete
from taggit_autocomplete_modified import settings
+from django.forms.models import inlineformset_factory
from string import letters, punctuation, digits
import datetime
@@ -177,7 +178,7 @@ class QuizForm(forms.Form):
new_quiz.save()
-class QuestionForm(forms.Form):
+class QuestionForm(forms.ModelForm):
"""Creates a form to add or edit a Question.
It has the related fields and functions required."""
@@ -186,8 +187,8 @@ class QuestionForm(forms.Form):
description = forms.CharField(widget=forms.Textarea\
(attrs={'cols': 40, 'rows': 1}))
points = forms.FloatField()
- test = forms.CharField(widget=forms.Textarea\
- (attrs={'cols': 40, 'rows': 1}))
+ solution = forms.CharField(widget=forms.Textarea\
+ (attrs={'cols': 40, 'rows': 1}), required=False)
options = forms.CharField(widget=forms.Textarea\
(attrs={'cols': 40, 'rows': 1}), required=False)
language = forms.CharField(max_length=20, widget=forms.Select\
@@ -198,29 +199,37 @@ class QuestionForm(forms.Form):
tags = TagField(widget=TagAutocomplete(), required=False)
snippet = forms.CharField(widget=forms.Textarea\
(attrs={'cols': 40, 'rows': 1}), required=False)
-
- def save(self):
- summary = self.cleaned_data["summary"]
- description = self.cleaned_data["description"]
- points = self.cleaned_data['points']
- test = self.cleaned_data["test"]
- options = self.cleaned_data['options']
- language = self.cleaned_data['language']
- type = self.cleaned_data["type"]
- active = self.cleaned_data["active"]
- snippet = self.cleaned_data["snippet"]
+ ref_code_path = forms.CharField(widget=forms.Textarea\
+ (attrs={'cols': 40, 'rows': 1}), required=False)
+
+ def save(self, commit=True):
+ summary = self.cleaned_data.get("summary")
+ description = self.cleaned_data.get("description")
+ points = self.cleaned_data.get("points")
+ options = self.cleaned_data.get("options")
+ language = self.cleaned_data.get("language")
+ type = self.cleaned_data.get("type")
+ active = self.cleaned_data.get("active")
+ snippet = self.cleaned_data.get("snippet")
new_question = Question()
new_question.summary = summary
new_question.description = description
new_question.points = points
- new_question.test = test
+ # new_question.test = test
new_question.options = options
new_question.language = language
new_question.type = type
new_question.active = active
new_question.snippet = snippet
- new_question.save()
+ new_question = super(QuestionForm, self).save(commit=False)
+ if commit:
+ new_question.save()
+
+ return new_question
+
+ class Meta:
+ model = Question
class RandomQuestionForm(forms.Form):
@@ -229,3 +238,6 @@ class RandomQuestionForm(forms.Form):
marks = forms.CharField(max_length=8, widget=forms.Select\
(choices=(('select', 'Select Marks'),)))
shuffle_questions = forms.BooleanField(required=False)
+
+TestCaseFormSet = inlineformset_factory(Question, TestCase,\
+ can_order=False, can_delete=False, extra=1)