diff --git a/server/book/blocks.py b/server/book/blocks.py index b69f8694..c801399e 100644 --- a/server/book/blocks.py +++ b/server/book/blocks.py @@ -1,4 +1,5 @@ from wagtail.core import blocks +from wagtail.core.blocks.field_block import RichTextBlock from wagtail.documents.blocks import DocumentChooserBlock DEFAULT_RICH_TEXT_FEATURES = ['bold', 'italic', 'link', 'ol', 'ul'] @@ -12,3 +13,19 @@ class LinkBlock(blocks.StructBlock): class DocumentBlock(blocks.StructBlock): document = DocumentChooserBlock() description = blocks.CharBlock() + + +class TextBlock(blocks.StructBlock): + text = RichTextBlock() + + +class ModalTextBlock(blocks.StructBlock): + description = RichTextBlock() + modal_content = RichTextBlock() + + +class StudentEntryBlock(blocks.StructBlock): + task_text = blocks.CharBlock() + + +# class ImageBlock diff --git a/server/book/migrations/0002_contentblock.py b/server/book/migrations/0002_contentblock.py new file mode 100644 index 00000000..8b4dd024 --- /dev/null +++ b/server/book/migrations/0002_contentblock.py @@ -0,0 +1,31 @@ +# Generated by Django 2.0.6 on 2018-08-15 08:45 + +from django.db import migrations, models +import django.db.models.deletion +import wagtail.core.blocks +import wagtail.core.fields +import wagtail.images.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailcore', '0040_page_draft_title'), + ('book', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='ContentBlock', + fields=[ + ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')), + ('contents', wagtail.core.fields.StreamField([('text', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock())], icon='doc-full')), ('modal_text', wagtail.core.blocks.StructBlock([('description', wagtail.core.blocks.RichTextBlock()), ('modal_content', wagtail.core.blocks.RichTextBlock())], icon='placeholder')), ('student_entry', wagtail.core.blocks.StructBlock([('task_text', wagtail.core.blocks.CharBlock())], icon='download')), ('image', wagtail.images.blocks.ImageChooserBlock(icon='image')), ('task', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock())], icon='tick'))])), + ('type', models.CharField(choices=[('plain', 'Normal'), ('yellow', 'Gelb'), ('green', 'Grün'), ('blue', 'Blau')], max_length=100)), + ], + options={ + 'verbose_name_plural': 'Inhaltsblöcke', + 'verbose_name': 'Inhaltsblock', + }, + bases=('wagtailcore.page',), + ), + ] diff --git a/server/book/models/__init__.py b/server/book/models/__init__.py index 33c9b7a0..ab27e557 100644 --- a/server/book/models/__init__.py +++ b/server/book/models/__init__.py @@ -1,3 +1,5 @@ from .book import * from .module import * from .topic import * +from .chapter import * +from .contentblock import * diff --git a/server/book/models/contentblock.py b/server/book/models/contentblock.py new file mode 100644 index 00000000..185182e9 --- /dev/null +++ b/server/book/models/contentblock.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +# +# Iterativ GmbH +# http://www.iterativ.ch/ +# +# Copyright (c) 2018 Iterativ GmbH. All rights reserved. +# +# Created on 15.08.18 +# @author: Ramon Wenger +import logging + +from django.db import models + +from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, \ + ObjectList +from wagtail.core.fields import StreamField +from wagtail.core.models import Page +from wagtail.images.blocks import ImageChooserBlock + +from book.blocks import TextBlock, ModalTextBlock, StudentEntryBlock + +logger = logging.getLogger(__name__) + + +class ContentBlock(Page): + class Meta: + verbose_name = 'Inhaltsblock' + verbose_name_plural = 'Inhaltsblöcke' + + contents = StreamField([ + ('text', TextBlock(icon='doc-full')), + ('modal_text', ModalTextBlock(icon='placeholder')), + ('student_entry', StudentEntryBlock(icon='download')), + ('image', ImageChooserBlock(icon='image')), + ('task', TextBlock(icon='tick')) + ]) + + type = models.CharField( + max_length=100, + choices=( + ('plain', 'Normal'), + ('yellow', 'Gelb'), + ('green', 'Grün'), + ('blue', 'Blau'), + ) + ) + + content_panels = [ + FieldPanel('title', classname="full title"), + ] + + settings_panels = [ + FieldPanel('slug') + ] + + edit_handler = TabbedInterface([ + ObjectList(content_panels, heading='Content'), + ObjectList(settings_panels, heading='Settings'), + ]) + + template = 'generic_page.html' + + parent_page_types = ['book.Chapter'] + + @classmethod + def get_chapter_content_blocks(cls, chapter): + return cls.objects.filter(id__in=chapter.get_child_ids()).live()