added video and wbt learning unit content

This commit is contained in:
Lorenz Padberg 2022-04-19 16:14:26 +02:00
parent 53675aa69c
commit daa51619dc
8 changed files with 162 additions and 16 deletions

View File

@ -0,0 +1,20 @@
# Generated by Django 3.2.12 on 2022-04-19 09:37
from django.db import migrations
import wagtail.core.blocks
import wagtail.core.fields
class Migration(migrations.Migration):
dependencies = [
('learnpath', '0004_auto_20220414_1503'),
]
operations = [
migrations.AddField(
model_name='learningunit',
name='contents',
field=wagtail.core.fields.StreamField([('web_based_training', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('video', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())]))], blank=True, null=True),
),
]

View File

@ -1,17 +1,12 @@
# Create your models here. # Create your models here.
from django.db import models from django.db import models
from wagtail.admin.edit_handlers import FieldPanel from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.core.blocks import StreamBlock
from wagtail.core.fields import StreamField
from wagtail.core.models import Page from wagtail.core.models import Page
from django.utils.translation import gettext_lazy as _
from vbv_lernwelt.learnpath.models_learning_unit_content import WebBasedTrainingBlock, VideoBlock
# class HomePage(Page):
# body = RichTextField(default='', blank=True)
#
# content_panels = Page.content_panels + [
# FieldPanel('body', classname="full"),
# ]
class LearningPath(Page): class LearningPath(Page):
@ -90,7 +85,23 @@ class LearningSequence(Page):
class LearningUnit(Page): class LearningUnit(Page):
parent_page_types = ['learnpath.Circle'] # TODO: Review model architecture, is the stream fiel the right thing here?
parent_page_types = ['learnpath.LearningSequence']
content_blocks = [
('web_based_training', WebBasedTrainingBlock()),
('video', VideoBlock()),
]
contents = StreamField(StreamBlock(content_blocks),
null=True, blank=True, min_num=1, max_num=1)
content_panels = [
FieldPanel('title', classname="full title"),
StreamFieldPanel('contents')
]
subpage_types = []
class Meta: class Meta:
verbose_name = "Learning Unit" verbose_name = "Learning Unit"

View File

@ -0,0 +1,33 @@
from django.db import models
from wagtail.core import blocks
# 'video_block'
class VideoBlock(blocks.StructBlock):
# TODO: Possible video Types for the user, upload file, add URL
title = models.CharField(max_length=128, default="")
description = models.TextField(default="")
url = blocks.URLBlock()
class Meta:
icon = 'media'
# 'Web based training Block'
class WebBasedTrainingBlock(blocks.StructBlock):
RISE = 'rise'
WBT_TYPE_CHOICES = (
(RISE, 'Rise'),
)
url = blocks.URLBlock()
type = models.CharField(
max_length=100,
choices=WBT_TYPE_CHOICES,
default=RISE
)
class Meta:
icon = 'media'

View File

@ -3,14 +3,14 @@ from wagtail.core.models import Site
from vbv_lernwelt.learnpath.models import LearningPath, Topic, Circle, LearningSequence, LearningUnit from vbv_lernwelt.learnpath.models import LearningPath, Topic, Circle, LearningSequence, LearningUnit
from vbv_lernwelt.learnpath.tests.learningpath_factories import LearningPathFactory, TopicFactory, CircleFactory, \ from vbv_lernwelt.learnpath.tests.learningpath_factories import LearningPathFactory, TopicFactory, CircleFactory, \
LearningSequenceFactory, LearningUnitFactory LearningSequenceFactory, LearningUnitFactory, VideoBlockFactory, WebBasedTrainingBlockFactory
def create_default_learning_path(): def create_default_learning_path():
site = Site.objects.filter(is_default_site=True).first() site = Site.objects.filter(is_default_site=True).first()
if not site: if not site:
site = wagtail_factories.SiteFactory.get(is_default_site=True) site = wagtail_factories.SiteFactory(is_default_site=True)
lp = LearningPathFactory.create(title="Versicherungsvermittler/in", parent=site.root_page) lp = LearningPathFactory.create(title="Versicherungsvermittler/in", parent=site.root_page)
@ -61,6 +61,21 @@ von Neukunden zu benützen
sequence_1 = LearningSequenceFactory.create(title="Starten", parent=circle_4) sequence_1 = LearningSequenceFactory.create(title="Starten", parent=circle_4)
learning_unit = LearningUnitFactory.create(title='Einleitung Circle "Anlayse"', parent=sequence_1) learning_unit = LearningUnitFactory.create(title='Einleitung Circle "Anlayse"', parent=sequence_1)
learning_unit = LearningUnitFactory.create(title='** Einstieg Video"', parent=sequence_1)
video_url = "https://www.vbv.ch/fileadmin/vbv/Videos/Statements_Externe/Janos_M/Testimonial_Janos_Mischler_PositiveEffekte.mp4"
video_title = "Ausbildung ist pflicht"
video_description = "Erfahren Sie, was für Janos Mischler die positiven Aspekte von ständiger Weiterbildung sind aus fachlicher und aus persönlicher Sicht."
video_block = VideoBlockFactory(type="video", url=video_url, title=video_title, description=video_description)
learning_unit.contents.append(('video', video_block))
learning_unit.save()
learning_unit = LearningUnitFactory.create(title='** Web Based Training"', parent=sequence_1)
wbt_url = "web_based_trainings/rise_cmi5_test_export/scormcontent/index.html"
wbt_block = WebBasedTrainingBlockFactory(type="web_based_training", url=wbt_url)
learning_unit.contents.append(('web_based_training', wbt_block))
learning_unit.save()
learning_unit = LearningUnitFactory.create(title="Selbsteinschätzung", parent=sequence_1) learning_unit = LearningUnitFactory.create(title="Selbsteinschätzung", parent=sequence_1)
sequence_2 = LearningSequenceFactory.create(title="Beobachten", parent=circle_4) sequence_2 = LearningSequenceFactory.create(title="Beobachten", parent=circle_4)

