added popup when elearning is completed, added handler for multiple settings
This commit is contained in:
parent
c7e3d50038
commit
c78ca647e6
10 changed files with 210 additions and 19 deletions
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -11,22 +11,50 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
<title>{{ settings.title }}</title>
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||
|
||||
<!-- Latest compiled and minified CSS -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
|
||||
|
||||
<!-- Optional theme -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
|
||||
|
||||
<!-- Latest compiled and minified JavaScript -->
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" id="completed-modal">
|
||||
<div class="modal-dialog modal-sm">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title" id="myModalLabel">{{ settings.popup_completed_title }}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
{{ settings.popup_completed_message|safe }}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal">OK</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="popup-leave-message" class="hide">{{ settings.popup_leave_message|safe }}</div>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<img src="{{ settings.logo }}" class="mainLogo">
|
||||
{% if settings.logo %}
|
||||
<img src="{{ settings.logo }}" class="mainLogo">
|
||||
{% endif %}
|
||||
<h1>{{ settings.title }}</h1>
|
||||
<p>{{ settings.message_welcome_user|safe }}</p>
|
||||
<div class="progress">
|
||||
<div id="progressbar" class="progress-bar progress-bar-striped" role="progressbar" style="width: {{ progress }}%">
|
||||
{{ progress }}%
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue