Merge branch 'master' of github.com:ramonwenger/skillbox
This commit is contained in:
commit
08527a7575
|
|
@ -9,10 +9,10 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import TextBlock from '@/components/TextBlock.vue';
|
||||
import Task from '@/components/Task.vue';
|
||||
import ImageBlock from '@/components/ImageBlock.vue';
|
||||
import StudentEntry from '@/components/StudentEntry.vue';
|
||||
import TextBlock from '@/components/content-blocks/TextBlock.vue';
|
||||
import Task from '@/components/content-blocks/Task.vue';
|
||||
import ImageBlock from '@/components/content-blocks/ImageBlock.vue';
|
||||
import StudentEntry from '@/components/content-blocks/StudentEntry.vue';
|
||||
|
||||
export default {
|
||||
props: ['contentBlock'],
|
||||
|
|
|
|||
|
|
@ -4,12 +4,41 @@
|
|||
from graphene.types import Scalar
|
||||
from graphene_django.converter import convert_django_field
|
||||
from wagtail.core.fields import StreamField
|
||||
from wagtail.images.models import Image
|
||||
|
||||
|
||||
class GenericStreamFieldType(Scalar):
|
||||
@staticmethod
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -5,18 +5,18 @@ DEFAULT_RICH_TEXT_FEATURES = ['bold', 'italic', 'link', 'ol', 'ul']
|
|||
|
||||
# 'text_block' 'task'
|
||||
class TextBlock(blocks.StructBlock):
|
||||
text = blocks.CharBlock()
|
||||
text = blocks.RichTextBlock()
|
||||
|
||||
|
||||
# 'modal_text'
|
||||
class ModalTextBlock(blocks.StructBlock):
|
||||
description = blocks.CharBlock()
|
||||
modal_content = blocks.CharBlock()
|
||||
description = blocks.RichTextBlock()
|
||||
url = blocks.URLBlock()
|
||||
|
||||
|
||||
# 'student_entry'
|
||||
class StudentEntryBlock(blocks.StructBlock):
|
||||
task_text = blocks.CharBlock()
|
||||
task_text = blocks.RichTextBlock()
|
||||
|
||||
|
||||
# 'text_block' 'task' 'modal_text' 'student_entry' 'image_block'
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ import factory
|
|||
import wagtail_factories
|
||||
|
||||
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 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):
|
||||
description = factory.LazyAttribute(fake_title)
|
||||
modal_content = factory.LazyAttribute(fake_title)
|
||||
url = factory.LazyAttribute(lambda x: fake.uri())
|
||||
|
||||
class Meta:
|
||||
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 Meta:
|
||||
model = ContentBlock
|
||||
|
|
@ -65,6 +75,9 @@ class ContentBlockFactory(BasePageFactory):
|
|||
contents = wagtail_factories.StreamFieldFactory({
|
||||
'text_block': TextBlockFactory,
|
||||
'modal_text': ModalTextBlockFactory,
|
||||
'student_entry': StudentEntryBlockFactory,
|
||||
'image_block': wagtail_factories.ImageChooserBlockFactory,
|
||||
'task': TextBlockFactory
|
||||
})
|
||||
|
||||
@classmethod
|
||||
|
|
@ -73,11 +86,22 @@ class ContentBlockFactory(BasePageFactory):
|
|||
for idx, resource in enumerate(kwargs[stream_field_name]):
|
||||
value = resource['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]
|
||||
else:
|
||||
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
|
||||
def create(cls, **kwargs):
|
||||
|
|
|
|||
|
|
@ -69,14 +69,14 @@ data = [
|
|||
'type': 'text_block',
|
||||
'value': {
|
||||
'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',
|
||||
'value': {
|
||||
'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>'
|
||||
}
|
||||
},
|
||||
# {
|
||||
|
|
|
|||
Loading…
Reference in New Issue