]> git.parisson.com Git - django_quiz.git/commitdiff
new branch, adding true and false, will require refactoring of quiz/views.py
authortomwalker <tomwalker0472@gmail.com>
Thu, 10 Apr 2014 20:05:45 +0000 (21:05 +0100)
committertomwalker <tomwalker0472@gmail.com>
Thu, 10 Apr 2014 20:05:45 +0000 (21:05 +0100)
multichoice/models.py
quiz/admin.py
quiz/models.py
quiz/templatetags/quiz_tags.py
quiz/views.py
true_false/__init__.py [new file with mode: 0644]
true_false/models.py [new file with mode: 0644]
true_false/models.py~ [new file with mode: 0644]
true_false/tests.py [new file with mode: 0644]
true_false/tests.py~ [new file with mode: 0644]
true_false/views.py [new file with mode: 0644]

index fbef01e788184abab46fc47b758c4167e8ce63a2..281cf0bf1daa965e87979447693d1258cb679c86 100644 (file)
@@ -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
index 291b7eecfc79b875f70e234c0f51caf24c29a40b..de383b6355367c1facff7a5fff9cea2013a6b44f 100644 (file)
@@ -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
index b674449813b7b8adc8292f8f155b7c0e65c4eab3..528223062767e7b4989b8940946c5922e987ffd9 100644 (file)
@@ -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)
 
 
index 314311c64b9ccd6fb04f1ba272b5265f47469184..6314c26b64e2c1c146bd27a55a803696da036729 100644 (file)
@@ -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()
 
index 8c52f35bae86579c9eb31ca1116ca3de889075d7..df2d442ea8754cd580055c5b914fa893b3b3c820 100644 (file)
@@ -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 (file)
index 0000000..e69de29
diff --git a/true_false/models.py b/true_false/models.py
new file mode 100644 (file)
index 0000000..06e9b83
--- /dev/null
@@ -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 (file)
index 0000000..71a8362
--- /dev/null
@@ -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 (file)
index 0000000..fa705ba
--- /dev/null
@@ -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 (file)
index 0000000..501deb7
--- /dev/null
@@ -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 (file)
index 0000000..60f00ef
--- /dev/null
@@ -0,0 +1 @@
+# Create your views here.