diff --git a/db.sqlite3 b/db.sqlite3
index 0cb670d..7596d46 100644
Binary files a/db.sqlite3 and b/db.sqlite3 differ
diff --git a/tkupek_elearning/elearning/migrations/0021_setting_token.py b/tkupek_elearning/elearning/migrations/0021_setting_token.py
new file mode 100644
index 0000000..b6a7317
--- /dev/null
+++ b/tkupek_elearning/elearning/migrations/0021_setting_token.py
@@ -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),
+ ),
+ ]
diff --git a/tkupek_elearning/elearning/models.py b/tkupek_elearning/elearning/models.py
index 4cc50b1..44defd0 100644
--- a/tkupek_elearning/elearning/models.py
+++ b/tkupek_elearning/elearning/models.py
@@ -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)
diff --git a/tkupek_elearning/elearning/templates/elearning.html b/tkupek_elearning/elearning/templates/elearning.html
index 287e40e..6802d0f 100644
--- a/tkupek_elearning/elearning/templates/elearning.html
+++ b/tkupek_elearning/elearning/templates/elearning.html
@@ -37,10 +37,6 @@
{{ 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),
+
]