diff options
Diffstat (limited to 'testapp/exam')
-rw-r--r-- | testapp/exam/forms.py | 16 | ||||
-rw-r--r-- | testapp/exam/models.py | 18 | ||||
-rw-r--r-- | testapp/exam/tests.py | 2 |
3 files changed, 18 insertions, 18 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py index a43ba2c..c96ac7e 100644 --- a/testapp/exam/forms.py +++ b/testapp/exam/forms.py @@ -12,7 +12,7 @@ from taggit_autocomplete_modified import settings from string import letters, punctuation, digits import datetime -LANGUAGES = ( +languages = ( ("select", "Select"), ("python", "Python"), ("bash", "Bash"), @@ -22,7 +22,7 @@ LANGUAGES = ( ("scilab", "Scilab"), ) -QUESTION_TYPES = ( +question_types = ( ("select", "Select"), ("mcq", "Multiple Choice"), ("code", "Code"), @@ -128,11 +128,11 @@ class QuizForm(forms.Form): def __init__(self, *args, **kwargs): super(QuizForm, self).__init__(*args, **kwargs) - QUIZZES = [('', 'Select a prerequisite quiz')] - QUIZZES = QUIZZES + \ + quizzes = [('', 'Select a prerequisite quiz')] + quizzes = quizzes + \ list(Quiz.objects.values_list('id','description')) self.fields['prerequisite'] = forms.CharField(required=False, - widget=forms.Select(choices=QUIZZES)) + widget=forms.Select(choices=quizzes)) start_date = forms.DateField(initial=datetime.date.today) duration = forms.IntegerField(help_text='Will be taken in minutes') @@ -141,7 +141,7 @@ class QuizForm(forms.Form): (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)) + language = forms.CharField(widget=forms.Select(choices=languages)) def save(self): start_date = self.cleaned_data["start_date"] @@ -176,9 +176,9 @@ class QuestionForm(forms.Form): options = forms.CharField(widget=forms.Textarea\ (attrs={'cols': 40, 'rows': 1}), required=False) language = forms.CharField(max_length=20, widget=forms.Select\ - (choices=LANGUAGES)) + (choices=languages)) type = forms.CharField(max_length=8, widget=forms.Select\ - (choices=QUESTION_TYPES)) + (choices=question_types)) active = forms.BooleanField(required=False) tags = TagField(widget=TagAutocomplete(), required=False) snippet = forms.CharField(widget=forms.Textarea\ diff --git a/testapp/exam/models.py b/testapp/exam/models.py index eb270ae..62c707b 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -16,7 +16,7 @@ class Profile(models.Model): position = models.CharField(max_length=64) -LANGUAGES = ( +languages = ( ("python", "Python"), ("bash", "Bash"), ("C", "C Language"), @@ -26,7 +26,7 @@ LANGUAGES = ( ) -QUESTION_TYPES = ( +question_types = ( ("mcq", "Multiple Choice"), ("code", "Code"), ) @@ -53,10 +53,10 @@ class Question(models.Model): # The language for question. language = models.CharField(max_length=24, - choices=LANGUAGES) + choices=languages) # The type of question. - type = models.CharField(max_length=24, choices=QUESTION_TYPES) + type = models.CharField(max_length=24, choices=question_types) # Is this question active or not. If it is inactive it will not be used # when creating a QuestionPaper. @@ -122,7 +122,7 @@ class Quiz(models.Model): prerequisite = models.ForeignKey("Quiz", null=True) # Programming language for a quiz - language = models.CharField(max_length=20, choices=LANGUAGES) + language = models.CharField(max_length=20, choices=languages) class Meta: verbose_name_plural = "Quizzes" @@ -248,8 +248,8 @@ class AnswerPaper(models.Model): # Marks percent scored by the user percent = models.FloatField(null=True, default=None) - # Result of the quiz, either PASSED or FAILED. - result = models.CharField(max_length=8, null=True, default=None) + # Result of the quiz, pass if True. + result = models.NullBooleanField() def current_question(self): """Returns the current active question to display.""" @@ -338,9 +338,9 @@ class AnswerPaper(models.Model): """ if self.percent is not None: if self.percent >= self.question_paper.quiz.pass_criteria: - self.result = "PASSED" + self.result = True else: - self.result = "FAILED" + self.result = False def get_question_answers(self): """ diff --git a/testapp/exam/tests.py b/testapp/exam/tests.py index 2cc208a..eb63ba4 100644 --- a/testapp/exam/tests.py +++ b/testapp/exam/tests.py @@ -276,7 +276,7 @@ class AnswerPaperTestCases(unittest.TestCase): def test_update_result(self): """ Test update_result() method of AnswerPaper""" self.answerpaper.update_result() - self.assertEqual(self.answerpaper.result, "FAILED") + self.assertFalse(self.answerpaper.result) def test_get_question_answer(self): """ Test get_question_answer() method of Answer Paper""" |