diff --git a/db.sqlite3 b/db.sqlite3 index b4ff743..0cb670d 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/tkupek_elearning/elearning/admin.py b/tkupek_elearning/elearning/admin.py index 8e41476..996a8b3 100644 --- a/tkupek_elearning/elearning/admin.py +++ b/tkupek_elearning/elearning/admin.py @@ -24,4 +24,4 @@ class UserAdmin(admin.ModelAdmin): admin.site.register(Question, QuestionAdmin) admin.site.register(Setting), -admin.site.register(User, UserAdmin) \ No newline at end of file +admin.site.register(User, UserAdmin) diff --git a/tkupek_elearning/elearning/migrations/0018_auto_20160221_1705.py b/tkupek_elearning/elearning/migrations/0018_auto_20160221_1705.py new file mode 100644 index 0000000..b1ab113 --- /dev/null +++ b/tkupek_elearning/elearning/migrations/0018_auto_20160221_1705.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.2 on 2016-02-21 17:05 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('elearning', '0017_auto_20160214_1534'), + ] + + operations = [ + migrations.AddField( + model_name='useranswer', + name='correct', + field=models.NullBooleanField(), + ), + migrations.AlterField( + model_name='setting', + name='logo', + field=models.CharField(default='test', max_length=256), + preserve_default=False, + ), + ] diff --git a/tkupek_elearning/elearning/migrations/0019_auto_20160221_1754.py b/tkupek_elearning/elearning/migrations/0019_auto_20160221_1754.py new file mode 100644 index 0000000..10d8186 --- /dev/null +++ b/tkupek_elearning/elearning/migrations/0019_auto_20160221_1754.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.2 on 2016-02-21 17:54 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('elearning', '0018_auto_20160221_1705'), + ] + + operations = [ + migrations.RenameField( + model_name='setting', + old_name='button_solution', + new_name='text_solution', + ), + migrations.AddField( + model_name='setting', + name='text_answer', + field=models.CharField(max_length=100, null=True), + ), + migrations.AlterField( + model_name='option', + name='text', + field=models.CharField(max_length=256, null=True), + ), + ] diff --git a/tkupek_elearning/elearning/migrations/0020_setting_text_next.py b/tkupek_elearning/elearning/migrations/0020_setting_text_next.py new file mode 100644 index 0000000..666591e --- /dev/null +++ b/tkupek_elearning/elearning/migrations/0020_setting_text_next.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.2 on 2016-02-21 20:50 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('elearning', '0019_auto_20160221_1754'), + ] + + operations = [ + migrations.AddField( + model_name='setting', + name='text_next', + field=models.CharField(max_length=100, null=True), + ), + ] diff --git a/tkupek_elearning/elearning/models.py b/tkupek_elearning/elearning/models.py index cca2f4f..4cc50b1 100644 --- a/tkupek_elearning/elearning/models.py +++ b/tkupek_elearning/elearning/models.py @@ -12,11 +12,13 @@ class Setting(models.Model): 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) + 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) - def __str__(self): + def __unicode__(self): return self.title @@ -26,16 +28,16 @@ class Question(models.Model): text = models.TextField(null=True) explanation = models.TextField(null=True) - def __str__(self): + def __unicode__(self): return self.title class Option(models.Model): - text = models.CharField(max_length=100, null=True) + text = models.CharField(max_length=256, null=True) correct = models.BooleanField(null=False, default=False) question = models.ForeignKey(Question, on_delete=models.CASCADE, null=False) - def __str__(self): + def __unicode__(self): return self.text @@ -49,7 +51,7 @@ class User(models.Model): name = models.CharField(max_length=100, null=False) last_seen = models.DateTimeField(null=True) - def __str__(self): + def __unicode__(self): return self.name @@ -58,8 +60,8 @@ class UserAnswer(models.Model): question = models.ForeignKey(Question, on_delete=models.CASCADE, null=False) correct = models.NullBooleanField(null=True) - def __str__(self): - return str(self.user) + " - " + str(self.question) + def __unicode__(self): + return str(self.user) + " - " + str(self.question.id) class Meta: unique_together = (('user', 'question'),) @@ -71,3 +73,6 @@ class UserAnswerOptions(models.Model): class Meta: unique_together = (('user_answer', 'option'),) + + def __unicode__(self): + return str(self.user_answer) + " - " + str(self.option) diff --git a/tkupek_elearning/elearning/static/css/style.css b/tkupek_elearning/elearning/static/css/style.css index 538b0f9..a0df864 100644 --- a/tkupek_elearning/elearning/static/css/style.css +++ b/tkupek_elearning/elearning/static/css/style.css @@ -34,12 +34,8 @@ p[id^="explanation_"] { margin-top: 50px; } -.correct { - outline: 4px solid #00a353; -} - -.failed { - outline: 4px solid #a60000; +.margin75 { + margin-top: 75px; } .mainLogo { @@ -54,4 +50,8 @@ p[id^="explanation_"] { .table_headline { font-weight: bold; +} + +.footer { + color: #b3b3b3 } \ No newline at end of file diff --git a/tkupek_elearning/elearning/static/js/elearning.js b/tkupek_elearning/elearning/static/js/elearning.js index 02c9ad1..1d92732 100644 --- a/tkupek_elearning/elearning/static/js/elearning.js +++ b/tkupek_elearning/elearning/static/js/elearning.js @@ -59,8 +59,8 @@ function toggle_solution(id) function show_solution(id) { var element = document.getElementById("explanation_" + id); - if (element.className == "hide") { - element.className = "show"; + if (element.className.indexOf("hide") > -1) { + element.className = element.className.replace("hide", "show"); } } @@ -76,9 +76,10 @@ function get_answer(id) { if (answerRequest.readyState==4){ if (answerRequest.status==200 || window.location.href.indexOf("http")==-1){ parseResponse(id, answerRequest.responseText); + setButtonToNext(id); } else{ - alert("An error has occured making the request"); + alert("Sorry, sending your answer was not successful!"); } } } @@ -91,6 +92,35 @@ function get_answer(id) { answerRequest.send(null) } +function setButtonToNext(id) { + button = document.getElementById('showSolution_' + id); + button.className = button.className.replace("show", "hide"); + + if(getNextQuestion(id)) { + button = document.getElementById('next_' + id); + button.className = button.className.replace("hide", "show"); + } +} + +function scrollToNextQuestion(id) { + var nextQuestion = getNextQuestion(id); + + if(nextQuestion) { + location.href = "#" + nextQuestion.id; + } +} + +function getNextQuestion(id) { + var questions = document.getElementsByName("question"); + + for(var i = 0; i < questions.length; i++) { + if(questions[i].id == "question_" + id) { + return questions[i+1]; + } + } + return null; +} + function getCheckboxAnswers(id) { var answers = []; @@ -107,32 +137,45 @@ function getCheckboxAnswers(id) { function parseResponse(id, responseText) { - var correctOptions = JSON.parse(responseText); + var correctOptions = JSON.parse(responseText).options_id; + var progress = JSON.parse(responseText).progress; + setCorrectOptions(correctOptions, id) + setProgress(progress) +} + +function setCorrectOptions(correctOptions, id) { var elements = document.getElementsByName("checkbox_" + id); + var holders = document.getElementsByName("checkbox_div_" + id); - for(var i = 0; i < elements.length; i++) { - var element = elements[i]; - element.className=""; + for(var i = 0; i < elements.length; i++) { + var element = elements[i]; + var holder = holders[i]; - var correct = isCorrectOption(element.value); - if(correct) { - element.className="correct"; - } else { - if(element.checked) { - element.className="failed"; + var correct = isCorrectOption(element.value); + if(correct) { + holder.className = holder.className + " list-group-item-success"; + } else { + if(element.checked) { + holder.className = holder.className + " list-group-item-danger";; + } } - } - } + element.disabled = true; + } - function isCorrectOption(option) { - for(var i = 0; i < correctOptions.length; i++) { - if(correctOptions[i] == option) { - return true; + function isCorrectOption(option) { + for(var i = 0; i < correctOptions.length; i++) { + if(correctOptions[i] == option) { + return true; + } } + return false; } - return false; - } +} + +function setProgress(progress) { + progressbar = document.getElementById("progressbar"); + progressbar.style.width = progress + "%"; } function ajaxRequest() { diff --git a/tkupek_elearning/elearning/templates/access_denied.html b/tkupek_elearning/elearning/templates/access_denied.html index 9215ec8..a498d12 100644 --- a/tkupek_elearning/elearning/templates/access_denied.html +++ b/tkupek_elearning/elearning/templates/access_denied.html @@ -7,7 +7,15 @@ {% load staticfiles %} + +
{{ settings.message_welcome_user }}
+{{ question.text }}
@@ -27,19 +41,28 @@ {{ settings.message_already_answered }} - + + {% endfor %} + -{{ question.explanation }}
- +name | questions answered | @@ -38,7 +46,7 @@
title | answers | @@ -57,7 +65,10 @@