Merge branch 'master' of github.com:ramonwenger/skillbox

This commit is contained in:
Ramon Wenger 2018-08-16 16:32:06 +02:00
commit 08527a7575
9 changed files with 68 additions and 15 deletions

View File

@ -9,10 +9,10 @@
</template> </template>
<script> <script>
import TextBlock from '@/components/TextBlock.vue'; import TextBlock from '@/components/content-blocks/TextBlock.vue';
import Task from '@/components/Task.vue'; import Task from '@/components/content-blocks/Task.vue';
import ImageBlock from '@/components/ImageBlock.vue'; import ImageBlock from '@/components/content-blocks/ImageBlock.vue';
import StudentEntry from '@/components/StudentEntry.vue'; import StudentEntry from '@/components/content-blocks/StudentEntry.vue';
export default { export default {
props: ['contentBlock'], props: ['contentBlock'],

View File

@ -4,12 +4,41 @@
from graphene.types import Scalar from graphene.types import Scalar
from graphene_django.converter import convert_django_field from graphene_django.converter import convert_django_field
from wagtail.core.fields import StreamField from wagtail.core.fields import StreamField
from wagtail.images.models import Image
class GenericStreamFieldType(Scalar): class GenericStreamFieldType(Scalar):
@staticmethod @staticmethod
def serialize(stream_value): def serialize(stream_value):
return stream_value.stream_data stream_data = stream_value.stream_data
for d in stream_data:
if isinstance(d, dict):
_type = d['type']
if _type == 'image_block':
_value = d['value']
value = {
# 'value': _value,
# 'id': d['id'],
'path': Image.objects.get(id=_value).file.url
}
d['value'] = value
# value = dict(d['value'])
# if 'document' in value:
# value['document'] = Document.objects.get(id=value['document']).file.url
# if 'image' in value:
# value['image'] = Image.objects.get(id=value['image']).file.url
# else:
# _type = d[0]
# value = dict(d[1])
# if 'document' in value:
# value['document'] = value['document'].file.url
# if 'image' in value:
# value['image'] = value['image'].file.url
return stream_data
@convert_django_field.register(StreamField) @convert_django_field.register(StreamField)

View File

@ -5,18 +5,18 @@ DEFAULT_RICH_TEXT_FEATURES = ['bold', 'italic', 'link', 'ol', 'ul']
# 'text_block' 'task' # 'text_block' 'task'
class TextBlock(blocks.StructBlock): class TextBlock(blocks.StructBlock):
text = blocks.CharBlock() text = blocks.RichTextBlock()
# '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

@ -4,8 +4,9 @@ import factory
import wagtail_factories import wagtail_factories
from factory import CREATE_STRATEGY from factory import CREATE_STRATEGY
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
@ -50,12 +51,21 @@ 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']
class ContentBlockFactory(BasePageFactory): class ContentBlockFactory(BasePageFactory):
class Meta: class Meta:
model = ContentBlock model = ContentBlock
@ -65,6 +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,
'student_entry': StudentEntryBlockFactory,
'image_block': wagtail_factories.ImageChooserBlockFactory,
'task': TextBlockFactory
}) })
@classmethod @classmethod
@ -73,11 +86,22 @@ class ContentBlockFactory(BasePageFactory):
for idx, resource in enumerate(kwargs[stream_field_name]): for idx, resource in enumerate(kwargs[stream_field_name]):
value = resource['value'] value = resource['value']
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)] = RichText(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, 'text_block', 'text')] = fake_title_noparam() block_type = random.choice(block_types)
if block_type == 'text_block':
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':
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'image_block', 'image__title')] = fake_title_noparam()
elif block_type == 'task':
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'task', 'text')] = RichText(fake_title_noparam())
@classmethod @classmethod
def create(cls, **kwargs): def create(cls, **kwargs):

View File

@ -69,14 +69,14 @@ data = [
'type': 'text_block', 'type': 'text_block',
'value': { 'value': {
'type': 'text_block', 'type': 'text_block',
'text': 'Sie haben diesen Sommer ihre Lehre begonnen. Was bedeutet dieser neue Abschnitt für Sie?\nHalten Sie Ihre Erfahrungen im Bereich fest und stellen Sie diese anschliessend der Klasse vor.' 'text': '<p>Sie haben diesen Sommer ihre Lehre begonnen. Was bedeutet dieser neue Abschnitt für Sie?<br/>Halten Sie Ihre Erfahrungen im Bereich fest und stellen Sie diese anschliessend der Klasse vor.</p>'
} }
}, },
{ {
'type': 'text_block', 'type': 'text_block',
'value': { 'value': {
'type': 'text_block', 'type': 'text_block',
'text': 'Das folgende Interview bezieht sich auf Jugendliche, die Ihre Lehre im Sommer begonnen haben. Lesen Sie das Interview durch und bearbeiten Sie anschliessend die Aufgaben.' '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>'
} }
}, },
# { # {