diff --git a/.idea/misc.xml b/.idea/misc.xml index b83ca74..8565230 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,8 @@ + + + diff --git a/db.sqlite3 b/db.sqlite3 index 41e595a..bbf6c74 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/tkupek_elearning/elearning/exampledata.sql b/tkupek_elearning/elearning/exampledata.sql deleted file mode 100644 index e5c988e..0000000 --- a/tkupek_elearning/elearning/exampledata.sql +++ /dev/null @@ -1,7 +0,0 @@ -#Settings -INSERT INTO elearning_setting (title, message, active) VALUES ('vcp bayern - elearning', 'servus beim elearning des vcp land bayern!', 1); - -#Questions -INSERT INTO elearning_question (id, title, text, options, answer, explanation) VALUES (0, 'Bananen', 'Warum ist die Banane krumm?', 'eins zwei oder drei', 1, 'darum'); -INSERT INTO elearning_question (id, title, text, options, answer, explanation) VALUES (1, 'Einstein', 'Wie lautet die Relativitätstheorie?', 'oben unten rechts links', 2, 'ich nehm die drei'); -INSERT INTO elearning_question (id, title, text, options, answer, explanation) VALUES (2, 'Wetter', 'Wie wird das Wetter?', 'gut schlecht dramatisch', 3, 'darum'); \ No newline at end of file diff --git a/tkupek_elearning/elearning/models.py b/tkupek_elearning/elearning/models.py index e360896..44143f5 100644 --- a/tkupek_elearning/elearning/models.py +++ b/tkupek_elearning/elearning/models.py @@ -3,9 +3,7 @@ from __future__ import unicode_literals import hashlib import os -import binascii from django.db import models -from django.db.models.signals import post_init, pre_init class Setting(models.Model): @@ -49,6 +47,7 @@ class User(models.Model): token = models.CharField(max_length=40, null=True, default=gen_token) name = models.CharField(max_length=100, null=False) + last_seen = models.DateTimeField(null=True) def __str__(self): return self.name @@ -63,4 +62,4 @@ class UserAnswer(models.Model): return str(self.user) + " - " + str(self.question) class Meta: - unique_together = (('user', 'question'),) \ No newline at end of file + unique_together = (('user', 'question'),) diff --git a/tkupek_elearning/elearning/static/css/style.css b/tkupek_elearning/elearning/static/css/style.css index 58ff5ad..538b0f9 100644 --- a/tkupek_elearning/elearning/static/css/style.css +++ b/tkupek_elearning/elearning/static/css/style.css @@ -51,3 +51,7 @@ p[id^="explanation_"] { .message_already_answered { font-style: italic; } + +.table_headline { + font-weight: bold; +} \ No newline at end of file diff --git a/tkupek_elearning/elearning/templates/access_denied.html b/tkupek_elearning/elearning/templates/access_denied.html index 8c3bb16..9215ec8 100644 --- a/tkupek_elearning/elearning/templates/access_denied.html +++ b/tkupek_elearning/elearning/templates/access_denied.html @@ -7,7 +7,6 @@ {% load staticfiles %} - {{ settings.title }} diff --git a/tkupek_elearning/elearning/templates/elearning.html b/tkupek_elearning/elearning/templates/elearning.html index 10c7359..09d3053 100644 --- a/tkupek_elearning/elearning/templates/elearning.html +++ b/tkupek_elearning/elearning/templates/elearning.html @@ -39,7 +39,7 @@

{{ question.explanation }}

-
+
{% endfor %}
diff --git a/tkupek_elearning/elearning/templates/statistic.html b/tkupek_elearning/elearning/templates/statistic.html new file mode 100644 index 0000000..ff00014 --- /dev/null +++ b/tkupek_elearning/elearning/templates/statistic.html @@ -0,0 +1,61 @@ + + + + + + + {% load staticfiles %} + + + {{ settings.title }} + + + + +
+ +

{{ settings.title }}

+

Welcome to the statistic backend!

+
+
+ +

Users

+ + + + + + + {% for user in users %} + + + + + + {% endfor %} +
namequestions answeredlast seen
{{ user.name }}{{ user.questions_answered }}{{ user.last_seen }}
+ +
+ +

Questions

+ + + + + + {% for question in questions %} + + + + + {% endfor %} +
titleanswers
{{ question.title }}{{ question.answers }}
+ +
+
+ {{ settings.footer }} + +
+ + + \ No newline at end of file diff --git a/tkupek_elearning/elearning/tests.py b/tkupek_elearning/elearning/tests.py index 4d66077..a79ca8b 100644 --- a/tkupek_elearning/elearning/tests.py +++ b/tkupek_elearning/elearning/tests.py @@ -1,3 +1,3 @@ -#from django.test import TestCase +# from django.test import TestCase # Create your tests here. diff --git a/tkupek_elearning/elearning/views.py b/tkupek_elearning/elearning/views.py index 39f7b34..25ec108 100644 --- a/tkupek_elearning/elearning/views.py +++ b/tkupek_elearning/elearning/views.py @@ -1,12 +1,14 @@ +import datetime from django.core.exceptions import ObjectDoesNotExist from django.http import HttpResponse from django.shortcuts import render_to_response from tkupek_elearning.elearning.models import Setting, Question, Option, UserAnswer, User -import pdb +# import pdb -def home(request): + +def start(request): token = request.GET.get('token') @@ -15,11 +17,12 @@ def home(request): except ObjectDoesNotExist: user = None - settings = Setting.objects.filter(active=1) - if settings: - settings = settings[0] + settings = Setting.objects.get(active=1) if user is not None: + + log_last_seen(user) + settings.message_welcome_user = settings.message_welcome_user.replace('{username}', user.name) questions_options = {} @@ -52,6 +55,7 @@ def get_answer(request): question = Question.objects.get(id=request_id) user = User.objects.get(token=request_token) + log_last_seen(user) user_answer = get_user_answer(question, user) @@ -80,4 +84,24 @@ def get_user_answer(question, user): except ObjectDoesNotExist: user_answer = None - return user_answer; \ No newline at end of file + return user_answer + + +def log_last_seen(user): + user.last_seen = datetime.datetime.now() + user.save() + + +def statistic(): + + settings = Setting.objects.get(active=1) + users = User.objects.all() + + for user in users: + user.questions_answered = UserAnswer.objects.filter(user=user.id).count() + + questions = Question.objects.all() + for question in questions: + question.answers = UserAnswer.objects.filter(question=question.id).count() + + return render_to_response('statistic.html', {'settings': settings, 'users': users, 'questions': questions}) diff --git a/tkupek_elearning/urls.py b/tkupek_elearning/urls.py index 5be92b7..0330621 100644 --- a/tkupek_elearning/urls.py +++ b/tkupek_elearning/urls.py @@ -20,6 +20,7 @@ import tkupek_elearning.elearning.views urlpatterns = [ url(r'^admin/', admin.site.urls), - url(r'start', tkupek_elearning.elearning.views.home), - url(r'api', tkupek_elearning.elearning.views.get_answer) + url(r'start', tkupek_elearning.elearning.views.start), + url(r'api', tkupek_elearning.elearning.views.get_answer), + url(r'statistic', tkupek_elearning.elearning.views.statistic) ]