View File

@ -1,6 +1,7 @@
import wagtail_factories import wagtail_factories
from vbv_lernwelt.learnpath.models import LearningPath, Topic, Circle, LearningSequence, LearningUnit from vbv_lernwelt.learnpath.models import LearningPath, Topic, Circle, LearningSequence, LearningUnit
from vbv_lernwelt.learnpath.models_learning_unit_content import VideoBlock, WebBasedTrainingBlock
class LearningPathFactory(wagtail_factories.PageFactory): class LearningPathFactory(wagtail_factories.PageFactory):
@ -37,3 +38,19 @@ class LearningUnitFactory(wagtail_factories.PageFactory):
class Meta: class Meta:
model = LearningUnit model = LearningUnit
class VideoBlockFactory(wagtail_factories.StructBlockFactory):
title = "Ausbildung ist Pflicht"
url = "https://www.vbv.ch/fileadmin/vbv/Videos/Statements_Externe/Janos_M/Testimonial_Janos_Mischler_PositiveEffekte.mp4"
class Meta:
model = VideoBlock
class WebBasedTrainingBlockFactory(wagtail_factories.StructBlockFactory):
title = "Beispiel Rise Modul"
url = "https://docs.wagtail.org/en/stable/topics/streamfield.html"
class Meta:
model = WebBasedTrainingBlock

View File

@ -18,4 +18,4 @@ class TestCreateDefaultLearningPaths(TestCase):
def create_locales_for_wagtail(): def create_locales_for_wagtail():
for language in settings.WAGTAIL_CONTENT_LANGUAGES: for language in settings.WAGTAIL_CONTENT_LANGUAGES:
Locale.objects.create(language_code=language[0]) Locale.objects.get_or_create(language_code=language[0])

View File

@ -36,7 +36,7 @@
<h2 class="font-bold">{{ learning_sequence.title }}</h2> <h2 class="font-bold">{{ learning_sequence.title }}</h2>
{% for learning_unit in learning_sequence.get_children %} {% for learning_unit in learning_sequence.get_children %}
<div> <div>
<h3>{{ learning_unit.title }}</h3> <a target="_blank" href="{% pageurl learning_unit %}">{{ learning_unit.title }}</a>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
@ -88,10 +88,8 @@
.attr("class", "arrow") .attr("class", "arrow")
.attr("marker-start", "url(#triangle)") .attr("marker-start", "url(#triangle)")
var markers = g.selectAll("arrow").attr("transform", "translate(60, 60) rotate(30)") var markers = g.selectAll("arrow").attr("transform", "translate(60, 60) rotate(30)")
//Draw arc paths //Draw arc paths
arcs.append("path") arcs.append("path")
.attr("fill", color) .attr("fill", color)

View File

@ -0,0 +1,52 @@
{% extends "base.html" %}
{% load wagtailcore_tags %}
{% load static %}
{% block body_class %}template-learning_unit{% endblock %}
{% block content %}
<learning_unit>
{% if not page.contents %}
<div> O0ps, in dieser Lerneinheit wurde kein Inhalt erfasst.</div>
{% endif %}
{% for block in page.contents %}
{% if block.block_type == 'video' %}
<h1>{{ block.block_type }}</h1>
<div class="video">
<h1>{{ block.value.title }}</h1>
<div>{{ block.value.description }}</div>
<div>{{ block.value.url }}</div>
<video width="640" height="480" controls>
<source src={{ block.value.url }} type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
{% endif %}
{% if block.block_type == 'web_based_training' %}
<div> Loading web based training...</div>
<a class="font-bold" href="javascript:open_web_based_training('{{ block.value.url }}');">Click me!</a>
{% endif %}
{% endfor %}
</learning_unit>
<script>
console.log("sali")
function open_web_based_training(url){
var realUrl = {% get_media_prefix %} + url
console.log("Loading wbt", realUrl)
window.location.href = realUrl;
}
console.log("adee")
</script>
{% endblock %}