From: Radek Czajka Date: Mon, 26 Sep 2011 06:53:41 +0000 (+0200) Subject: pretty much working version X-Git-Url: https://git.mdrn.pl/koed-quiz.git/commitdiff_plain/5acb6fe123f2007fcb19e1f70dec854e516aaad3?hp=2c2b8f122dd789a089ac5054e112f59874c01a70 pretty much working version --- diff --git a/apps/quiz/admin.py b/apps/quiz/admin.py index 849f918..ddc66d4 100644 --- a/apps/quiz/admin.py +++ b/apps/quiz/admin.py @@ -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) diff --git a/apps/quiz/migrations/0001_initial.py b/apps/quiz/migrations/0001_initial.py index df82327..0545fd7 100644 --- a/apps/quiz/migrations/0001_initial.py +++ b/apps/quiz/migrations/0001_initial.py @@ -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'}) diff --git a/apps/quiz/models.py b/apps/quiz/models.py index 92955fa..ccde81e 100644 --- a/apps/quiz/models.py +++ b/apps/quiz/models.py @@ -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 index 0000000..55eac96 --- /dev/null +++ b/apps/quiz/static/css/style.css @@ -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; +} diff --git a/apps/quiz/templates/quiz/question_detail.html b/apps/quiz/templates/quiz/question_detail.html index b739a98..c74742c 100755 --- a/apps/quiz/templates/quiz/question_detail.html +++ b/apps/quiz/templates/quiz/question_detail.html @@ -2,35 +2,40 @@ {% load i18n %} {% load url from future %} + +{% block "title" %}{{ question.quiz.name }}{% endblock %} +{% block "header" %}{{ question.quiz.name }}{% endblock %} + + {% block "body" %} -

{{ question.title }}

+

{{ question.title }}

-{{ question.text }} +{{ question.text|safe }}
-
+ {% csrf_token %} {{ form.answer.errors }} {{ form.answer }} {% if valid %} - + {% if previous_url %} - {% trans "Back to last question" %} + {% trans "Back to last question" %} {% endif %} {% else %} {% if valid_url %} - {% trans "Back to my test" %} + {% trans "Back to my test" %} {% else %} - {% trans "Start from the beginning" %} + {% trans "Start from the beginning" %} {% endif %} {% endif %} @@ -38,8 +43,8 @@
-
-{{ question.description }} +
+{{ question.description|safe }}
diff --git a/apps/quiz/templates/quiz/result_detail.html b/apps/quiz/templates/quiz/result_detail.html index 89b875c..6a06ec0 100755 --- a/apps/quiz/templates/quiz/result_detail.html +++ b/apps/quiz/templates/quiz/result_detail.html @@ -3,32 +3,31 @@ {% load url from future %} -{% block "body" %} +{% block "title" %}{{ result.quiz.name }}{% endblock %} +{% block "header" %}{{ result.quiz.name }}{% endblock %} -

{{ result.title }}

+{% block "body" %} +

{{ result.title }}

-{{ result.text }} +{{ result.text|safe }}
{% if valid %} {% if previous_url %} - {% trans "Back to last question" %} + {% trans "Back to last question" %} {% endif %} {% else %} {% if valid_url %} - {% trans "Back to my test" %} - {% else %} - {% trans "Start from the beginning" %} + {% trans "Back to my test" %} {% endif %} {% endif %} - -{% trans "Start again" %} +{% trans "Start from the beginning" %} {% endblock %} diff --git a/apps/quiz/views.py b/apps/quiz/views.py index 7160759..037f0c5 100644 --- a/apps/quiz/views.py +++ b/apps/quiz/views.py @@ -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()) diff --git a/koedquiz/settings.py b/koedquiz/settings.py index 52cd99a..c527648 100644 --- a/koedquiz/settings.py +++ b/koedquiz/settings.py @@ -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 index 0000000..928901c --- /dev/null +++ b/koedquiz/templates/404.html @@ -0,0 +1,67 @@ + + + + + + Nie ma takiej strony + + + + + + +
+

Nie znaleziono żądanej strony.

+ + Powrót do strony głównej. + +
+ + + diff --git a/koedquiz/templates/500.html b/koedquiz/templates/500.html new file mode 100755 index 0000000..92a02fa --- /dev/null +++ b/koedquiz/templates/500.html @@ -0,0 +1,49 @@ + + + + + + {% block "title" %}{% endblock %} + + + + + + +
+

Serwis jest chwilowo niedostępny. + Proszę spróbować jeszcze raz za chwilę. + Jeśli problem będzie się powtarzał, proszę skontaktować się + z administratorami.

+
+ + + diff --git a/koedquiz/templates/base.html b/koedquiz/templates/base.html index c6ffd3c..cc33400 100644 --- a/koedquiz/templates/base.html +++ b/koedquiz/templates/base.html @@ -4,10 +4,17 @@ {% block "title" %}{% endblock %} + - {% block "body" %}{% endblock %} + + +
+ {% block "body" %}{% endblock %} +
diff --git a/koedquiz/templates/home.html b/koedquiz/templates/home.html index 5c856b8..1e0c763 100644 --- a/koedquiz/templates/home.html +++ b/koedquiz/templates/home.html @@ -1,7 +1,16 @@ {% extends "base.html" %} + +{% block "title" %}{{ quiz.name }}{% endblock %} +{% block "header" %}{{ quiz.name }}{% endblock %} + + {% block "body" %} -Start quiz! +
+{{ quiz.description|safe }} +
+ +Start quiz! {% endblock %}