Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform Training and Quiz 2 #1889

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions physionet-django/console/templates/console/console_navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,31 @@
</li>
{% endif %}

<!-- Training -->
{% if perms.user.can_review_training %}
<!-- training -->
<li class="nav-item {% if training_nav %}active{% endif %}" data-toggle="tooltip" data-placement="right">
<a id="nav_storage_requests" class="nav-link" href="{% url 'training_list' 'review' %}">
<i class="fa fa-fw fa-school"></i>
<span class="nav-link-text">Training check</span>
<li class="nav-item" data-toggle="tooltip" data-placement="right">
{% if training_type_nav or training_nav %}
<a id="nav_pages_dropdown" class="nav-link nav-link-collapse drop" data-toggle="collapse" href="#trainingComponent" data-parent="#sideAccordion" aria-expanded="true">
{% else %}
<a id="nav_pages_dropdown" class="nav-link nav-link-collapse drop collapsed" data-toggle="collapse" href="#trainingComponent" data-parent="#sideAccordion" aria-expanded="false">
{% endif %}
<i class="fa fa-fw fa-window-maximize"></i>
<span class="nav-link-text">Training</span>
</a>
</li>
<!-- submenu -->
{% if training_type_nav or training_nav %}
<ul class="sidenav-second-level collapse show" id="trainingComponent" style="">
{% else %}
<ul class="sidenav-second-level collapse" id="trainingComponent">
{% endif %}
<li class="nav-item {% if training_nav %}active{% endif %}">
<a id="nav_console_news" class="nav-link" href="{% url 'training_list' 'review' %}">Training Check</a>
</li>
<li class="nav-item {% if training_type_nav %}active{% endif %}">
<a id="nav_console_news" class="nav-link" href="{% url 'op_training' %}">OP Training</a>
</li>
</ul>
</li>
{% endif %}

<!-- events -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{% extends "console/base_console.html" %}

{% load static %}

{% block title %}Training Types{% endblock %}

{% block content %}
<div class="card mb-3">
<div class="card-header">
Training Types <span class="badge badge-pill badge-info">{{ training_types|length }}</span>
</div>
<div class="card-body">
<div><button type="button" class="btn btn-sm btn-danger" data-toggle="modal" data-target="#op-training">Create an On Platform Training</button></div>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Valid Duration</th>
<th>On Platform Training</th>
</tr>
</thead>
<tbody>
{% for training in training_types %}
<tr>
<td>{{ training.name|title }}</td>
<td>{{ training.valid_duration }}</td>
<td>{% if training.required_field == 2 %} True {% else %} False {% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>

<div class="modal fade" id="op-training" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">

<div class="modal-body">
<p>Download Sample Json File by <a href="{% static 'sample/create.json' %}" download>Clicking Here</a></p>
<div>
<form action="{% url 'op_training' %}" method="POST" enctype="multipart/form-data" class="">
{% csrf_token %}
<div class="form-group">
<label>Training Type: </label>
<select name="training_id" class="form-control" required>
<option disabled>Choose...</option>
{% for training in training_types %}
<option value="{{ training.id }}">{{ training.name|title }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label>File: </label>
<input type="file" name="json_file" id="json_file" required="True" class="form-control">
</div>
<div class="form-group">
<input type="submit" name="create" class="btn btn-primary">
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

</div>
</div>
{% endblock %}
16 changes: 16 additions & 0 deletions physionet-django/notification/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,3 +983,19 @@ def notify_participant_event_decision(request, user, event, decision, comment_to
body = loader.render_to_string('events/email/event_participation_decision.html', context)
# Not resend the email if there was an integrity error
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False)


def notify_users_of_training_expiry(user, training, expiry):
"""
Send the training expiry email.
"""

subject = f"{settings.SITE_NAME} Training Validation Notification"
context = {
'name': user.get_full_name(),
'SITE_NAME': settings.SITE_NAME,
'training': training,
'expiry': expiry
}
body = loader.render_to_string('training/email/training_notification.html', context)
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [user, ], fail_silently=False)
3 changes: 2 additions & 1 deletion physionet-django/physionet/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'background_task',
'rest_framework',

'training',
'user',
'project',
'console',
Expand Down Expand Up @@ -370,7 +371,7 @@
['NumberedList', 'BulletedList'],
['InlineEquation', 'BlockEquation', 'CodeSnippet', 'Table'],
['Link', 'Unlink'],
['RemoveFormat', 'Source'],
['RemoveFormat', 'Source']
],
'removeDialogTabs': 'link:advanced',
'disableNativeSpellChecker': False,
Expand Down
2 changes: 2 additions & 0 deletions physionet-django/physionet/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
path('console/', include('console.urls')),
# user app
path('', include('user.urls')),
# training app
path('', include('training.urls')),
# project app
path('projects/', include('project.urls')),
# events
Expand Down
15 changes: 15 additions & 0 deletions physionet-django/static/custom/css/quiz.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

