From fceeb63f9fa0131f8d95b4e6d01619aec0a2dabd Mon Sep 17 00:00:00 2001 From: tkupek Date: Thu, 3 Mar 2016 22:00:14 +0100 Subject: [PATCH] authentification of statistic backend --- db.sqlite3 | Bin 106496 -> 107520 bytes .../migrations/0021_setting_token.py | 21 +++++++++++ tkupek_elearning/elearning/models.py | 9 +++-- .../elearning/templates/elearning.html | 8 ++-- tkupek_elearning/elearning/views.py | 35 ++++++++++++------ tkupek_elearning/urls.py | 3 +- 6 files changed, 56 insertions(+), 20 deletions(-) create mode 100644 tkupek_elearning/elearning/migrations/0021_setting_token.py diff --git a/db.sqlite3 b/db.sqlite3 index 0cb670df613a1dbcd1acf957f0f39dd1362abb08..7596d4626f6fa1235f5e1797b442bc466768a65e 100644 GIT binary patch delta 2841 zcma)8Yiv}<6}~gy-Fx=|*z019*T&wL_u&}(?p^Q8wwf#;=fNWn5|I>ASnLfoU<0;+ z(A3(Pn7Az!uPfvqQKVK>^r1$MvPzt)NHma2X@gXtKY*&Vp;U@ODmCk9+b9Br(3b75f9w)Open+6NRecJ|x0@ggw3f63`^`zN-))7xX3%@bvOlW>`v61wf zMn@{yVPsp)Y$9!D%OA9bmmz>oOCQd2bkYphx#j?4?tqoweVV$~S^D$TwT`-~;85XW zfpX!6W6p(6TqOULwYZHNxQ@T#L;M++aghv9g2(*j%j03Ej#rd=sLXO63I(b$7t8P@ zy08K&TF{Pqgh`)y>C?CQ)4IwS<9ZOb!o!-%T#Se8s=LufPlJulW*c2`8yztl5w%f^ z*r+yH>#Y0R$YW8&6SYBUoW`1Ite8ffu>2dVV-5oRmZg8cwfYe(K?h7UBM2X=;0EWn z$m!Sl8aYYa7q+q1b~aWKl=Y}9V58G-qizQgsj`EJco)g`CQrS@uv#Z$4*9Idk4+w5 z#?&`{%xLW=iOUSbr^Mn7d=;Ny6Ru$he?b9%L_aPfgY$R_d$1NIJdAyK6#H=)6L=NJ z@Ds9_dCBRI`4X|v#Ipb%7E2qFOW!D@r$I<(vyiU1kd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DvL%*^2mVhJ8lJXA0V; za0EHtIkzc{BpO}$dZpEZJQ{hD|58GaOHcNbrz-q*aW?Kgw0AJ0EaAuGXyaJO@i<40 zV+uzBrx?M(w}d&5TcxNsFp5vuz%%$2$8nu)`T_6b8w}!0)Z+r~!6wW>7h3Qf9>9xu z1iR3Nezao`mb0B5cpGat>5nwqf)KJ)VW32zlTjF)q%bs5VR(YVNLpburLdq_VJxYT zZQ3+gSEi&LRcJ*Nnqh?qDWsqYM>yVv!JJu_#43Y}{|A1-HGGfDxQNd&j8iy@LtN}m zY{LuKf!$ceMSlu!U<3B!J)Ua~#;9bI^ z%^+h&Bud+Dqb`JOQmTkJmg*@0+; z7Z0P^pcA6UXm(>}gLmTey~67`HA~pSn%`sP-I0qKZ|z6pMKq`eqtCz)`tUVp?}1s4 z`NBPSI^%wDabAq74O7?#f4PS`u@M_N;qTtUOH+k1c|NyVyw0zBMGzP;_(-3`0B3mx z-oUp@s{@2CgA3fnT^;D}8Y{YkYI=ffgKX{`6=Sz;5QRo#ciSc>)g9}evlXd|p&KpY zs@Rth**6DndzCha%vLd)@|{zy)#6rMp9;ES;3i)w*Kh@wcu#%Itmd`HC*g+-(E8(pU>Je%Fr#V3ND3`mkCS_DXDv~WmH(jrK5 zq81^N6SN4EOe^6;NTzg8lw`3M1tgPN#7HKzC?q@1!U;I`c+Ek3oaT^SWEuTSdqsA- zjOw8_$%qyf$*>kC$&eNx8PtNvb}YjY0qQ^AD`xH|wXxD>fW$3B+`{{ question.id }}: {{ question.title }}

{{ question.text }}

-

- {{ settings.message_already_answered }} -

-
    {% for option in options %}
  • @@ -52,6 +48,10 @@ {% endfor %}
+

+ {{ settings.message_already_answered }} +

+
diff --git a/tkupek_elearning/elearning/views.py b/tkupek_elearning/elearning/views.py index 44a232f..be7950a 100644 --- a/tkupek_elearning/elearning/views.py +++ b/tkupek_elearning/elearning/views.py @@ -127,18 +127,31 @@ def log_last_seen(user): def statistic(request): + token = request.GET.get('token') + + try: + auth = Setting.objects.get(active=1, token=token) + except ObjectDoesNotExist: + auth = None + settings = Setting.objects.get(active=1) - users = User.objects.all() - for user in users: - user.questions_answered = UserAnswer.objects.filter(user=user.id).count() + if auth is not None: + settings = Setting.objects.get(active=1) + users = User.objects.all() - questions = Question.objects.all() - for question in questions: - question.answers = UserAnswer.objects.filter(question=question.id).count() - question.correct_answers = UserAnswer.objects.filter(question=question.id, correct=True).count() - if question.answers: - question.correct_answers_percentage = str(int(question.correct_answers / question.answers * 100)) - question.correct_answers_percentage += str(' %') + for user in users: + user.questions_answered = UserAnswer.objects.filter(user=user.id).count() - return render_to_response('statistic.html', {'settings': settings, 'users': users, 'questions': questions}) + questions = Question.objects.all() + for question in questions: + question.answers = UserAnswer.objects.filter(question=question.id).count() + question.correct_answers = UserAnswer.objects.filter(question=question.id, correct=True).count() + if question.answers: + question.correct_answers_percentage = str(int(question.correct_answers / question.answers * 100)) + question.correct_answers_percentage += str(' %') + + return render_to_response('statistic.html', {'settings': settings, 'users': users, 'questions': questions}) + + else: + return render_to_response('access_denied.html', {'settings': settings}) \ No newline at end of file diff --git a/tkupek_elearning/urls.py b/tkupek_elearning/urls.py index 0330621..646d63b 100644 --- a/tkupek_elearning/urls.py +++ b/tkupek_elearning/urls.py @@ -22,5 +22,6 @@ urlpatterns = [ url(r'^admin/', admin.site.urls), 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) + url(r'statistic', tkupek_elearning.elearning.views.statistic), + ]