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)
|
# logger.debug(block)
|
||||||
if content_type == "assignment":
|
if content_type == "assignment":
|
||||||
assignment = value.get("assignment_id")
|
assignment = value.get("assignment_id")
|
||||||
|
if assignment is None:
|
||||||
|
return None
|
||||||
# copy the assignment
|
# copy the assignment
|
||||||
assignment.pk = None
|
assignment.pk = None
|
||||||
assignment.title = f"{assignment.title} (Kopie)"
|
assignment.title = f"{assignment.title} (Kopie)"
|
||||||
|
|
@ -56,6 +58,8 @@ def duplicate_entities_generator(new_module):
|
||||||
if content_type == "survey":
|
if content_type == "survey":
|
||||||
# logger.debug(value)
|
# logger.debug(value)
|
||||||
survey = value.get("survey_id")
|
survey = value.get("survey_id")
|
||||||
|
if survey is None:
|
||||||
|
return None
|
||||||
# copy the survey
|
# copy the survey
|
||||||
survey.pk = None
|
survey.pk = None
|
||||||
survey.title = f"{survey.title} (Kopie)"
|
survey.title = f"{survey.title} (Kopie)"
|
||||||
|
|
@ -165,13 +169,13 @@ class ContentBlock(StrictHierarchyPage, GraphqlNodeMixin):
|
||||||
iterator = map(duplicate_entities, self.contents)
|
iterator = map(duplicate_entities, self.contents)
|
||||||
# logger.debug("here is the iterator")
|
# logger.debug("here is the iterator")
|
||||||
new_contents = list(iterator)
|
new_contents = list(iterator)
|
||||||
|
cleaned_contents = [item for item in new_contents if item is not None]
|
||||||
# logger.debug(new_contents)
|
# logger.debug(new_contents)
|
||||||
# we can't just insert a list here, we need a StreamValue data type
|
# 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
|
# so we need to clear the list, then add each element in turn
|
||||||
self.contents.clear()
|
self.contents.clear()
|
||||||
# like this, the internal methods of the SteamValue data type can work on the single elements
|
# like this, the internal methods of the SteamValue data type can work on the single elements
|
||||||
for content in new_contents:
|
for content in cleaned_contents:
|
||||||
# logger.debug(content)
|
|
||||||
self.contents.append(content)
|
self.contents.append(content)
|
||||||
|
|
||||||
# as an illustration
|
# as an illustration
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue