Add document to solution, add more generic document block

This commit is contained in:
Ramon Wenger 2022-09-07 08:41:06 +02:00
parent 04aa7a2524
commit d96a8c7b11
3 changed files with 25 additions and 7 deletions

View File

@ -2,10 +2,10 @@ from django.db import models
from django.utils.text import slugify from django.utils.text import slugify
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.core.fields import RichTextField, StreamField from wagtail.core.fields import RichTextField, StreamField
from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.images.blocks import ImageChooserBlock from wagtail.images.blocks import ImageChooserBlock
from books.blocks import DocumentBlock, GeniallyBlock, InfogramBlock, InstrumentTextBlock, LinkBlock, SectionTitleBlock, \ from books.blocks import CMSDocumentBlock, DocumentBlock, GeniallyBlock, InfogramBlock, InstrumentTextBlock, LinkBlock, \
SectionTitleBlock, \
SubtitleBlock, ThinglinkBlock, VideoBlock SubtitleBlock, ThinglinkBlock, VideoBlock
from core.constants import DEFAULT_RICH_TEXT_FEATURES from core.constants import DEFAULT_RICH_TEXT_FEATURES
from core.wagtail_utils import StrictHierarchyPage from core.wagtail_utils import StrictHierarchyPage
@ -53,7 +53,7 @@ class BasicKnowledge(StrictHierarchyPage):
('genially_block', GeniallyBlock()), ('genially_block', GeniallyBlock()),
('thinglink_block', ThinglinkBlock()), ('thinglink_block', ThinglinkBlock()),
('subtitle', SubtitleBlock()), ('subtitle', SubtitleBlock()),
('cms_document_block', DocumentChooserBlock()), ('cms_document_block', CMSDocumentBlock()),
], null=True, blank=True) ], null=True, blank=True)
new_type = models.ForeignKey(InstrumentType, null=True, on_delete=models.PROTECT, related_name='instruments') new_type = models.ForeignKey(InstrumentType, null=True, on_delete=models.PROTECT, related_name='instruments')

View File

@ -1,4 +1,5 @@
from wagtail.core import blocks from wagtail.core import blocks
from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.snippets.blocks import SnippetChooserBlock from wagtail.snippets.blocks import SnippetChooserBlock
from assignments.models import Assignment from assignments.models import Assignment
@ -6,6 +7,11 @@ from core.constants import DEFAULT_RICH_TEXT_FEATURES, INSTRUMENTS_RICH_TEXT_FEA
from surveys.models import Survey from surveys.models import Survey
class CMSDocumentBlock(DocumentChooserBlock):
class Meta:
label = 'CMS Document'
# link_block # link_block
class LinkBlock(blocks.StructBlock): class LinkBlock(blocks.StructBlock):
class Meta: class Meta:
@ -23,6 +29,14 @@ class TextBlock(blocks.StructBlock):
text = blocks.RichTextBlock(features=DEFAULT_RICH_TEXT_FEATURES) text = blocks.RichTextBlock(features=DEFAULT_RICH_TEXT_FEATURES)
class SolutionBlock(blocks.StructBlock):
class Meta:
icon = 'tick'
text = blocks.RichTextBlock(features=DEFAULT_RICH_TEXT_FEATURES)
document = CMSDocumentBlock()
# 'basic_knowledge' # 'basic_knowledge'
class BasicKnowledgeBlock(blocks.StructBlock): class BasicKnowledgeBlock(blocks.StructBlock):
class Meta: class Meta:
@ -115,6 +129,8 @@ class InstructionBlock(blocks.StructBlock):
url = blocks.URLBlock() url = blocks.URLBlock()
text = blocks.TextBlock(required=False) text = blocks.TextBlock(required=False)
document = DocumentChooserBlock()
# 'text_block' 'task' 'basic_knowledge' 'student_entry' 'image_block' # 'text_block' 'task' 'basic_knowledge' 'student_entry' 'image_block'
# #

View File

@ -4,11 +4,11 @@ from django.db import models
from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList, StreamFieldPanel from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList, StreamFieldPanel
from wagtail.core.blocks import StreamBlock from wagtail.core.blocks import StreamBlock
from wagtail.core.fields import StreamField from wagtail.core.fields import StreamField
from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.images.blocks import ImageChooserBlock from wagtail.images.blocks import ImageChooserBlock
from core.wagtail_utils import get_default_settings from core.wagtail_utils import get_default_settings
from books.blocks import TextBlock, BasicKnowledgeBlock, LinkBlock, VideoBlock, DocumentBlock, \ from books.blocks import CMSDocumentBlock, SolutionBlock, TextBlock, BasicKnowledgeBlock, LinkBlock, VideoBlock, \
DocumentBlock, \
ImageUrlBlock, AssignmentBlock, InfogramBlock, GeniallyBlock, SubtitleBlock, SurveyBlock, ModuleRoomSlugBlock, \ ImageUrlBlock, AssignmentBlock, InfogramBlock, GeniallyBlock, SubtitleBlock, SurveyBlock, ModuleRoomSlugBlock, \
ThinglinkBlock, InstructionBlock ThinglinkBlock, InstructionBlock
from books.utils import get_type_and_value from books.utils import get_type_and_value
@ -56,7 +56,8 @@ class ContentBlock(StrictHierarchyPage):
('image_block', ImageChooserBlock()), ('image_block', ImageChooserBlock()),
('image_url_block', ImageUrlBlock()), ('image_url_block', ImageUrlBlock()),
('link_block', LinkBlock()), ('link_block', LinkBlock()),
('solution', TextBlock(icon='tick')), # ('solution', TextBlock(icon='tick')),
('solution', SolutionBlock()),
('video_block', VideoBlock()), ('video_block', VideoBlock()),
('document_block', DocumentBlock()), ('document_block', DocumentBlock()),
('infogram_block', InfogramBlock()), ('infogram_block', InfogramBlock()),
@ -65,7 +66,8 @@ class ContentBlock(StrictHierarchyPage):
('subtitle', SubtitleBlock()), ('subtitle', SubtitleBlock()),
('instruction', InstructionBlock()), ('instruction', InstructionBlock()),
('module_room_slug', ModuleRoomSlugBlock()), ('module_room_slug', ModuleRoomSlugBlock()),
('cms_document_block', DocumentChooserBlock()) # ('cms_document_block', DocumentChooserBlock(label='CMS Document'))
('cms_document_block', CMSDocumentBlock())
] ]
content_list_item = StreamBlock(content_blocks) content_list_item = StreamBlock(content_blocks)