--- /dev/null
+from .models import Quiz
+
+class CurrentQuizMiddleware(object):
+ def process_request(self, request):
+ request.current_quiz = Quiz.current(request)
verbose_name_plural = _('quizzes')
@classmethod
- def current(cls):
- return cls.objects.get(id=settings.SITE_ID)
+ def current(cls, request):
+ return cls.objects.get(domain=request.get_host())
def start(self):
return self.question_set.all()[0]
{% load i18n %}
-{% block "title" %}{{ quiz.name }}{% endblock %}
-{% block "header" %}{{ quiz.name }}{% endblock %}
+{% block "title" %}{{ request.current_quiz.name }}{% endblock %}
+{% block "header" %}{{ request.current_quiz.name }}{% endblock %}
{% block "body" %}
<div>
-{{ quiz.description|safe }}
+{{ request.current_quiz.description|safe }}
</div>
-<a class='big-button' href="{{ quiz.get_absolute_url }}">{% trans "Start the test!" %}</a>
+<a class='big-button' href="{{ request.current_quiz.get_absolute_url }}">{% trans "Start the test!" %}</a>
{% endblock %}
register = template.Library()
-@register.simple_tag
-def quiz_footer():
- return mark_safe(Quiz.current().footer)
+@register.simple_tag(takes_context=True)
+def quiz_footer(context):
+ return mark_safe(context.get('request').current_quiz.footer)
def question(request, slug=None):
if slug is None:
- question = Quiz.current().start()
+ question = request.current_quiz.start()
request.session['ticket'] = [request.path]
else:
- question = get_object_or_404(Quiz.current().question_set, slug=slug)
+ question = get_object_or_404(request.current_quiz.question_set, slug=slug)
ticket = request.session.get('ticket', [])
valid = request.path in ticket
elif ticket:
valid_url = ticket[-1]
- result = get_object_or_404(Quiz.current().result_set, slug=slug)
+ result = get_object_or_404(request.current_quiz.result_set, slug=slug)
return render(request, "quiz/result_detail.html", locals())
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'pl'
-SITE_ID = 1
-
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# 'django.template.loaders.eggs.Loader',
]
+TEMPLATE_CONTEXT_PROCESSORS = (
+ "django.contrib.auth.context_processors.auth",
+ "django.core.context_processors.debug",
+ "django.core.context_processors.i18n",
+ "django.core.context_processors.media",
+ "django.core.context_processors.static",
+ "django.core.context_processors.tz",
+ "django.contrib.messages.context_processors.messages",
+ "django.core.context_processors.request",
+)
+
MIDDLEWARE_CLASSES = [
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
+ 'quiz.middleware.CurrentQuizMiddleware',
]
ROOT_URLCONF = 'koedquiz.urls'
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django.conf.urls import patterns, include, url
-
+from django.views.generic import TemplateView
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
- url(r'^$', 'koedquiz.views.home', name='main_page'),
+ url(r'^$', TemplateView.as_view(template_name="quiz/home.html"), name='main_page'),
url(r'^quiz/', include('quiz.urls')),
+++ /dev/null
-# -*- coding: utf-8 -*-
-# 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.shortcuts import render
-
-from django.conf import settings
-from quiz.models import Quiz
-
-
-def home(request):
- quiz = Quiz.current()
- return render(request, "quiz/home.html", locals())