From fc15b01d66f55e4a9e1a74198aa45a0987f55ed3 Mon Sep 17 00:00:00 2001 From: tkupek Date: Sun, 14 Feb 2016 16:15:13 +0100 Subject: [PATCH] added first implementation of statistic backend --- .idea/misc.xml | 3 + db.sqlite3 | Bin 70656 -> 70656 bytes tkupek_elearning/elearning/exampledata.sql | 7 -- tkupek_elearning/elearning/models.py | 5 +- .../elearning/static/css/style.css | 4 ++ .../elearning/templates/access_denied.html | 1 - .../elearning/templates/elearning.html | 2 +- .../elearning/templates/statistic.html | 61 ++++++++++++++++++ tkupek_elearning/elearning/tests.py | 2 +- tkupek_elearning/elearning/views.py | 36 +++++++++-- tkupek_elearning/urls.py | 5 +- 11 files changed, 105 insertions(+), 21 deletions(-) delete mode 100644 tkupek_elearning/elearning/exampledata.sql create mode 100644 tkupek_elearning/elearning/templates/statistic.html 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 41e595aa2f11886dc80ebe65cc36f5f05d1653ed..bbf6c742dbf15594fda6cfa5c9aa16d3a442d5cb 100644 GIT binary patch delta 1105 zcmaizU1$_n6vywqXLct$ag7PtT~keVl33Xk-OS9+uKR)1X(&F_6hG=ii;@n_m~0a_ zVRvmyE!ByF*rIf~LZxptFH#F(GJPo27>OWgp`{u_kWg)Cp()Z5sP zKX(}J?|=Shm^pY_ICxrkZ&m#bLddhIG)h99tgK7W8_vt0ihc;Qd+eTLR~R3Y`~tj4 znkq(!e<3wJ5eYHqq`j}2g}$Mlz4^YPS8N|>NNr67z9D|NOyDapf`*d{_BQ`As?v=P>luQFkz4*kb{pMyA#CC%tyML z4SsV{UfW%a%Ukn>0Zma;>lJOis>`aL)$vNkld76fRcsTh*lWb?f{*NOH~2@Bu_s@! zN@dwAR`C%qxgnlODoI6m>9i>L0>~?T*<3qSTxD(=T7qPZz$Cm48`)j<8GDmu=pS@~ zzD0B778$G9$2R6x`$#llSc8^XEaVG)3TErsSF(ydgJ!ARQ?jhWgIzTxtEyhyOgin} zx)~Dd=m7%6A(v zi?8&X#h9*i@XAP-A01iIe7|R#+-sJta(=HRKfiO!mJS?js$!pWjUO%q4@jhyu-j~k zy~B1fN{4AZIYai~LvM9O1Ej8+Gt5?3?A}&2Nn3~m})c*b?{v)2umsMr{ fQdQ;as&W2qwQsqeO{iH#k0(=^Ogc46?>7DkyAm9S delta 703 zcmY*UO-Phc6n*!dr{CxNkEvr$;)E>}WSnnwCPhLGTC|V~i#EkH=x7$H=s;2tW{aqW zWX~41Y$dn|=PL+oDhz}yjLaqp`=y13^aCmOL-uBL(}R28edpeD&w2f$qJLCe^}1&m zV|!H8sIaQIK2%XfGvmkZYT0}p1t>7xVu;IImTby7);Db^#+S7rVRE?99>Q;*-b zzoYY{5sQXfW8vzSwoueCVxeejwAyG1w}nH&P))57OFX1a&+`l`_=I10i?5hh-e;9? z67uDfyvi&P30FG9DUd^sbjj@&7MVO0se!*fjG9ul~%m^UC3FG?zHt}NyuG6E4JD7fy-VostOaH~V%Ib=kFkt(j+ zGjNFWJ4Bj(%_gWp+7?PFYz7wQu+7Gn86My~cJV)af}i2F^p}!!j_TO5bc?6v^80+v zsl0#&84dDAB#~4es)?FZf3M|2Af|cB%W1$XCl - {{ 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) ]