authentification of statistic backend
This commit is contained in:
parent
1c0927ca1c
commit
fceeb63f9f
6 changed files with 56 additions and 20 deletions
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
21
tkupek_elearning/elearning/migrations/0021_setting_token.py
Normal file
21
tkupek_elearning/elearning/migrations/0021_setting_token.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.1 on 2016-03-03 20:57
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import tkupek_elearning.elearning.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('elearning', '0020_setting_text_next'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='setting',
|
||||
name='token',
|
||||
field=models.CharField(default=tkupek_elearning.elearning.models.gen_token, max_length=40, null=True),
|
||||
),
|
||||
]
|
|
@ -6,6 +6,10 @@ import os
|
|||
from django.db import models
|
||||
|
||||
|
||||
def gen_token():
|
||||
return hashlib.sha1(os.urandom(128)).hexdigest()
|
||||
|
||||
|
||||
class Setting(models.Model):
|
||||
title = models.CharField(max_length=100, null=True)
|
||||
footer = models.TextField(null=True)
|
||||
|
@ -17,6 +21,7 @@ class Setting(models.Model):
|
|||
text_next = models.CharField(max_length=100, null=True)
|
||||
logo = models.CharField(max_length=256, null=False)
|
||||
active = models.BooleanField(unique=True, default=False)
|
||||
token = models.CharField(max_length=40, null=True, default=gen_token)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
|
@ -41,10 +46,6 @@ class Option(models.Model):
|
|||
return self.text
|
||||
|
||||
|
||||
def gen_token():
|
||||
return hashlib.sha1(os.urandom(128)).hexdigest()
|
||||
|
||||
|
||||
class User(models.Model):
|
||||
|
||||
token = models.CharField(max_length=40, null=True, default=gen_token)
|
||||
|
|
|
@ -37,10 +37,6 @@
|
|||
<h2>{{ question.id }}: {{ question.title }}</h2>
|
||||
<p>{{ question.text }}</p>
|
||||
|
||||
<p id="enable-{{ question.id }}" data-value="{{ question.enable }}" data-questionId= "{{ question.id }}" class="message_already_answered hide">
|
||||
{{ settings.message_already_answered }}
|
||||
</p>
|
||||
|
||||
<ul class="list-group ">
|
||||
{% for option in options %}
|
||||
<li name="checkbox_div_{{ question.id }}" class="list-group-item">
|
||||
|
@ -52,6 +48,10 @@
|
|||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<p id="enable-{{ question.id }}" data-value="{{ question.enable }}" data-questionId= "{{ question.id }}" class="message_already_answered hide">
|
||||
{{ settings.message_already_answered }}
|
||||
</p>
|
||||
|
||||
<div class="container">
|
||||
<button class="btn btn-default show" type="button" id="showSolution_{{ question.id }}" onmouseup="get_answer({{ question.id }})">{{ settings.text_solution }}</button>
|
||||
<button class="btn btn-default hide" type="button" id="next_{{ question.id }}" onmouseup="scrollToNextQuestion({{ question.id }})">{{ settings.text_next }}</button>
|
||||
|
|
|
@ -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})
|
|
@ -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),
|
||||
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue