Add content block model
This commit is contained in:
parent
bdeda1428c
commit
4650fecfc7
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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',),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
from .book import *
|
||||
from .module import *
|
||||
from .topic import *
|
||||
from .chapter import *
|
||||
from .contentblock import *
|
||||
|
|
|
|||
|
|
@ -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 <ramon.wenger@iterativ.ch>
|
||||
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()
|
||||
Loading…
Reference in New Issue