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 28, 2023
1 parent 9750547 commit ec80e43
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 1 deletion.
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
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-28 14:29

from django.db import migrations, models
import django.db.models.deletion
import project.modelcomponents.fields


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', project.modelcomponents.fields.SafeHTMLField()),
('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', project.modelcomponents.fields.SafeHTMLField()),
('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 project.modelcomponents.fields import SafeHTMLField


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 = SafeHTMLField()
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 = SafeHTMLField()
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)
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 ec80e43

Please sign in to comment.