added dynamic number of learning sequences

This commit is contained in:
Lorenz Padberg 2022-06-08 17:20:11 +02:00
parent 84bf372a58
commit c3481c22d7
5 changed files with 20 additions and 20 deletions

View File

@ -3,7 +3,7 @@ import * as d3 from 'd3';
export default { export default {
props: { props: {
learningSequeces: {required: false, learningSequences: {required: false,
default: [{title: '', done: false}, {title: '', done: false}, {title: '', done: false}, {title: '', done: false}]}, default: [{title: '', done: false}, {title: '', done: false}, {title: '', done: false}, {title: '', done: false}]},
width: { width: {
default: 250, default: 250,
@ -16,7 +16,7 @@ export default {
}, },
computed: { computed: {
pieData () { pieData () {
return new Array(this.learningSequeces.length).fill(1); return new Array(Math.max(this.learningSequences.length, 1)).fill(1);
}, },
viewBox() { viewBox() {
return `0 0 ${this.width} ${this.height}`; return `0 0 ${this.width} ${this.height}`;

View File

@ -75,7 +75,7 @@ export default {
<div class="font-bold text-blue-900 mb-4">{{topic.title}}</div> <div class="font-bold text-blue-900 mb-4">{{topic.title}}</div>
<div class="flex flex-row"> <div class="flex flex-row">
<button class="circle mr-8" aria-label="circle.title" v-for="circle in topic.circles"> <button class="circle mr-8" aria-label="circle.title" v-for="circle in topic.circles">
<SimpleCircleDiagram class="w-48 h-48"></SimpleCircleDiagram> <SimpleCircleDiagram class="w-48 h-48" :learning-sequences="circle.learning_sequences"></SimpleCircleDiagram>
<div class="text-center text-xl text-blue-900 font-bold mt-4">{{ circle.title }}</div> <div class="text-center text-xl text-blue-900 font-bold mt-4">{{ circle.title }}</div>
</button> </button>

View File

@ -33,7 +33,6 @@ class Topic(Page):
parent_page_types = ['learnpath.LearningPath'] parent_page_types = ['learnpath.LearningPath']
panels = [FieldPanel('title'), panels = [FieldPanel('title'),
FieldPanel('is_visible'), FieldPanel('is_visible'),
] ]
@ -43,7 +42,6 @@ class Topic(Page):
APIField('is_visible'), APIField('is_visible'),
] ]
# content_panels = Page.content_panels + [ # content_panels = Page.content_panels + [
# FieldPanel('is_visible', classname="full"), # FieldPanel('is_visible', classname="full"),
# PageChooserPanel('learning_path', 'learnpath.LearningPath'), # PageChooserPanel('learning_path', 'learnpath.LearningPath'),
@ -57,11 +55,10 @@ class Topic(Page):
print(self.slug) print(self.slug)
super(Topic, self).full_clean(*args, **kwargs) super(Topic, self).full_clean(*args, **kwargs)
@classmethod @classmethod
def get_serializer_class(cls): def get_serializer_class(cls):
return get_it_serializer_class(cls, field_names=['id', 'title', 'slug', 'type', 'translation_key', 'is_visible']) return get_it_serializer_class(cls,
field_names=['id', 'title', 'slug', 'type', 'translation_key', 'is_visible', ])
class Meta: class Meta:
verbose_name = "Topic" verbose_name = "Topic"
@ -74,14 +71,6 @@ class Circle(Page):
description = models.TextField(default="", blank=True) description = models.TextField(default="", blank=True)
goals = models.TextField(default="", blank=True) goals = models.TextField(default="", blank=True)
# topic = models.ForeignKey(
# 'learnpath.Topic',
# null=True,
# blank=True,
# on_delete=models.SET_NULL,
# related_name='circles'
# )
parent_page_types = ['learnpath.LearningPath'] parent_page_types = ['learnpath.LearningPath']
subpage_types = ['learnpath.LearningSequence', 'learnpath.LearningUnit'] subpage_types = ['learnpath.LearningSequence', 'learnpath.LearningUnit']
@ -93,12 +82,16 @@ class Circle(Page):
api_fields = [ api_fields = [
APIField('title'), APIField('title'),
APIField('description'), APIField('description'),
APIField('learning_sequences'),
] ]
@property
def learning_sequences(self):
return self.get_children().filter(content_type__model='learningsequence').values('id', 'title')
@classmethod @classmethod
def get_serializer_class(cls): def get_serializer_class(cls):
return get_it_serializer_class(cls, field_names=['id', 'title', 'slug', 'type', 'translation_key']) return get_it_serializer_class(cls, field_names=['id', 'title', 'slug', 'type', 'translation_key', 'learning_sequences'])
def full_clean(self, *args, **kwargs): def full_clean(self, *args, **kwargs):
self.slug = find_available_slug(Circle, slugify(self.title, allow_unicode=True)) self.slug = find_available_slug(Circle, slugify(self.title, allow_unicode=True))
@ -192,7 +185,9 @@ class LearningUnit(Page):
@classmethod @classmethod
def get_serializer_class(cls): def get_serializer_class(cls):
return get_it_serializer_class(cls, field_names=['id', 'title', 'minutes', 'package', 'contents', 'slug', 'type', 'translation_key']) return get_it_serializer_class(cls,
field_names=['id', 'title', 'minutes', 'package', 'contents', 'slug', 'type',
'translation_key'])
def __str__(self): def __str__(self):
return f"{self.title}" return f"{self.title}"

View File

@ -7,3 +7,6 @@ class TestCreateDefaultCompetences(TestCase):
def test_create_default_competeneces(self): def test_create_default_competeneces(self):
create_default_competences() create_default_competences()

View File

@ -2,12 +2,14 @@ from django.conf import settings
from django.test import TestCase from django.test import TestCase
from wagtail.core.models import Locale from wagtail.core.models import Locale
from vbv_lernwelt.core.create_default_users import create_default_users
from vbv_lernwelt.learnpath.models import LearningPath from vbv_lernwelt.learnpath.models import LearningPath
from vbv_lernwelt.learnpath.tests.create_default_learning_path import create_default_learning_path from vbv_lernwelt.learnpath.tests.create_default_learning_path import create_default_learning_path
class TestCreateDefaultLearningPaths(TestCase): class TestCreateDefaultLearningPaths(TestCase):
def setUp(self) -> None: def setUp(self) -> None:
create_default_users()
create_locales_for_wagtail() create_locales_for_wagtail()
def test_create_learning_path(self): def test_create_learning_path(self):