pretty much working version
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Mon, 26 Sep 2011 06:53:41 +0000 (08:53 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Mon, 26 Sep 2011 06:53:41 +0000 (08:53 +0200)
12 files changed:
apps/quiz/admin.py
apps/quiz/migrations/0001_initial.py
apps/quiz/models.py
apps/quiz/static/css/style.css [new file with mode: 0755]
apps/quiz/templates/quiz/question_detail.html
apps/quiz/templates/quiz/result_detail.html
apps/quiz/views.py
koedquiz/settings.py
koedquiz/templates/404.html [new file with mode: 0755]
koedquiz/templates/500.html [new file with mode: 0755]
koedquiz/templates/base.html
koedquiz/templates/home.html

index 849f918..ddc66d4 100644 (file)
@@ -1,6 +1,6 @@
 from django.contrib import admin
 
-from quiz.models import Question, Result, Answer
+from quiz.models import Quiz, Question, Result, Answer
 
 
 class AnswerInline(admin.TabularInline):
@@ -16,3 +16,4 @@ class QuestionAdmin(admin.ModelAdmin):
 
 admin.site.register(Question, QuestionAdmin)
 admin.site.register(Result)
+admin.site.register(Quiz)
index df82327..0545fd7 100644 (file)
@@ -8,10 +8,17 @@ class Migration(SchemaMigration):
 
     def forwards(self, orm):
         
+        # Adding model 'Quiz'
+        db.create_table('quiz_quiz', (
+            ('site_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['sites.Site'], unique=True, primary_key=True)),
+            ('description', self.gf('django.db.models.fields.TextField')()),
+        ))
+        db.send_create_signal('quiz', ['Quiz'])
+
         # Adding model 'Result'
         db.create_table('quiz_result', (
             ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
-            ('quiz', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['sites.Site'])),
+            ('quiz', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['quiz.Quiz'])),
             ('slug', self.gf('django.db.models.fields.SlugField')(max_length=50, db_index=True)),
             ('title', self.gf('django.db.models.fields.CharField')(max_length=255)),
             ('text', self.gf('django.db.models.fields.TextField')()),
@@ -21,7 +28,7 @@ class Migration(SchemaMigration):
         # Adding model 'Question'
         db.create_table('quiz_question', (
             ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
-            ('quiz', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['sites.Site'])),
+            ('quiz', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['quiz.Quiz'])),
             ('slug', self.gf('django.db.models.fields.SlugField')(max_length=50, db_index=True)),
             ('ordering', self.gf('django.db.models.fields.SmallIntegerField')()),
             ('title', self.gf('django.db.models.fields.CharField')(max_length=255)),
@@ -56,6 +63,9 @@ class Migration(SchemaMigration):
         # Removing unique constraint on 'Question', fields ['quiz', 'slug']
         db.delete_unique('quiz_question', ['quiz_id', 'slug'])
 
+        # Deleting model 'Quiz'
+        db.delete_table('quiz_quiz')
+
         # Deleting model 'Result'
         db.delete_table('quiz_result')
 
@@ -81,18 +91,20 @@ class Migration(SchemaMigration):
             'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
             'ordering': ('django.db.models.fields.SmallIntegerField', [], {}),
-            'quiz': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+            'quiz': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['quiz.Quiz']"}),
             'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'db_index': 'True'}),
             'text': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
             'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
         },
         'quiz.quiz': {
-            'Meta': {'ordering': "('domain',)", 'object_name': 'Quiz', 'db_table': "'django_site'", '_ormbases': ['sites.Site'], 'proxy': 'True'}
+            'Meta': {'ordering': "('domain',)", 'object_name': 'Quiz', '_ormbases': ['sites.Site']},
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'site_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['sites.Site']", 'unique': 'True', 'primary_key': 'True'})
         },
         'quiz.result': {
             'Meta': {'object_name': 'Result'},
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'quiz': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
+            'quiz': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['quiz.Quiz']"}),
             'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'db_index': 'True'}),
             'text': ('django.db.models.fields.TextField', [], {}),
             'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
index 92955fa..ccde81e 100644 (file)
@@ -6,8 +6,9 @@ from django.conf import settings
 
 
 class Quiz(Site):
+    description = models.TextField()
+
     class Meta:
-        proxy=True
         verbose_name = _('quiz')
         verbose_name_plural = _('quizzes')
 
diff --git a/apps/quiz/static/css/style.css b/apps/quiz/static/css/style.css
new file mode 100755 (executable)
index 0000000..55eac96
--- /dev/null
@@ -0,0 +1,73 @@
+html, body {
+    margin: 0;
+    padding: 0;
+}
+body {
+    font-family: arial, verdana, sans-serif;
+}
+#body {
+    max-width: 40em;
+    margin: auto;
+}
+
+#header {
+    background: #222;
+    color: #eee;
+    padding: 1em 0;
+    
+}
+h1 {
+    font-size: 2em;
+    max-width: 20em;
+    margin: auto;
+    margin-top: 0;
+    color: #eee;
+}
+
+button {
+    background: #999;
+    color: white;
+    padding: 1em;
+    text-decoration:none;
+    border: 1px solid #ddd;
+    border-radius: 1em;
+    width: 100%;
+}
+button:hover {
+    background: #aaa;
+}
+
+a.big-button {
+    background: #999;
+    color: white;
+    padding: 1em;
+    text-decoration:none;
+    border: 1px solid #ddd;
+    border-radius: 1em;
+    display: block;
+    text-align: center;
+    margin-top: 1em;
+}
+
+a.big-button:hover {
+    background: #aaa;
+}
+
+.question li {
+    list-style: none;
+    margin-bottom: 1em;
+}
+
+.errorlist {
+    font-weight: bold;
+    color: red;
+}
+
+#description {
+    margin-top: 1em;
+    font-size: .9em;
+    color: #444;
+    padding: 0 1em;
+    border: 1px solid #ddd;
+    border-radius: 1em;
+}
index b739a98..c74742c 100755 (executable)
@@ -2,35 +2,40 @@
 {% load i18n %}
 {% load url from future %}
 
