From c78ca647e61028a75ed17d732fab6493450b24d4 Mon Sep 17 00:00:00 2001 From: tkupek Date: Sat, 5 Mar 2016 15:02:08 +0100 Subject: [PATCH] added popup when elearning is completed, added handler for multiple settings --- db.sqlite3 | Bin 137216 -> 137216 bytes .../0025_user_completed_message_shown.py | 20 +++++ .../migrations/0026_auto_20160305_1331.py | 25 +++++++ .../migrations/0027_auto_20160305_1333.py | 70 ++++++++++++++++++ .../migrations/0028_auto_20160305_1338.py | 20 +++++ tkupek_elearning/elearning/models.py | 33 ++++++--- .../elearning/static/js/elearning.js | 16 +++- .../elearning/templates/elearning.html | 30 +++++++- tkupek_elearning/elearning/views.py | 13 +++- tkupek_elearning/settings.py | 2 +- 10 files changed, 210 insertions(+), 19 deletions(-) create mode 100644 tkupek_elearning/elearning/migrations/0025_user_completed_message_shown.py create mode 100644 tkupek_elearning/elearning/migrations/0026_auto_20160305_1331.py create mode 100644 tkupek_elearning/elearning/migrations/0027_auto_20160305_1333.py create mode 100644 tkupek_elearning/elearning/migrations/0028_auto_20160305_1338.py diff --git a/db.sqlite3 b/db.sqlite3 index c2c53834cfc130732713e70c3143192ba0c001ad..0a4db407d2a075cae1cb3265592ffaad39d13d50 100644 GIT binary patch delta 5666 zcmcgw3vg8B6~6yDo7~M~^FYDy3O5l=P_o>|-n|cy5E4j$Jb;B-&`cV#mn00$r231jfPf*@Q^zfSs%7X${|r>g-vTJZs7(4lNR^hj3} z#~A$v{j2CF5H7re;G&@;SmG=06>?y(0R90-Fb|ti#ka5ucf<2|5C&mzsL*#K6vOL+ zB*5!q=im(HbUUqySZA!grN>DoNrL-)c16+hu|OxIYg%LN@s_on?TOZ8XFS$Z?&jsx zvxs|H&V=!}Pf)zkPx;WnN!zQ6+}$}BGSz({M`hZbx#o^pzAQvR!22|YkI4<=t zdkM$I{74hm8#y*`tmn9h<3bO`1sv-*)^eQBaURDS53{Q|&gEE@k>eej!~awc-F)SG zMvTf_albgY)ORI-oyg~DexKq#|39f&eRq+ZOf@feK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?{3LWtIUg%(~$^FMT#KyckSW`KEjsxOi{TM&Mcj+B^gI=Xy(jgJ| zYm_jv9?=GGn9PiFyf7P;6M}dY)YzY6~zE zYK36LJ)-Hp=@%bjt966nZ4GaW#K)n>(d`>svxY@q*v-t);wmBKK`}%Zw1Kh6lWcu> qM7aH8+$~0_7!A|nfAv3I)1iIr;lPBKypzJyAM=uD+7l6P$$tS44#2no diff --git a/tkupek_elearning/elearning/migrations/0025_user_completed_message_shown.py b/tkupek_elearning/elearning/migrations/0025_user_completed_message_shown.py new file mode 100644 index 0000000..a572c60 --- /dev/null +++ b/tkupek_elearning/elearning/migrations/0025_user_completed_message_shown.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.1 on 2016-03-05 12:48 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('elearning', '0024_auto_20160305_1222'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='completed_message_shown', + field=models.BooleanField(default=False), + ), + ] diff --git a/tkupek_elearning/elearning/migrations/0026_auto_20160305_1331.py b/tkupek_elearning/elearning/migrations/0026_auto_20160305_1331.py new file mode 100644 index 0000000..2b7c44e --- /dev/null +++ b/tkupek_elearning/elearning/migrations/0026_auto_20160305_1331.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.1 on 2016-03-05 13:31 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('elearning', '0025_user_completed_message_shown'), + ] + + operations = [ + migrations.AddField( + model_name='setting', + name='popup_completed_message', + field=models.TextField(null=True), + ), + migrations.AddField( + model_name='setting', + name='popup_completed_title', + field=models.CharField(max_length=100, null=True), + ), + ] diff --git a/tkupek_elearning/elearning/migrations/0027_auto_20160305_1333.py b/tkupek_elearning/elearning/migrations/0027_auto_20160305_1333.py new file mode 100644 index 0000000..d56f81b --- /dev/null +++ b/tkupek_elearning/elearning/migrations/0027_auto_20160305_1333.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.1 on 2016-03-05 13:33 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('elearning', '0026_auto_20160305_1331'), + ] + + operations = [ + migrations.AddField( + model_name='setting', + name='popup_leave_message', + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name='setting', + name='footer', + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name='setting', + name='logo', + field=models.CharField(blank=True, max_length=256), + ), + migrations.AlterField( + model_name='setting', + name='message_access_denied', + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name='setting', + name='message_already_answered', + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name='setting', + name='message_welcome_user', + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name='setting', + name='popup_completed_message', + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name='setting', + name='popup_completed_title', + field=models.CharField(blank=True, max_length=100, null=True), + ), + migrations.AlterField( + model_name='setting', + name='text_answer', + field=models.CharField(blank=True, max_length=100, null=True), + ), + migrations.AlterField( + model_name='setting', + name='text_next', + field=models.CharField(blank=True, max_length=100, null=True), + ), + migrations.AlterField( + model_name='setting', + name='text_solution', + field=models.CharField(blank=True, max_length=100, null=True), + ), + ] diff --git a/tkupek_elearning/elearning/migrations/0028_auto_20160305_1338.py b/tkupek_elearning/elearning/migrations/0028_auto_20160305_1338.py new file mode 100644 index 0000000..ddd36d6 --- /dev/null +++ b/tkupek_elearning/elearning/migrations/0028_auto_20160305_1338.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.1 on 2016-03-05 13:38 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('elearning', '0027_auto_20160305_1333'), + ] + + operations = [ + migrations.AlterField( + model_name='setting', + name='active', + field=models.BooleanField(default=False), + ), + ] diff --git a/tkupek_elearning/elearning/models.py b/tkupek_elearning/elearning/models.py index 4e4f6f3..45855a0 100644 --- a/tkupek_elearning/elearning/models.py +++ b/tkupek_elearning/elearning/models.py @@ -13,20 +13,34 @@ def gen_token(): class Setting(models.Model): title = models.CharField(max_length=100, 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) - text_answer = models.CharField(max_length=100, null=True) - text_solution = models.CharField(max_length=100, null=True) - text_next = models.CharField(max_length=100, null=True) - logo = models.CharField(max_length=256, null=False) - active = models.BooleanField(unique=True, default=False) + footer = models.TextField(null=True, blank=True) + message_welcome_user = models.TextField(null=True, blank=True) + message_access_denied = models.TextField(null=True, blank=True) + message_already_answered = models.TextField(null=True, blank=True) + text_answer = models.CharField(max_length=100, null=True, blank=True) + text_solution = models.CharField(max_length=100, null=True, blank=True) + text_next = models.CharField(max_length=100, null=True, blank=True) + popup_completed_title = models.CharField(max_length=100, null=True, blank=True) + popup_completed_message = models.TextField(null=True, blank=True) + popup_leave_message = models.TextField(null=True, blank=True) + logo = models.CharField(max_length=256, null=False, blank=True) + active = models.BooleanField(default=False) statistic_token = models.CharField(max_length=40, null=True, default=gen_token, unique=True) def __unicode__(self): return self.title + def save(self, *args, **kwargs): + if self.active: + try: + temp = Setting.objects.get(active=True) + if self != temp: + temp.active = False + temp.save() + except Setting.DoesNotExist: + pass + super(Setting, self).save(*args, **kwargs) + class Question(models.Model): id = models.AutoField(primary_key=True) @@ -52,6 +66,7 @@ class User(models.Model): token = models.CharField(max_length=40, null=True, default=gen_token, unique=True) name = models.CharField(max_length=100, null=False) last_seen = models.DateTimeField(null=True, blank=True) + completed_message_shown = models.BooleanField(null=False, default=False) def __unicode__(self): return self.name diff --git a/tkupek_elearning/elearning/static/js/elearning.js b/tkupek_elearning/elearning/static/js/elearning.js index 1d92732..346dabe 100644 --- a/tkupek_elearning/elearning/static/js/elearning.js +++ b/tkupek_elearning/elearning/static/js/elearning.js @@ -22,6 +22,10 @@ var QueryString = function () { }(); window.onload = init(); +//window.onbeforeunload = function() { + //var message = document.getElementById("popup-leave-message").innerHTML; + //return message; + //} function init() { enable_disable_question(); @@ -45,7 +49,6 @@ function enable_disable_question() { } } - function toggle_solution(id) { var element = document.getElementById("explanation_" + id); @@ -137,8 +140,13 @@ function getCheckboxAnswers(id) { function parseResponse(id, responseText) { - var correctOptions = JSON.parse(responseText).options_id; - var progress = JSON.parse(responseText).progress; + var parse = JSON.parse(responseText); + var correctOptions = parse.options_id; + var progress = parse.progress; + + if(parse.show_completed) { + $('#completed-modal').modal('show'); + } setCorrectOptions(correctOptions, id) setProgress(progress) @@ -176,6 +184,7 @@ function setCorrectOptions(correctOptions, id) { function setProgress(progress) { progressbar = document.getElementById("progressbar"); progressbar.style.width = progress + "%"; + progressbar.innerHTML = progress + "%"; } function ajaxRequest() { @@ -196,4 +205,3 @@ function ajaxRequest() { else return false } - diff --git a/tkupek_elearning/elearning/templates/elearning.html b/tkupek_elearning/elearning/templates/elearning.html index 7ca0743..4b2d4b4 100644 --- a/tkupek_elearning/elearning/templates/elearning.html +++ b/tkupek_elearning/elearning/templates/elearning.html @@ -11,22 +11,50 @@ {{ settings.title }} + + + + + + + + + +
- + {% if settings.logo %} + + {% endif %}

