-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3ac3fc
commit 25ac5a5
Showing
4 changed files
with
158 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
physionet-django/console/templates/console/training_type/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{% extends "console/base_console.html" %} | ||
|
||
{% load static %} | ||
|
||
{% block title %}Training Types{% endblock %} | ||
|
||
{% block content %} | ||
<div class="card mb-3"> | ||
<div class="card-header"> | ||
Courses <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-success" data-toggle="modal" data-target="#course">Create/Update Courses</button></div> | ||
<div class="table-responsive"> | ||
<table class="table table-bordered"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Valid Duration</th> | ||
<th>Version</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for training in training_types %} | ||
|
||
<tr> | ||
<td>{{ training.name|title }}</td> | ||
<td>{{ training.valid_duration.days }} days</td> | ||
<td>{{ training.courses.last.version }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
<div class="modal fade" id="course" tabindex="-1"> | ||
<div class="modal-dialog"> | ||
<form action="{% url 'courses' %}" method="POST" enctype="multipart/form-data" class=""> | ||
<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> | ||
{% csrf_token %} | ||
<div class="form-group"> | ||
<label>Training Type: </label> | ||
<select name="training_id" class="form-control" required> | ||
<option disabled>Choose...</option> | ||
<option value="-1">Create new course</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>#} | ||
|
||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<input type="submit" name="create" class="btn btn-primary"> | ||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
from django.urls import path | ||
from training import views | ||
|
||
|
||
urlpatterns = [ | ||
path('training/', views.courses, name='courses'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import json | ||
import operator | ||
from itertools import chain | ||
|
||
from django.contrib import messages | ||
from django.contrib.auth.decorators import login_required, permission_required | ||
from django.db import transaction | ||
from django.db.models import Prefetch | ||
from django.http import JsonResponse | ||
from django.shortcuts import get_object_or_404, redirect, render | ||
from django.utils import timezone | ||
from django.utils.crypto import get_random_string | ||
|
||
from rest_framework.parsers import JSONParser | ||
|
||
from user.models import Training, TrainingType, TrainingQuestion, RequiredField | ||
from user.enums import TrainingStatus | ||
|
||
from training.models import Course, Quiz, QuizChoice, ContentBlock | ||
from training.models import CourseProgress, ModuleProgress, CompletedContent, CompletedQuiz | ||
from training.serializers import TrainingTypeSerializer | ||
|
||
|
||
@permission_required('training.change_course', raise_exception=True) | ||
def courses(request): | ||
|
||
if request.POST: | ||
|
||
if request.POST.get('training_id') != "-1": | ||
training_type = get_object_or_404(TrainingType, pk=request.POST.get('training_id')) | ||
else: | ||
training_type = None | ||
|
||
json_file = request.FILES.get("json_file", "") | ||
|
||
if not json_file.name.endswith('.json'): | ||
messages.error(request, 'File is not of JSON type') | ||
return redirect("courses") | ||
file_data = JSONParser().parse(json_file.file) | ||
serializer = TrainingTypeSerializer(training_type, data=file_data, partial=True) | ||
if serializer.is_valid(raise_exception=False): | ||
serializer.save() | ||
messages.success(request, 'Course created successfully.') | ||
else: | ||
messages.error(request, serializer.errors) | ||
|
||
return redirect("courses") | ||
|
||
training_types = TrainingType.objects.filter(required_field=RequiredField.PLATFORM) | ||
return render( | ||
request, | ||
'console/training_type/index.html', | ||
{ | ||
'training_types': training_types, | ||
'training_type_nav': True, | ||
}) |