fnp
/
koed-quiz.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add a makefile.
[koed-quiz.git]
/
apps
/
quiz
/
models.py
diff --git
a/apps/quiz/models.py
b/apps/quiz/models.py
index
92955fa
..
f6cdc4a
100644
(file)
--- a/
apps/quiz/models.py
+++ b/
apps/quiz/models.py
@@
-1,26
+1,34
@@
+# This file is part of KOED-Quiz, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
from django.db import models
from django.contrib.sites.models import Site
from django.db import models
from django.contrib.sites.models import Site
+from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
class Quiz(Site):
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
class Quiz(Site):
+ description = models.TextField()
+ footer = models.TextField(null=True, blank=True)
+
class Meta:
class Meta:
- proxy=True
verbose_name = _('quiz')
verbose_name_plural = _('quizzes')
@classmethod
verbose_name = _('quiz')
verbose_name_plural = _('quizzes')
@classmethod
- def current(cls):
- return cls.objects.get(id=settings.SITE_ID)
+ def current(cls, request):
+ try:
+ return cls.objects.get(domain=request.get_host().rstrip('.'))
+ except cls.DoesNotExist:
+ pass
def start(self):
return self.question_set.all()[0]
def start(self):
return self.question_set.all()[0]
- @models.permalink
def get_absolute_url(self):
def get_absolute_url(self):
- return
('quiz',
)
+ return
reverse('quiz'
)
def where_to(self):
try:
def where_to(self):
try:
@@
-31,7
+39,7
@@
class Quiz(Site):
class Result(models.Model):
class Result(models.Model):
- quiz = models.ForeignKey(Quiz)
+ quiz = models.ForeignKey(Quiz
, models.CASCADE
)
slug = models.SlugField(db_index=True)
title = models.CharField(max_length=255)
text = models.TextField()
slug = models.SlugField(db_index=True)
title = models.CharField(max_length=255)
text = models.TextField()
@@
-39,17
+47,17
@@
class Result(models.Model):
class Meta:
verbose_name = _('result')
verbose_name_plural = _('results')
class Meta:
verbose_name = _('result')
verbose_name_plural = _('results')
+ ordering = ['quiz', 'title']
- def __
unicode
__(self):
+ def __
str
__(self):
return self.title
return self.title
- @models.permalink
def get_absolute_url(self):
def get_absolute_url(self):
- return
('quiz_result',
[self.slug])
+ return
reverse('quiz_result', args=
[self.slug])
class Question(models.Model):
class Question(models.Model):
- quiz = models.ForeignKey(Quiz)
+ quiz = models.ForeignKey(Quiz
, models.CASCADE
)
slug = models.SlugField(db_index=True)
ordering = models.SmallIntegerField()
title = models.CharField(max_length=255)
slug = models.SlugField(db_index=True)
ordering = models.SmallIntegerField()
title = models.CharField(max_length=255)
@@
-62,12
+70,11
@@
class Question(models.Model):
ordering = ['quiz', 'ordering']
unique_together = [['quiz', 'slug'], ['quiz', 'ordering']]
ordering = ['quiz', 'ordering']
unique_together = [['quiz', 'slug'], ['quiz', 'ordering']]
- def __
unicode
__(self):
+ def __
str
__(self):
return self.title
return self.title
- @models.permalink
def get_absolute_url(self):
def get_absolute_url(self):
- return
('quiz',
[self.slug])
+ return
reverse('quiz', args=
[self.slug])
def where_to(self):
later = self.quiz.question_set.filter(ordering__gt=self.ordering)
def where_to(self):
later = self.quiz.question_set.filter(ordering__gt=self.ordering)
@@
-77,13
+84,12
@@
class Question(models.Model):
return self.quiz.where_to()
return self.quiz.where_to()
-
class Answer(models.Model):
title = models.CharField(max_length=255)
class Answer(models.Model):
title = models.CharField(max_length=255)
- question = models.ForeignKey(Question)
- go_to = models.ForeignKey(Question, null=True, blank=True,
+ question = models.ForeignKey(Question
, models.CASCADE
)
+ go_to = models.ForeignKey(Question,
models.SET_NULL,
null=True, blank=True,
related_name='go_tos')
related_name='go_tos')
- result = models.ForeignKey(Result, null=True, blank=True)
+ result = models.ForeignKey(Result,
models.SET_NULL,
null=True, blank=True)
ordering = models.SmallIntegerField()
class Meta:
ordering = models.SmallIntegerField()
class Meta:
@@
-91,7
+97,7
@@
class Answer(models.Model):
verbose_name_plural = _('answers')
ordering = ['question', 'ordering']
verbose_name_plural = _('answers')
ordering = ['question', 'ordering']
- def __
unicode
__(self):
+ def __
str
__(self):
return self.title
def where_to(self):
return self.title
def where_to(self):