From: tomwalker Date: Thu, 10 Apr 2014 20:05:45 +0000 (+0100) Subject: new branch, adding true and false, will require refactoring of quiz/views.py X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=329cc42a8c08e2b59c0ea706f772ba4b5b41ee8e;p=django_quiz.git new branch, adding true and false, will require refactoring of quiz/views.py --- diff --git a/multichoice/models.py b/multichoice/models.py index fbef01e..281cf0b 100644 --- a/multichoice/models.py +++ b/multichoice/models.py @@ -1,5 +1,5 @@ from django.db import models -from quiz.models import Quiz, Category +from django_quiz.quiz.models import Quiz, Category """ Multiple choice style question for quiz diff --git a/quiz/admin.py b/quiz/admin.py index 291b7ee..de383b6 100644 --- a/quiz/admin.py +++ b/quiz/admin.py @@ -1,8 +1,8 @@ from django import forms from django.contrib import admin from django.contrib.admin.widgets import FilteredSelectMultiple -from quiz.models import Quiz, Category, Progress -from multichoice.models import Question, Answer +from django_quiz.quiz.models import Quiz, Category, Progress +from django_quiz.multichoice.models import Question, Answer class QuestionInline(admin.TabularInline): model = Question.quiz.through diff --git a/quiz/models.py b/quiz/models.py index b674449..5282230 100644 --- a/quiz/models.py +++ b/quiz/models.py @@ -94,23 +94,30 @@ class Quiz(models.Model): random_order = models.BooleanField(blank=False, default=False, - help_text="Display the questions in a random order or as they are set?", + help_text="Display the questions in a\ + random order or as they are set?", ) answers_at_end = models.BooleanField(blank=False, default=False, - help_text="Correct answer is NOT shown after question. Answers displayed at end", + help_text="Correct answer is NOT shown\ + after question. Answers displayed at end", ) exam_paper = models.BooleanField(blank=False, default=False, - help_text="If yes, the result of each attempt by a user will be stored", + help_text="If yes, the result of each\ + attempt by a user will be stored", ) def save(self, force_insert=False, force_update=False): - self.url = self.url.replace(' ', '-').lower() # automatically converts url to lowercase, replace space with dash - self.url = ''.join(letter for letter in self.url if letter.isalnum() or letter == '-') # removes non-alphanumerics + self.url = self.url.replace(' ', '-').lower() + # automatically converts url to lowercase, replace space with dash + + self.url = ''.join(letter for letter in self.url if letter.isalnum() + or letter == '-') # removes non-alphanumerics + super(Quiz, self).save(force_insert, force_update) diff --git a/quiz/templatetags/quiz_tags.py b/quiz/templatetags/quiz_tags.py index 314311c..6314c26 100644 --- a/quiz/templatetags/quiz_tags.py +++ b/quiz/templatetags/quiz_tags.py @@ -1,5 +1,5 @@ from django import template -from multichoice.models import Question, Answer +from django_quiz.multichoice.models import Question, Answer register = template.Library() diff --git a/quiz/views.py b/quiz/views.py index 8c52f35..df2d442 100644 --- a/quiz/views.py +++ b/quiz/views.py @@ -10,8 +10,8 @@ from django.template import RequestContext from django.shortcuts import render, get_object_or_404 -from quiz.models import Quiz, Category, Progress, Sitting -from multichoice.models import Question, Answer +from django_quiz.quiz.models import Quiz, Category, Progress, Sitting +from django_quiz.multichoice.models import Question, Answer """ @@ -331,6 +331,7 @@ def question_check_anon(request, quiz): and return the previous questions details """ quiz_id = str(quiz.id) + question_list = request.session[q_list] # list of ints, each is question id guess = request.GET['guess'] answer = Answer.objects.get(id=guess) question = answer.question # the id of the question diff --git a/true_false/__init__.py b/true_false/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/true_false/models.py b/true_false/models.py new file mode 100644 index 0000000..06e9b83 --- /dev/null +++ b/true_false/models.py @@ -0,0 +1,35 @@ +from django.db import models +from django_quiz.quiz.models import Quiz, Category + +class TF_Question(models.Model): + + quiz = models.ManyToManyField(Quiz, blank=True, ) + + category = models.ForeignKey(Category, blank=True, null=True, ) + + content = models.CharField(max_length=1000, + blank=False, + help_text="Enter the question text that you want displayed", + verbose_name='Question', + ) + + explanation = models.TextField(max_length=2000, + blank=True, + help_text="Explanation to be shown after the question has been answered.", + verbose_name='Explanation', + ) + + correct = models.BooleanField(blank=False, + default=False, + help_text="Is this question true or false?" + ) + + class Meta: + verbose_name = "Question" + verbose_name_plural = "Questions" + ordering = ['category'] + + + def __unicode__(self): + return self.content + diff --git a/true_false/models.py~ b/true_false/models.py~ new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/true_false/models.py~ @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/true_false/tests.py b/true_false/tests.py new file mode 100644 index 0000000..fa705ba --- /dev/null +++ b/true_false/tests.py @@ -0,0 +1,21 @@ +from django.test import TestCase + +from django_quiz.true_false.models import TF_Question + + +class TestTrueFalseQuestionModel(TestCase): + def setUp(self): + TF_Question.objects.create(content = "Is red the best colour?", + explanation = "it is", + correct = True,) + TF_Question.objects.create(content = "Is blue the best colour?", + explanation = "it is not", + correct = False,) + + def test_true_q(self): + red = TF_Question.objects.get(explanation = "it is") + self.assertEqual(red.correct, True) + + def test_false_q(self): + red = TF_Question.objects.get(explanation = "it is not") + self.assertEqual(red.correct, False) diff --git a/true_false/tests.py~ b/true_false/tests.py~ new file mode 100644 index 0000000..501deb7 --- /dev/null +++ b/true_false/tests.py~ @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2) diff --git a/true_false/views.py b/true_false/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/true_false/views.py @@ -0,0 +1 @@ +# Create your views here.