Provide first working version of content block stream content generation

This commit is contained in:
Pawel Kowalski 2018-08-16 13:35:39 +02:00
parent 6c7a1c9a7b
commit 4b03a702fe
3 changed files with 16 additions and 18 deletions

View File

@ -1,31 +1,25 @@
from wagtail.core import blocks 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'] DEFAULT_RICH_TEXT_FEATURES = ['bold', 'italic', 'link', 'ol', 'ul']
class LinkBlock(blocks.StructBlock): # 'text_block' 'task'
url = blocks.URLBlock()
description = blocks.CharBlock()
class DocumentBlock(blocks.StructBlock):
document = DocumentChooserBlock()
description = blocks.CharBlock()
class TextBlock(blocks.StructBlock): class TextBlock(blocks.StructBlock):
text = blocks.CharBlock() text = blocks.CharBlock()
# 'modal_text'
class ModalTextBlock(blocks.StructBlock): class ModalTextBlock(blocks.StructBlock):
description = blocks.CharBlock() description = blocks.CharBlock()
modal_content = blocks.CharBlock() modal_content = blocks.CharBlock()
# 'student_entry'
class StudentEntryBlock(blocks.StructBlock): class StudentEntryBlock(blocks.StructBlock):
task_text = blocks.CharBlock() task_text = blocks.CharBlock()
# class ImageBlock # 'text_block' 'task' 'modal_text' 'student_entry' 'image_block'
#
# url = blocks.URLBlock()
# document = DocumentChooserBlock()

View File

@ -5,9 +5,9 @@ import wagtail_factories
from factory import CREATE_STRATEGY from factory import CREATE_STRATEGY
from book.blocks import DocumentBlock, ModalTextBlock from book.blocks import ModalTextBlock
from book.models import Book, Topic, Module, Chapter, ContentBlock, TextBlock from book.models import Book, Topic, Module, Chapter, ContentBlock, TextBlock
from core.factories import BasePageFactory, fake, DummyImageFactory, fake_title from core.factories import BasePageFactory, fake, DummyImageFactory, fake_title, fake_title_noparam
class BookFactory(BasePageFactory): class BookFactory(BasePageFactory):
@ -75,9 +75,9 @@ class ContentBlockFactory(BasePageFactory):
for jdx, field in enumerate(value): for jdx, field in enumerate(value):
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, resource['type'], field)] = value[field] kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, resource['type'], field)] = value[field]
del kwargs[stream_field_name] del kwargs[stream_field_name]
# else: else:
# for i in range(0, random.randint(3, 7)): for i in range(0, random.randint(3, 7)):
# kwargs['{}__{}__{}__b'.format(stream_field_name, i, random.choice(['link', 'document']))] = None kwargs['{}__{}__{}__b'.format(stream_field_name, i, 'text_block', 'text')] = fake_title_noparam()
@classmethod @classmethod
def create(cls, **kwargs): def create(cls, **kwargs):

View File

@ -17,6 +17,10 @@ def fake_title(x):
return fake.sentence(nb_words=random.randint(2, 4)).replace('.', '') return fake.sentence(nb_words=random.randint(2, 4)).replace('.', '')
def fake_title_noparam():
return fake_title(None)
class BasePageFactory(wagtail_factories.PageFactory): class BasePageFactory(wagtail_factories.PageFactory):
title = factory.LazyAttribute(fake_title) title = factory.LazyAttribute(fake_title)