.eachQuiz{
display: none
}

.quizContainer {
max-width: 100%;
position: relative;
margin: auto;
display: block;
}

.alert {
display: none
}
58 changes: 58 additions & 0 deletions physionet-django/static/custom/js/quiz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var slideIndex = 1;
sessionStorage.setItem("slidePosition", 0)

showSlide(slideIndex);

function changeSlide(n) {
console.log(n)
showSlide(slideIndex += n);
}

$('.next').on('click', function () {
// move to next slide but keep track of start of partaining training
var slidePosition = parseInt(sessionStorage.getItem("slidePosition"))
sessionStorage.setItem("slidePosition", slidePosition-1)
changeSlide(1);
})

function showSlide(n) {
var i;
var slides = document.getElementsByClassName("eachQuiz");
if (n > slides.length) {
alertBox("<strong>Congratulations</strong> You have come to the end of the training.")
sessionStorage.clear()
$('form').submit()
}
if (n < 1) { slideIndex = slides.length }
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slides[slideIndex - 1].style.display = "block";
}

$("input[type=radio]").on("click", function () {
// check if answer is correct and proceed, else take back to training
let id = $(this).attr("name")
let value = $(this).val();
var slidePosition = parseInt(sessionStorage.getItem("slidePosition"))

sessionStorage.setItem("slidePosition", 0)

if (sessionStorage.getItem(id) == value) {
alertBox("<strong>Yay!</strong> You chose the correct answer.", "success")
changeSlide(1)
} else {
alertBox("<strong>Oops!</strong> You chose a wrong answer, kindly go through the training again.", "danger")
changeSlide(slidePosition)
}
})

function alertBox(message, _class) {
var alert = document.getElementById("alert");
alert.classList.add("alert-" + _class)
alert.innerHTML = message
alert.style.display = "block"
setTimeout(function() {
alert.style.display = "none"
}, 3000);
};
23 changes: 23 additions & 0 deletions physionet-django/static/sample/create.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"op_trainings": {
"version": "float",
"contents": [
{
"body": "string",
"order": "integer"
}
],
"quizzes": [
{
"question": "string",
"order": "string",
"choices": [
{
"body": "string",
"is_correct": "boolean"
}
]
}
]
}
}
Empty file.
30 changes: 30 additions & 0 deletions physionet-django/training/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.contrib import admin
from training import models


class ContentBlockInline(admin.StackedInline):
model = models.ContentBlock
extra = 1


class QuizChoiceInline(admin.TabularInline):
model = models.QuizChoice
extra = 1


class QuizInline(admin.StackedInline):
model = models.Quiz
inlines = [QuizChoiceInline, ]
extra = 1


@admin.register(models.Quiz)
class QuizAdmin(admin.ModelAdmin):
list_display = ('training', 'question', 'order')
inlines = [QuizChoiceInline, ]


@admin.register(models.OnPlatformTraining)
class OnPlatformTrainingAdmin(admin.ModelAdmin):
list_display = ('training', 'version')
inlines = [ContentBlockInline, QuizInline]
5 changes: 5 additions & 0 deletions physionet-django/training/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class TrainingConfig(AppConfig):
name = 'training'
73 changes: 73 additions & 0 deletions physionet-django/training/fixtures/demo-training.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
[
{
"model": "training.onplatformtraining",
"pk": 1,
"fields": {
"training": 2,
"version": 1.0
}
},
{
"model": "training.contentblock",
"pk": 1,
"fields": {
"training": 1,
"body": "Content Body 1",
"order": 1
}
},
{
"model": "training.contentblock",
"pk": 2,
"fields": {
"training": 1,
"body": "Content Body 2",
"order": 3
}
},
{
"model": "training.quiz",
"pk": 1,
"fields": {
"training": 1,
"question": "Which of this is not a country in America?",
"order": 2
}
},
{
"model": "training.quizchoice",
"pk": 1,
"fields": {
"quiz": 1,
"body": "Canada",
"is_correct": false
}
},
{
"model": "training.quizchoice",
"pk": 2,
"fields": {
"quiz": 1,
"body": "Spain",
"is_correct": true
}
},
{
"model": "training.quizchoice",
"pk": 3,
"fields": {
"quiz": 1,
"body": "Cuba",
"is_correct": false
}
},
{
"model": "training.quizchoice",
"pk": 4,
"fields": {
"quiz": 1,
"body": "Mexico",
"is_correct": false
}
}
]
Loading