Fix dummy data creation

This commit is contained in:
Ramon Wenger 2018-08-21 16:49:50 +02:00
parent 71c339a40c
commit 98df92d559
3 changed files with 12 additions and 9 deletions

View File

@ -8,7 +8,7 @@ from wagtail.core.rich_text import RichText
from book.blocks import ModalTextBlock, StudentEntryBlock
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, fake_paragraph
class BookFactory(BasePageFactory):
@ -43,14 +43,14 @@ class ChapterFactory(BasePageFactory):
class TextBlockFactory(wagtail_factories.StructBlockFactory):
text = factory.LazyAttribute(fake_title)
text = factory.LazyAttribute(fake_paragraph)
class Meta:
model = TextBlock
class ModalTextBlockFactory(wagtail_factories.StructBlockFactory):
description = factory.LazyAttribute(fake_title)
description = factory.LazyAttribute(fake_paragraph)
url = factory.LazyAttribute(lambda x: fake.uri())
class Meta:
@ -92,16 +92,16 @@ 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_title_noparam())
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'text_block', 'text')] = RichText(fake_paragraph())
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')] = RichText(fake_paragraph())
# 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())
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_title_noparam()
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_title_noparam())
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'task', 'text')] = RichText(fake_paragraph())
@classmethod
def create(cls, **kwargs):

View File

@ -20,6 +20,9 @@ def fake_title(x):
def fake_title_noparam():
return fake_title(None)
def fake_paragraph(x=None):
return '<p>{}</p>'.format(fake_title_noparam())
class BasePageFactory(wagtail_factories.PageFactory):
title = factory.LazyAttribute(fake_title)

View File

@ -76,7 +76,7 @@ data = [
'type': 'text_block',
'value': {
'type': 'text_block',
'text': '<p>Das folgende Interview bezieht sich auf Jugendliche, die Ihre Lehre im Sommer begonnen haben.<p></p>Lesen Sie das Interview durch und bearbeiten Sie anschliessend die Aufgaben.</p>'
'text': '<p>Das folgende Interview bezieht sich auf Jugendliche, die Ihre Lehre im Sommer begonnen haben. </p> <p>Lesen Sie das Interview durch und bearbeiten Sie anschliessend die Aufgaben.</p>'
}
},
# {