Skip to content

Commit

Permalink
create training app, models and fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
harryface committed Feb 20, 2023
1 parent f0897a4 commit 2cdecfb
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 1 deletion.
4 changes: 4 additions & 0 deletions 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 @@ -371,6 +372,7 @@
['InlineEquation', 'BlockEquation', 'CodeSnippet', 'Table'],
['Link', 'Unlink'],
['RemoveFormat', 'Source'],
['Image']
],
'removeDialogTabs': 'link:advanced',
'disableNativeSpellChecker': False,
Expand Down Expand Up @@ -604,3 +606,5 @@ class StorageTypes:

# minimum number of word needed for research_summary field for Credentialing Model.
MIN_WORDS_RESEARCH_SUMMARY_CREDENTIALING = config('MIN_WORDS_RESEARCH_SUMMARY_CREDENTIALING', cast=int, default=20)

CKEDITOR_UPLOAD_PATH = 'ckeditor/'
5 changes: 4 additions & 1 deletion physionet-django/physionet/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@

# path for Database List - to be deprecated soon
path('rest/database-list/', database_list,
name='database_list')
name='database_list'),

# for ckeditor
path('ckeditor/', include('ckeditor_uploader.urls'))
]

if settings.ENABLE_LIGHTWAVE and ProjectFiles().is_lightwave_supported:
Expand Down
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
}
}
]
67 changes: 67 additions & 0 deletions physionet-django/training/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Generated by Django 4.1.5 on 2023-02-20 18:16

import ckeditor_uploader.fields
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('user', '0052_alter_trainingtype_required_field'),
]

operations = [
migrations.CreateModel(
name='OnPlatformTraining',
fields=[
('id', models.AutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('version', models.FloatField(default=1.0, unique=True)),
('training', models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='op_trainings', to='user.trainingtype')),
],
options={
'default_permissions': ('change',),
},
),
migrations.CreateModel(
name='Quiz',
fields=[
('id', models.AutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('question', ckeditor_uploader.fields.RichTextUploadingField()),
('order', models.PositiveIntegerField()),
('training', models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='quizzes', to='training.onplatformtraining')),
],
),
migrations.CreateModel(
name='QuizChoice',
fields=[
('id', models.AutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField()),
('is_correct', models.BooleanField(default=False, verbose_name='Correct Choice?')),
('quiz', models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='choices', to='training.quiz')),
],
),
migrations.CreateModel(
name='ContentBlock',
fields=[
('id', models.AutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', ckeditor_uploader.fields.RichTextUploadingField()),
('order', models.PositiveIntegerField()),
('training', models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='contents', to='training.onplatformtraining')),
],
),
]
Empty file.
33 changes: 33 additions & 0 deletions physionet-django/training/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.db import models

from ckeditor_uploader.fields import RichTextUploadingField


class OnPlatformTraining(models.Model):
training = models.ForeignKey('user.TrainingType',
on_delete=models.CASCADE, related_name='op_trainings')
version = models.FloatField(default=1.0, unique=True)

class Meta:
default_permissions = ('change',)


class Quiz(models.Model):
question = RichTextUploadingField()
training = models.ForeignKey('training.OnPlatformTraining',
on_delete=models.CASCADE, related_name='quizzes')
order = models.PositiveIntegerField()


class ContentBlock(models.Model):
training = models.ForeignKey('training.OnPlatformTraining',
on_delete=models.CASCADE, related_name='contents')
body = RichTextUploadingField()
order = models.PositiveIntegerField()


class QuizChoice(models.Model):
quiz = models.ForeignKey('training.Quiz',
on_delete=models.CASCADE, related_name='choices')
body = models.TextField()
is_correct = models.BooleanField('Correct Choice?', default=False)
14 changes: 14 additions & 0 deletions physionet-django/training/to_do
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Console
- Add a create training type button *
- View all Training with button beside asking to make it OP *
- Button on-top asking to create a training type
- Add a button to download sample json/ paste the sample json on the page *
- Modify the settings training page to display the latest versions
- Write test cases for them all
- Write a function that puts all validity at 30 days and sends a mail asking them to retake the training for major version change *
- Change the trainingType required_field to Platform from serializer


New Branch
- Create the Training App, as well as their models, admins, fixtures, migrations, apps,
- Another PR for the views and viewing it from settings
3 changes: 3 additions & 0 deletions physionet-django/training/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# write your views here
1 change: 1 addition & 0 deletions physionet-django/user/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def choices(cls):
class RequiredField(IntEnum):
DOCUMENT = 0
URL = 1
PLATFORM = 2

@classmethod
def choices(cls):
Expand Down
18 changes: 18 additions & 0 deletions physionet-django/user/fixtures/demo-training-type.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
]
}
},
{
"model": "user.trainingtype",
"pk": 2,
"fields": {
"name": "On Platform Training",
"description": "<p>This training teaches about name of places.</p><br/><p>Lorem ipsum dolor sit amet. Et excepturi amet <strong>Et autem aut quisquam galisum eos totam esse ut omnis eveniet</strong>. Et eius assumenda non tempore sequiqui laboriosam est corporis dolores. Eos consequatur fugiatAut iste ad corrupti nostrum est quos autem est optio quod et iure nemo ea temporibus magni. Est placeat dicta 33 laborum nulla33 veritatis non nihil quod sit quia dolor. </p><p>Id internos repellatSed culpa cum natus internos aut enim consectetur et architecto quibusdam eum ipsam fugit et quia animi. Eos obcaecati exercitationem <em>Ut repellat aut nemo quia ut quia perferendis</em>. </p>",
"home_page": "/",
"valid_duration": "1095 00:00:00",
"required_field": 2,
"questions": [
1,
2,
3,
4,
5
]
}
},
{
"model": "user.question",
"pk": 1,
Expand Down
5 changes: 5 additions & 0 deletions physionet-django/user/fixtures/demo-user.json
Original file line number Diff line number Diff line change
Expand Up @@ -14362,6 +14362,11 @@
"can_review_training",
"user",
"trainingtype"
],
[
"change_onplatformtraining",
"training",
"onplatformtraining"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.1.5 on 2023-02-18 02:12

from django.db import migrations, models
import user.enums


class Migration(migrations.Migration):

dependencies = [
('user', '0051_credentialapplication_auto_rejection_reason'),
]

operations = [
migrations.AlterField(
model_name='trainingtype',
name='required_field',
field=models.PositiveSmallIntegerField(
choices=[(0, 'DOCUMENT'), (1, 'URL'), (2, 'PLATFORM')],
default=user.enums.RequiredField['DOCUMENT']),
),
]

0 comments on commit 2cdecfb

Please sign in to comment.