Handle edge case when the assignment or survey is not set correctly
This commit is contained in:
parent
deecef5e5b
commit
41610cc0b6
|
|
@ -44,6 +44,8 @@ def duplicate_entities_generator(new_module):
|
|||
# logger.debug(block)
|
||||
if content_type == "assignment":
|
||||
assignment = value.get("assignment_id")
|
||||
if assignment is None:
|
||||
return None
|
||||
# copy the assignment
|
||||
assignment.pk = None
|
||||
assignment.title = f"{assignment.title} (Kopie)"
|
||||
|
|
@ -56,6 +58,8 @@ def duplicate_entities_generator(new_module):
|
|||
if content_type == "survey":
|
||||
# logger.debug(value)
|
||||
survey = value.get("survey_id")
|
||||
if survey is None:
|
||||
return None
|
||||
# copy the survey
|
||||
survey.pk = None
|
||||
survey.title = f"{survey.title} (Kopie)"
|
||||
|
|
@ -165,13 +169,13 @@ class ContentBlock(StrictHierarchyPage, GraphqlNodeMixin):
|
|||
iterator = map(duplicate_entities, self.contents)
|
||||
# logger.debug("here is the iterator")
|
||||
new_contents = list(iterator)
|
||||
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()
|
||||
# like this, the internal methods of the SteamValue data type can work on the single elements
|
||||
for content in new_contents:
|
||||
# logger.debug(content)
|
||||
for content in cleaned_contents:
|
||||
self.contents.append(content)
|
||||
|
||||
# as an illustration
|
||||
|
|
|
|||
Loading…
Reference in New Issue