+
+{% block "title" %}{{ question.quiz.name }}{% endblock %}
+{% block "header" %}{{ question.quiz.name }}{% endblock %}
+
+
 {% block "body" %}
 
 
-<h1>{{ question.title }}</h1>
+<h2>{{ question.title }}</h2>
 <div>
-{{ question.text }}
+{{ question.text|safe }}
 </div>
 
 <div>
 
 
 
-<form method='post'>
+<form class='question' method='post'>
 {% csrf_token %}
 {{ form.answer.errors }}
 {{ form.answer }}
 
 {% if valid %}
-    <input type='submit' />
+    <button>{% trans "Send answer" %}</button>
 
     {% if previous_url %}
-        <a href='{{ previous_url }}'>{% trans "Back to last question" %}</a>
+        <a class='button' href='{{ previous_url }}'>{% trans "Back to last question" %}</a>
     {% endif %}
 
 {% else %}
     {% if valid_url %}
-        <a href='{{ valid_url }}'>{% trans "Back to my test" %}</a>
+        <a class='big-button' href='{{ valid_url }}'>{% trans "Back to my test" %}</a>
     {% else %}
-        <a href='{% url "quiz" %}'>{% trans "Start from the beginning" %}</a>
+        <a class='big-button' href='{% url "quiz" %}'>{% trans "Start from the beginning" %}</a>
     {% endif %}
 {% endif %}
 
@@ -38,8 +43,8 @@
 </div>
 
 
-<div>
-{{ question.description }}
+<div id='description'>
+{{ question.description|safe }}
 </div>
 
 
index 89b875c..6a06ec0 100755 (executable)
@@ -3,32 +3,31 @@
 {% load url from future %}
 
 
-{% block "body" %}
+{% block "title" %}{{ result.quiz.name }}{% endblock %}
+{% block "header" %}{{ result.quiz.name }}{% endblock %}
 
-<h1>{{ result.title }}</h1>
 
+{% block "body" %}
 
+<h2>{{ result.title }}</h2>
 
 <div>
-{{ result.text }}
+{{ result.text|safe }}
 </div>
 
 
 
 {% if valid %}
     {% if previous_url %}
-        <a href='{{ previous_url }}'>{% trans "Back to last question" %}</a>
+        <a class='big-button' href='{{ previous_url }}'>{% trans "Back to last question" %}</a>
     {% endif %}
 {% else %}
     {% if valid_url %}
-        <a href='{{ valid_url }}'>{% trans "Back to my test" %}</a>
-    {% else %}
-        <a href='{% url "quiz" %}'>{% trans "Start from the beginning" %}</a>
+        <a class='big-button' href='{{ valid_url }}'>{% trans "Back to my test" %}</a>
     {% endif %}
 {% endif %}
 
 
-
-<a href='{% url "quiz" %}'>{% trans "Start again" %}</a>
+<a class='big-button' href='{% url "quiz" %}'>{% trans "Start from the beginning" %}</a>
 
 {% endblock %}
index 7160759..037f0c5 100644 (file)
@@ -47,6 +47,14 @@ def result(request, slug=None):
     ticket = request.session['ticket']
     valid = request.path in ticket
 
