Subtitle not Description

This commit is contained in:
Pawel Kowalski 2018-09-04 15:42:34 +02:00
parent a963111287
commit ff9a07e187
5 changed files with 46 additions and 20 deletions

View File

@ -16,7 +16,7 @@ query RoomEntriesQuery($slug: String!) {
id id
slug slug
title title
description subtitle
contents contents
author { author {
id id

View File

@ -14,6 +14,12 @@ class BasicKnowledgeBlock(blocks.StructBlock):
url = blocks.URLBlock() url = blocks.URLBlock()
# 'image_url'
class ImageUrlBlock(blocks.StructBlock):
title = blocks.RichTextBlock()
url = blocks.URLBlock()
# 'student_entry' # 'student_entry'
class StudentEntryBlock(blocks.StructBlock): class StudentEntryBlock(blocks.StructBlock):
task_text = blocks.RichTextBlock() task_text = blocks.RichTextBlock()

View File

@ -5,9 +5,9 @@ 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 BasicKnowledgeBlock, StudentEntryBlock from book.blocks import BasicKnowledgeBlock, StudentEntryBlock, ImageUrlBlock
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_paragraph from core.factories import BasePageFactory, fake, DummyImageFactory, fake_paragraph, fake_title
class BookFactory(BasePageFactory): class BookFactory(BasePageFactory):
@ -56,6 +56,14 @@ class BasicKnowledgeBlockFactory(wagtail_factories.StructBlockFactory):
model = BasicKnowledgeBlock model = BasicKnowledgeBlock
class ImageUrlBlockBlockFactory(wagtail_factories.StructBlockFactory):
title = fake_title()
url = factory.LazyAttribute(lambda x: 'https://picsum.photos/200/300/?random')
class Meta:
model = ImageUrlBlock
class StudentEntryBlockFactory(wagtail_factories.StructBlockFactory): class StudentEntryBlockFactory(wagtail_factories.StructBlockFactory):
class Meta: class Meta:
@ -69,7 +77,6 @@ class ContentBlockFactory(BasePageFactory):
class Meta: class Meta:
model = ContentBlock model = ContentBlock
# parent = factory.LazyAttribute(lambda x: Site.objects.get(is_default_site=True).root_page)
type = factory.LazyAttribute(lambda x: random.choice(['plain', 'yellow', 'green', 'blue'])) type = factory.LazyAttribute(lambda x: random.choice(['plain', 'yellow', 'green', 'blue']))
contents = wagtail_factories.StreamFieldFactory({ contents = wagtail_factories.StreamFieldFactory({
@ -93,9 +100,10 @@ class ContentBlockFactory(BasePageFactory):
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': 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()
# kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'image_block', )] = fake_paragraph()
#
# image file # image file
#
# kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'image_block', )] = fake_paragraph()
del kwargs[stream_field_name] del kwargs[stream_field_name]
else: else:

View File

@ -19,7 +19,7 @@ data = [
'entries': [ 'entries': [
{ {
'title': 'Ein neues Festival auf dem Gurten und ich bin dabei!', 'title': 'Ein neues Festival auf dem Gurten und ich bin dabei!',
'description': 'Endlich war es soweit. Zum ersten Mal fand am 2. und 3. Juli 1977 das 1. Internationale …', 'subtitle': 'Endlich war es soweit. Zum ersten Mal fand am 2. und 3. Juli 1977 das 1. Internationale …',
'contents': [ 'contents': [
{ {
'type': 'image_block', 'type': 'image_block',
@ -45,7 +45,7 @@ data = [
}, },
{ {
'title': 'Mein Tagesblog', 'title': 'Mein Tagesblog',
'description': 'https://blogger.com/cruel-festivals-around-the-world/', 'subtitle': 'https://blogger.com/cruel-festivals-around-the-world/',
'contents': [ 'contents': [
{ {
'type': 'image_block', 'type': 'image_block',
@ -71,7 +71,7 @@ data = [
}, },
{ {
'title': 'Woodstock', 'title': 'Woodstock',
'description': 'In Woodstock hat sich dem Mythos nach vor genau vierzig Jahren das Lebensgefühl …', 'subtitle': 'In Woodstock hat sich dem Mythos nach vor genau vierzig Jahren das Lebensgefühl …',
'contents': [ 'contents': [
{ {
'type': 'image_block', 'type': 'image_block',
@ -97,7 +97,7 @@ data = [
}, },
{ {
'title': 'Das Festival', 'title': 'Das Festival',
'description': 'www.meinblog.ch', 'subtitle': 'www.meinblog.ch',
'contents': [ 'contents': [
{ {
'type': 'image_block', 'type': 'image_block',
@ -129,13 +129,13 @@ data = [
'entries': [ 'entries': [
{ {
'title': 'Ich heisse Jan und habe am 01. August 2017 meine Ausbildung begonnen. Pünktlich zum …', 'title': 'Ich heisse Jan und habe am 01. August 2017 meine Ausbildung begonnen. Pünktlich zum …',
'description': '', 'subtitle': '',
'contents': [ 'contents': [
{ {
'type': 'image_block', 'type': 'image_block',
'value': { 'value': {
'image__title': 'Ein Bild sagt mehr als 1000 Worte' 'image__title': 'Ein Bild sagt mehr als 1000 Worte',
# 'image': 'https://picsum.photos/200/300/?random', 'path': 'https://picsum.photos/200/300/?random',
} }
}, },
{ {
@ -155,13 +155,13 @@ data = [
}, },
{ {
'title': 'Mein Lehrbeginn', 'title': 'Mein Lehrbeginn',
'description': 'Was war ich angespannt… und nervös. Das hat sich aber schnell gelegt.', 'subtitle': 'Was war ich angespannt… und nervös. Das hat sich aber schnell gelegt.',
'contents': [ 'contents': [
{ {
'type': 'image_block', 'type': 'image_url',
'value': { 'value': {
'image__title': 'Ein Bild sagt mehr als 1000 Worte' 'title': 'Ein Bild sagt mehr als 1000 Worte',
# 'image': 'https://picsum.photos/200/300/?random', 'url': 'https://picsum.photos/200/300/?random'
} }
}, },
{ {

View File

@ -6,6 +6,7 @@ from django.contrib.auth import get_user_model
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 ImageUrlBlock
from book.factories import TextBlockFactory from book.factories import TextBlockFactory
from core.factories import fake, fake_paragraph from core.factories import fake, fake_paragraph
from rooms.models import Room, RoomEntry from rooms.models import Room, RoomEntry
@ -35,6 +36,7 @@ class RoomEntryFactory(factory.django.DjangoModelFactory):
contents = wagtail_factories.StreamFieldFactory({ contents = wagtail_factories.StreamFieldFactory({
'text_block': TextBlockFactory, 'text_block': TextBlockFactory,
'image_url': ImageUrlBlock,
'image_block': wagtail_factories.ImageChooserBlockFactory 'image_block': wagtail_factories.ImageChooserBlockFactory
}) })
@ -47,9 +49,19 @@ class RoomEntryFactory(factory.django.DjangoModelFactory):
block_type = resource['type'] block_type = resource['type']
if block_type == 'text_block': 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])
elif block_type == 'image_block':
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, 'image__title')] = fake_paragraph() # if block_type == 'image_url':
# kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'image_block', )] = fake_paragraph() # 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])
#
# elif block_type == 'image_block':
# kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, 'image__title')] = fake_paragraph()
# if field == 'path':
# field_value = value[field]
# kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, 'image__file')] = field_value
# # kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'image_block', )] = fake_paragraph()
del kwargs[stream_field_name] del kwargs[stream_field_name]
else: else: