diff --git a/db.sqlite3 b/db.sqlite3 index ff2ac8a..41e595a 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/tkupek_elearning/elearning/models.py b/tkupek_elearning/elearning/models.py index 42bf6fe..e360896 100644 --- a/tkupek_elearning/elearning/models.py +++ b/tkupek_elearning/elearning/models.py @@ -1,16 +1,21 @@ from __future__ import unicode_literals -import uuid +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): title = models.CharField(max_length=100, null=True) - message = models.TextField(null=True) footer = models.TextField(null=True) + message_welcome_user = models.TextField(null=True) + message_access_denied = models.TextField(null=True) + message_already_answered = models.TextField(null=True) button_solution = models.CharField(max_length=100, null=True) + logo = models.CharField(max_length=256, null=True) active = models.BooleanField(unique=True, default=False) def __str__(self): @@ -36,8 +41,13 @@ 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=32, null=True) + + token = models.CharField(max_length=40, null=True, default=gen_token) name = models.CharField(max_length=100, null=False) def __str__(self): diff --git a/tkupek_elearning/elearning/static/css/style.css b/tkupek_elearning/elearning/static/css/style.css index 2702043..58ff5ad 100644 --- a/tkupek_elearning/elearning/static/css/style.css +++ b/tkupek_elearning/elearning/static/css/style.css @@ -41,3 +41,13 @@ p[id^="explanation_"] { .failed { outline: 4px solid #a60000; } + +.mainLogo { + width: 300px; + height: auto; + float: right; +} + +.message_already_answered { + font-style: italic; +} diff --git a/tkupek_elearning/elearning/static/js/elearning.js b/tkupek_elearning/elearning/static/js/elearning.js index 6a2e8f0..12a0171 100644 --- a/tkupek_elearning/elearning/static/js/elearning.js +++ b/tkupek_elearning/elearning/static/js/elearning.js @@ -1,6 +1,54 @@ +var QueryString = function () { + // This function is anonymous, is executed immediately and + // the return value is assigned to QueryString! + var query_string = {}; + var query = window.location.search.substring(1); + var vars = query.split("&"); + for (var i=0;i + + + + + + {% load staticfiles %} + + + + {{ settings.title }} + + + + +
+ +

{{ settings.title }}

+
+

{{ settings.message_access_denied }}

+ +
+ + + \ No newline at end of file diff --git a/tkupek_elearning/elearning/templates/index.html b/tkupek_elearning/elearning/templates/elearning.html similarity index 76% rename from tkupek_elearning/elearning/templates/index.html rename to tkupek_elearning/elearning/templates/elearning.html index 7158005..10c7359 100644 --- a/tkupek_elearning/elearning/templates/index.html +++ b/tkupek_elearning/elearning/templates/elearning.html @@ -7,15 +7,15 @@ {% load staticfiles %} - {{ settings.title }}
+

{{ settings.title }}

-

{{ settings.message }}

+

{{ settings.message_welcome_user }}


@@ -23,6 +23,10 @@

{{ question.id }}: {{ question.title }}

{{ question.text }}

+

+ {{ settings.message_already_answered }} +

+
{% for option in options %} @@ -44,5 +48,6 @@
+ \ No newline at end of file diff --git a/tkupek_elearning/elearning/views.py b/tkupek_elearning/elearning/views.py index dc452e8..39f7b34 100644 --- a/tkupek_elearning/elearning/views.py +++ b/tkupek_elearning/elearning/views.py @@ -4,20 +4,43 @@ 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): + + token = request.GET.get('token') + + try: + user = User.objects.get(token=token) + except ObjectDoesNotExist: + user = None + settings = Setting.objects.filter(active=1) if settings: settings = settings[0] - questions_options = {} - questions = Question.objects.all() - for question in questions: - options = Option.objects.filter(question=question.id) - questions_options[question] = options + if user is not None: + settings.message_welcome_user = settings.message_welcome_user.replace('{username}', user.name) - return render_to_response('index.html', {'settings': settings, 'questions_options': questions_options}) + questions_options = {} + questions = Question.objects.all() + for question in questions: + options = Option.objects.filter(question=question.id) + + user_answer = get_user_answer(question, user) + + if user_answer is None: + question.enable = True + else: + question.enable = False + + questions_options[question] = options + questions_options[question] = options + + return render_to_response('elearning.html', {'settings': settings, 'questions_options': questions_options}) + + else: + return render_to_response('access_denied.html', {'settings': settings}) def get_answer(request): @@ -30,10 +53,7 @@ def get_answer(request): question = Question.objects.get(id=request_id) user = User.objects.get(token=request_token) - try: - user_answer = UserAnswer.objects.get(question=question.id, user=user.id) - except ObjectDoesNotExist: - user_answer = None + user_answer = get_user_answer(question, user) if user_answer is None: user_answer = UserAnswer() @@ -52,3 +72,12 @@ def get_answer(request): options_id = options_id[:-1] return HttpResponse(options_id) + + +def get_user_answer(question, user): + try: + user_answer = UserAnswer.objects.get(question=question.id, user=user.id) + except ObjectDoesNotExist: + user_answer = None + + return user_answer; \ No newline at end of file