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.blocks.field_block import RichTextBlock
from wagtail.documents.blocks import DocumentChooserBlock
DEFAULT_RICH_TEXT_FEATURES = ['bold', 'italic', 'link', 'ol', 'ul']
class LinkBlock(blocks.StructBlock):
url = blocks.URLBlock()
description = blocks.CharBlock()
class DocumentBlock(blocks.StructBlock):
document = DocumentChooserBlock()
description = blocks.CharBlock()
# 'text_block' 'task'
class TextBlock(blocks.StructBlock):
text = blocks.CharBlock()
# 'modal_text'
class ModalTextBlock(blocks.StructBlock):
description = blocks.CharBlock()
modal_content = blocks.CharBlock()
# 'student_entry'
class StudentEntryBlock(blocks.StructBlock):
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 book.blocks import DocumentBlock, ModalTextBlock
from book.blocks import ModalTextBlock
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):
@ -75,9 +75,9 @@ class ContentBlockFactory(BasePageFactory):
for jdx, field in enumerate(value):
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, resource['type'], field)] = value[field]
del kwargs[stream_field_name]
# else:
# for i in range(0, random.randint(3, 7)):
# kwargs['{}__{}__{}__b'.format(stream_field_name, i, random.choice(['link', 'document']))] = None
else:
for i in range(0, random.randint(3, 7)):
kwargs['{}__{}__{}__b'.format(stream_field_name, i, 'text_block', 'text')] = fake_title_noparam()
@classmethod
def create(cls, **kwargs):

View File

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