+    if valid:
+        cur_index = ticket.index(request.path)
+        if cur_index:
+            previous_url = ticket[cur_index - 1]
+    else:
+        valid_url = ticket[-1]
+
+
     result = get_object_or_404(Quiz.current().result_set, slug=slug)
     return render(request, "quiz/result_detail.html", locals())
 
index 52cd99a..c527648 100644 (file)
@@ -60,7 +60,7 @@ MEDIA_URL = '/media/'
 # Don't put anything in this directory yourself; store your static files
 # in apps' "static/" subdirectories and in STATICFILES_DIRS.
 # Example: "/home/media/media.lawrence.com/static/"
-STATIC_ROOT = os.path.join(PROJECT_DIR, '../static')
+STATIC_ROOT = os.path.join(PROJECT_DIR, 'static/')
 
 # URL prefix for static files.
 # Example: "http://media.lawrence.com/static/"
diff --git a/koedquiz/templates/404.html b/koedquiz/templates/404.html
new file mode 100755 (executable)
index 0000000..928901c
--- /dev/null
@@ -0,0 +1,67 @@
+<!DOCTYPE HTML>
+<html>
+
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+    <title>Nie ma takiej strony</title>
+    <style type="text/css">
+html, body {
+    margin: 0;
+    padding: 0;
+}
+body {
+    font-family: arial, verdana, sans-serif;
+}
+#body {
+    max-width: 40em;
+    margin: auto;
+}
+
+#header {
+    background: #222;
+    color: #eee;
+    padding: 1em 0;
+    
+}
+h1 {
+    font-size: 2em;
+    max-width: 20em;
+    margin: auto;
+    margin-top: 0;
+    color: #eee;
+}
+
+
+a.big-button {
+    background: #999;
+    color: white;
+    padding: 1em;
+    text-decoration:none;
+    border: 1px solid #ddd;
+    border-radius: 1em;
+    display: block;
+    text-align: center;
+    margin-top: 1em;
+}
+
+a.big-button:hover {
+    background: #aaa;
+}
+
+    </style>
+</head>
+
+<body>
+    <div id="header">
+    <a href='/'><h1>Nie ma takiej strony</h1></a>
+    </div>
+
+    <div id="body">
+        <p>Nie znaleziono żądanej strony.</p>
+
+        <a class='big-button' href="/">Powrót do strony głównej.</a>
+
+    </div>
+</body>
+
+</html>
diff --git a/koedquiz/templates/500.html b/koedquiz/templates/500.html
new file mode 100755 (executable)
index 0000000..92a02fa
--- /dev/null
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML>
+<html>
+
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+    <title>{% block "title" %}{% endblock %}</title>
+    <style type="text/css">
+html, body {
+    margin: 0;
+    padding: 0;
+}
+body {
+    font-family: arial, verdana, sans-serif;
+}
+#body {
+    max-width: 40em;
+    margin: auto;
+}
+
+#header {
+    background: #222;
+    color: #eee;
+    padding: 1em 0;
+    
+}
+h1 {
+    font-size: 2em;
+    max-width: 20em;
+    margin: auto;
+    margin-top: 0;
+    color: #eee;
+}
+    </style>
+</head>
+
+<body>
+    <div id="header">
+    <h1>Błąd serwera</h1>
+    </div>
+
+    <div id="body">
+        <p>Serwis jest chwilowo niedostępny.
+        Proszę spróbować jeszcze raz za chwilę.
+        Jeśli problem będzie się powtarzał, proszę skontaktować się
+        z <a href='mailto:fundacja@nowoczesnapolska.org.pl'>administratorami</a>.</p>
+    </div>
+</body>
+
+</html>
index c6ffd3c..cc33400 100644 (file)
@@ -4,10 +4,17 @@
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     <title>{% block "title" %}{% endblock %}</title>
+    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/style.css" />
 </head>
 
 <body>
-    {% block "body" %}{% endblock %}
+    <div id="header">
+    <a href='/'><h1>{% block "header" %}{% endblock %}</h1></a>
+    </div>
+
+    <div id="body">
+        {% block "body" %}{% endblock %}
+    </div>
 </body>
 
 </html>
index 5c856b8..1e0c763 100644 (file)
@@ -1,7 +1,16 @@
 {% extends "base.html" %}
 
+
+{% block "title" %}{{ quiz.name }}{% endblock %}
+{% block "header" %}{{ quiz.name }}{% endblock %}
+
+
 {% block "body" %}
 
-<a href="{{ quiz.get_absolute_url }}">Start quiz!</a>
+<div>
+{{ quiz.description|safe }}
+</div>
+
+<a class='big-button' href="{{ quiz.get_absolute_url }}">Start quiz!</a>
 
 {% endblock %}