{{ settings.title }}

{{ settings.message_welcome_user|safe }}

+ {{ progress }}%

diff --git a/tkupek_elearning/elearning/views.py b/tkupek_elearning/elearning/views.py index f1ad9b9..4e381ad 100644 --- a/tkupek_elearning/elearning/views.py +++ b/tkupek_elearning/elearning/views.py @@ -14,8 +14,7 @@ from tkupek_elearning.elearning.models import Setting, Question, Option, UserAns def get_progress(user): progress_max = Question.objects.all().count() progress_current = UserAnswer.objects.filter(user=user.id).count() - progress = str(int(progress_current / progress_max * 100)) - return progress + return int(progress_current / progress_max * 100) def start(request): @@ -84,7 +83,6 @@ def get_answer(request): options_id = [] for option in correct_options: options_id.append(option.id) - options_id = json.dumps(options_id) user_answer = get_user_answer(question, user) @@ -111,7 +109,14 @@ def get_answer(request): user_answer_options.option = Option.objects.get(id=option) user_answer_options.save() - holder = {'options_id': options_id, 'progress': get_progress(user)} + progress = get_progress(user) + show_completed = False + if progress is 100 and user.completed_message_shown is False: + show_completed = True + user.completed_message_shown = True + user.save() + + holder = {'options_id': options_id, 'progress': str(progress), 'show_completed': show_completed} holder = json.dumps(holder) return HttpResponse(holder) diff --git a/tkupek_elearning/settings.py b/tkupek_elearning/settings.py index 381b514..5b3dca0 100644 --- a/tkupek_elearning/settings.py +++ b/tkupek_elearning/settings.py @@ -25,7 +25,7 @@ SECRET_KEY = '_*hrxgzo(8hkrp5f8n4j9vo15acsy0b88yiy$6d5ezwi&pns(j' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["127.0.0.1", "localhost"] # Application definition