Add Link Block
This commit is contained in:
parent
000e3abdf7
commit
a5d0be0396
|
|
@ -2,6 +2,10 @@ from wagtail.core import blocks
|
|||
|
||||
DEFAULT_RICH_TEXT_FEATURES = ['bold', 'italic', 'link', 'ol', 'ul']
|
||||
|
||||
# link_block
|
||||
class LinkBlock(blocks.StructBlock):
|
||||
text = blocks.TextBlock()
|
||||
url = blocks.URLBlock()
|
||||
|
||||
# 'text_block' 'task'
|
||||
class TextBlock(blocks.StructBlock):
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import wagtail_factories
|
|||
from factory import CREATE_STRATEGY
|
||||
from wagtail.core.rich_text import RichText
|
||||
|
||||
from book.blocks import BasicKnowledgeBlock, StudentEntryBlock, ImageUrlBlock
|
||||
from book.blocks import BasicKnowledgeBlock, StudentEntryBlock, ImageUrlBlock, LinkBlock
|
||||
from book.models import Book, Topic, Module, Chapter, ContentBlock, TextBlock
|
||||
from core.factories import BasePageFactory, fake, DummyImageFactory, fake_paragraph, fake_title
|
||||
|
||||
|
|
@ -64,8 +64,15 @@ class ImageUrlBlockBlockFactory(wagtail_factories.StructBlockFactory):
|
|||
model = ImageUrlBlock
|
||||
|
||||
|
||||
class StudentEntryBlockFactory(wagtail_factories.StructBlockFactory):
|
||||
class LinkBlockFactory(wagtail_factories.StructBlockFactory):
|
||||
text = fake_title()
|
||||
url = factory.LazyAttribute(lambda x: 'https://picsum.photos/200/300/?random')
|
||||
|
||||
class Meta:
|
||||
model = LinkBlock
|
||||
|
||||
|
||||
class StudentEntryBlockFactory(wagtail_factories.StructBlockFactory):
|
||||
class Meta:
|
||||
model = StudentEntryBlock
|
||||
|
||||
|
|
@ -95,11 +102,14 @@ class ContentBlockFactory(BasePageFactory):
|
|||
for jdx, field in enumerate(value):
|
||||
block_type = resource['type']
|
||||
if block_type == 'text_block':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, field)] = RichText(value[field])
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, field)] = RichText(
|
||||
value[field])
|
||||
if block_type == 'task':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, field)] = RichText(value[field])
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, field)] = RichText(
|
||||
value[field])
|
||||
elif block_type == 'image_block':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, 'image__title')] = fake_paragraph()
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type,
|
||||
'image__title')] = fake_paragraph()
|
||||
|
||||
# image file
|
||||
#
|
||||
|
|
@ -110,14 +120,18 @@ class ContentBlockFactory(BasePageFactory):
|
|||
for i in range(0, random.randint(3, 7)):
|
||||
block_type = random.choice(block_types)
|
||||
if block_type == 'text_block':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'text_block', 'text')] = RichText(fake_paragraph())
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'text_block', 'text')] = RichText(
|
||||
fake_paragraph())
|
||||
elif block_type == 'basic_knowledge':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'basic_knowledge', 'description')] = RichText(fake_paragraph())
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'basic_knowledge', 'description')] = RichText(
|
||||
fake_paragraph())
|
||||
# kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'basic_knowledge', 'description')] = ..url..
|
||||
elif block_type == 'student_entry':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'student_entry', 'task_text')] = RichText(fake_paragraph())
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'student_entry', 'task_text')] = RichText(
|
||||
fake_paragraph())
|
||||
elif block_type == 'image_block':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'image_block', 'image__title')] = fake_paragraph()
|
||||
kwargs[
|
||||
'{}__{}__{}__{}'.format(stream_field_name, i, 'image_block', 'image__title')] = fake_paragraph()
|
||||
elif block_type == 'task':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'task', 'text')] = RichText(fake_paragraph())
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList,
|
|||
from wagtail.core.fields import StreamField
|
||||
from wagtail.images.blocks import ImageChooserBlock
|
||||
|
||||
from book.blocks import TextBlock, BasicKnowledgeBlock, StudentEntryBlock
|
||||
from book.blocks import TextBlock, BasicKnowledgeBlock, StudentEntryBlock, LinkBlock
|
||||
from core.wagtail_utils import StrictHierarchyPage
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -21,6 +21,7 @@ class ContentBlock(StrictHierarchyPage):
|
|||
('basic_knowledge', BasicKnowledgeBlock(icon='placeholder')),
|
||||
('student_entry', StudentEntryBlock(icon='download')),
|
||||
('image_block', ImageChooserBlock(icon='image')),
|
||||
('link_block', LinkBlock(icon='link')),
|
||||
('task', TextBlock(icon='tick'))
|
||||
], null=True, blank=True)
|
||||
|
||||
|
|
|
|||
|
|
@ -81,16 +81,10 @@ data = [
|
|||
}
|
||||
},
|
||||
{
|
||||
'type': 'text_block',
|
||||
'type': 'link_block',
|
||||
'value': {
|
||||
'text': """<p>Das folgende Interview bezieht sich auf Jugendliche, die Ihre Lehre im Sommer begonnen haben. Lesen Sie das Interview durch und bearbeiten Sie anschliessend die Aufgaben.</p>
|
||||
<p>Aufgaben zum Interview «Das ist ein ganz markanter Wechsel»</p>"""
|
||||
}
|
||||
},
|
||||
{
|
||||
'type': 'task',
|
||||
'value': {
|
||||
'text': '<p>Erklären Sie, welche Informationen den Leserinnen und Lesern in der Einleitung vermittelt werden.</p>'
|
||||
'text': 'Netflix & Chill',
|
||||
'url': 'https://netflix.com'
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from factory import CREATE_STRATEGY
|
|||
from wagtail.core.rich_text import RichText
|
||||
|
||||
from book.blocks import ImageUrlBlock
|
||||
from book.factories import TextBlockFactory, BasicKnowledgeBlockFactory, ImageUrlBlockBlockFactory
|
||||
from book.factories import TextBlockFactory, BasicKnowledgeBlockFactory, ImageUrlBlockBlockFactory, LinkBlockFactory
|
||||
from core.factories import fake, fake_paragraph
|
||||
from rooms.models import Room, RoomEntry
|
||||
from user.models import UserGroup
|
||||
|
|
@ -37,7 +37,7 @@ class RoomEntryFactory(factory.django.DjangoModelFactory):
|
|||
contents = wagtail_factories.StreamFieldFactory({
|
||||
'text_block': TextBlockFactory,
|
||||
'image_url': ImageUrlBlockBlockFactory,
|
||||
'image_block': wagtail_factories.ImageChooserBlockFactory
|
||||
'link_block': LinkBlockFactory
|
||||
})
|
||||
|
||||
@classmethod
|
||||
|
|
@ -50,13 +50,16 @@ class RoomEntryFactory(factory.django.DjangoModelFactory):
|
|||
|
||||
if block_type == 'text_block':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, field)] = RichText(value[field])
|
||||
|
||||
|
||||
if block_type == 'image_url':
|
||||
if field == 'url':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, field)] = value[field]
|
||||
else:
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, field)] = RichText(value[field])
|
||||
|
||||
if block_type == 'link_block':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, field)] = value[field]
|
||||
|
||||
# elif block_type == 'image_block':
|
||||
# kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, 'image__title')] = fake_paragraph()
|
||||
# if field == 'path':
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from django_extensions.db.models import TitleDescriptionModel, TitleSlugDescript
|
|||
from wagtail.core.fields import StreamField
|
||||
from wagtail.images.blocks import ImageChooserBlock
|
||||
|
||||
from book.blocks import ImageUrlBlock, BasicKnowledgeBlock
|
||||
from book.blocks import ImageUrlBlock, LinkBlock
|
||||
from book.models import ContentBlock, TextBlock
|
||||
from user.models import UserGroup
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ class RoomEntry(TitleSlugDescriptionModel):
|
|||
contents = StreamField([
|
||||
('text_block', TextBlock(icon='doc-full')),
|
||||
('image_url', ImageUrlBlock(icon='image')),
|
||||
('image_block', ImageChooserBlock(icon='image'))
|
||||
('link_block', LinkBlock(icon='link'))
|
||||
], null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
|||
Loading…
Reference in New Issue