Generate all types of content

This commit is contained in:
Pawel Kowalski 2018-08-16 15:48:46 +02:00
parent 80719e9a65
commit ef4fb4b20e
2 changed files with 21 additions and 9 deletions

View File

@ -10,13 +10,13 @@ class TextBlock(blocks.StructBlock):
# 'modal_text' # 'modal_text'
class ModalTextBlock(blocks.StructBlock): class ModalTextBlock(blocks.StructBlock):
description = blocks.CharBlock() description = blocks.RichTextBlock()
modal_content = blocks.CharBlock() url = blocks.URLBlock()
# 'student_entry' # 'student_entry'
class StudentEntryBlock(blocks.StructBlock): class StudentEntryBlock(blocks.StructBlock):
task_text = blocks.CharBlock() task_text = blocks.RichTextBlock()
# 'text_block' 'task' 'modal_text' 'student_entry' 'image_block' # 'text_block' 'task' 'modal_text' 'student_entry' 'image_block'

View File

@ -6,7 +6,7 @@ import wagtail_factories
from factory import CREATE_STRATEGY from factory import CREATE_STRATEGY
from wagtail.core.rich_text import RichText from wagtail.core.rich_text import RichText
from book.blocks import ModalTextBlock from book.blocks import ModalTextBlock, StudentEntryBlock
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, fake_title_noparam from core.factories import BasePageFactory, fake, DummyImageFactory, fake_title, fake_title_noparam
@ -51,12 +51,18 @@ class TextBlockFactory(wagtail_factories.StructBlockFactory):
class ModalTextBlockFactory(wagtail_factories.StructBlockFactory): class ModalTextBlockFactory(wagtail_factories.StructBlockFactory):
description = factory.LazyAttribute(fake_title) description = factory.LazyAttribute(fake_title)
modal_content = factory.LazyAttribute(fake_title) url = factory.LazyAttribute(lambda x: fake.uri())
class Meta: class Meta:
model = ModalTextBlock model = ModalTextBlock
class StudentEntryBlockFactory(wagtail_factories.StructBlockFactory):
class Meta:
model = StudentEntryBlock
block_types = ['text_block', 'modal_text', 'student_entry', 'image_block', 'task'] block_types = ['text_block', 'modal_text', 'student_entry', 'image_block', 'task']
@ -69,7 +75,9 @@ class ContentBlockFactory(BasePageFactory):
contents = wagtail_factories.StreamFieldFactory({ contents = wagtail_factories.StreamFieldFactory({
'text_block': TextBlockFactory, 'text_block': TextBlockFactory,
'modal_text': ModalTextBlockFactory, 'modal_text': ModalTextBlockFactory,
'image_block': wagtail_factories.ImageChooserBlockFactory 'student_entry': StudentEntryBlockFactory,
'image_block': wagtail_factories.ImageChooserBlockFactory,
'task': TextBlockFactory
}) })
@classmethod @classmethod
@ -85,11 +93,15 @@ class ContentBlockFactory(BasePageFactory):
block_type = random.choice(block_types) block_type = random.choice(block_types)
if block_type == 'text_block': if block_type == 'text_block':
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'text_block', 'text')] = RichText(fake_title_noparam()) kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'text_block', 'text')] = RichText(fake_title_noparam())
elif block_type == 'modal_text':
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'modal_text', 'description')] = RichText(fake_title_noparam())
# kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'modal_text', 'description')] = ..url..
elif block_type == 'student_entry':
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'student_entry', 'task_text')] = RichText(fake_title_noparam())
elif block_type == 'image_block': elif block_type == 'image_block':
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'image_block', 'image__title')] = fake_title_noparam() kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'image_block', 'image__title')] = fake_title_noparam()
elif block_type == 'task':
# for i in range(4, 6): kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'task', 'text')] = RichText(fake_title_noparam())
# kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'image_block', 'image')] = ''
@classmethod @classmethod
def create(cls, **kwargs): def create(cls, **kwargs):