Refactor some code
Implement suggestions from pull request
This commit is contained in:
parent
cb0e23a5ba
commit
9ce6f9d48e
|
|
@ -6,16 +6,29 @@ from assignments.models import Assignment
|
|||
from core.constants import DEFAULT_RICH_TEXT_FEATURES, INSTRUMENTS_RICH_TEXT_FEATURES
|
||||
from surveys.models import Survey
|
||||
|
||||
"""
|
||||
Using a StructBlock inside a StreamField (e.g. inside a ContentBlock):
|
||||
as an illustration
|
||||
data = {'text': 'This is me'}
|
||||
self.contents.append(('solution', data))
|
||||
|
||||
by itself:
|
||||
block = SolutionBlock()
|
||||
data = {'text': 'This is me'}
|
||||
value = block.to_python(data)
|
||||
cleaned_value = block.clean(value)
|
||||
"""
|
||||
|
||||
|
||||
class CMSDocumentBlock(DocumentChooserBlock):
|
||||
class Meta:
|
||||
label = 'CMS Document'
|
||||
label = "CMS Document"
|
||||
|
||||
|
||||
# link_block
|
||||
class LinkBlock(blocks.StructBlock):
|
||||
class Meta:
|
||||
icon = 'link'
|
||||
icon = "link"
|
||||
|
||||
text = blocks.TextBlock()
|
||||
url = blocks.URLBlock()
|
||||
|
|
@ -24,14 +37,14 @@ class LinkBlock(blocks.StructBlock):
|
|||
# 'text_block' 'solution'
|
||||
class TextBlock(blocks.StructBlock):
|
||||
class Meta:
|
||||
icon = 'doc-full'
|
||||
icon = "doc-full"
|
||||
|
||||
text = blocks.RichTextBlock(features=DEFAULT_RICH_TEXT_FEATURES)
|
||||
|
||||
|
||||
class SolutionBlock(blocks.StructBlock):
|
||||
class Meta:
|
||||
icon = 'tick'
|
||||
icon = "tick"
|
||||
|
||||
text = blocks.RichTextBlock(features=DEFAULT_RICH_TEXT_FEATURES)
|
||||
document = CMSDocumentBlock(required=False)
|
||||
|
|
@ -40,17 +53,19 @@ class SolutionBlock(blocks.StructBlock):
|
|||
# 'basic_knowledge'
|
||||
class BasicKnowledgeBlock(blocks.StructBlock):
|
||||
class Meta:
|
||||
icon = 'placeholder'
|
||||
label = 'Instrument'
|
||||
icon = "placeholder"
|
||||
label = "Instrument"
|
||||
|
||||
description = blocks.RichTextBlock(required=False)
|
||||
basic_knowledge = blocks.PageChooserBlock(required=True, page_type='basicknowledge.BasicKnowledge')
|
||||
basic_knowledge = blocks.PageChooserBlock(
|
||||
required=True, page_type="basicknowledge.BasicKnowledge"
|
||||
)
|
||||
|
||||
|
||||
# 'image_url'
|
||||
class ImageUrlBlock(blocks.StructBlock):
|
||||
class Meta:
|
||||
icon = 'image'
|
||||
icon = "image"
|
||||
|
||||
title = blocks.TextBlock()
|
||||
url = blocks.URLBlock()
|
||||
|
|
@ -59,7 +74,7 @@ class ImageUrlBlock(blocks.StructBlock):
|
|||
# 'assignment'
|
||||
class AssignmentBlock(blocks.StructBlock):
|
||||
class Meta:
|
||||
icon = 'download'
|
||||
icon = "download"
|
||||
|
||||
assignment_id = SnippetChooserBlock(Assignment)
|
||||
|
||||
|
|
@ -67,7 +82,7 @@ class AssignmentBlock(blocks.StructBlock):
|
|||
# 'survey'
|
||||
class SurveyBlock(blocks.StructBlock):
|
||||
class Meta:
|
||||
icon = 'form'
|
||||
icon = "form"
|
||||
|
||||
survey_id = SnippetChooserBlock(Survey)
|
||||
|
||||
|
|
@ -75,7 +90,7 @@ class SurveyBlock(blocks.StructBlock):
|
|||
# 'video_block'
|
||||
class VideoBlock(blocks.StructBlock):
|
||||
class Meta:
|
||||
icon = 'media'
|
||||
icon = "media"
|
||||
|
||||
url = blocks.URLBlock()
|
||||
|
||||
|
|
@ -83,7 +98,7 @@ class VideoBlock(blocks.StructBlock):
|
|||
# 'document_block'
|
||||
class DocumentBlock(blocks.StructBlock):
|
||||
class Meta:
|
||||
icon = 'doc-full'
|
||||
icon = "doc-full"
|
||||
|
||||
url = blocks.URLBlock()
|
||||
|
||||
|
|
@ -111,21 +126,21 @@ class SubtitleBlock(blocks.StructBlock):
|
|||
|
||||
class InstrumentTextBlock(blocks.StructBlock):
|
||||
class Meta:
|
||||
icon = 'doc-full'
|
||||
icon = "doc-full"
|
||||
|
||||
text = blocks.RichTextBlock(features=INSTRUMENTS_RICH_TEXT_FEATURES)
|
||||
|
||||
|
||||
class ModuleRoomSlugBlock(blocks.StructBlock):
|
||||
class Meta:
|
||||
icon = 'link'
|
||||
icon = "link"
|
||||
|
||||
title = blocks.TextBlock()
|
||||
|
||||
|
||||
class InstructionBlock(blocks.StructBlock):
|
||||
class Meta:
|
||||
icon = 'help'
|
||||
icon = "help"
|
||||
|
||||
url = blocks.URLBlock(required=False)
|
||||
text = blocks.TextBlock(required=False)
|
||||
|
|
|
|||
|
|
@ -163,14 +163,9 @@ class ContentBlock(StrictHierarchyPage, GraphqlNodeMixin):
|
|||
|
||||
# duplicate all attached Surveys and Assignments
|
||||
def duplicate_attached_entities(self):
|
||||
# logger.debug("starting to duplicate inside the content block")
|
||||
duplicate_entities = duplicate_entities_generator(self.module)
|
||||
# logger.debug(f"new module: {self.module}")
|
||||
iterator = map(duplicate_entities, self.contents)
|
||||
# logger.debug("here is the iterator")
|
||||
new_contents = list(iterator)
|
||||
duplicate_entities_func = duplicate_entities_generator(self.module)
|
||||
new_contents = [duplicate_entities_func(content) for content in self.contents]
|
||||
cleaned_contents = [item for item in new_contents if item is not None]
|
||||
# logger.debug(new_contents)
|
||||
# we can't just insert a list here, we need a StreamValue data type
|
||||
# so we need to clear the list, then add each element in turn
|
||||
self.contents.clear()
|
||||
|
|
@ -179,13 +174,8 @@ class ContentBlock(StrictHierarchyPage, GraphqlNodeMixin):
|
|||
self.contents.append(content)
|
||||
|
||||
# as an illustration
|
||||
# block = SolutionBlock()
|
||||
# data = {'text': 'This is me'}
|
||||
# value = block.to_python(data)
|
||||
# clean_value = block.clean(value)
|
||||
# self.contents.append(('solution', clean_value))
|
||||
# logger.debug("self.contents")
|
||||
# logger.debug(self.contents)
|
||||
# self.contents.append(('solution', data))
|
||||
self.save()
|
||||
|
||||
def is_hidden_for_class(self, school_class):
|
||||
|
|
|
|||
Loading…
Reference in New Issue