Add circle title to assignment in wagtail cms view

This commit is contained in:
Daniel Egger 2023-09-06 15:16:51 +02:00
parent aabaced836
commit 7597311220
2 changed files with 24 additions and 0 deletions

View File

@ -127,6 +127,12 @@ class Assignment(CourseBasePage):
"evaluation_tasks",
]
def get_admin_display_title(self):
circle_title = self.get_attached_circle_title()
if circle_title:
return f"{circle_title}: {self.title}"
return self.title
assignment_type = models.CharField(
max_length=50,
choices=[(tag.value, tag.value) for tag in AssignmentType],
@ -271,6 +277,16 @@ class Assignment(CourseBasePage):
return lp.get_frontend_url()
return ""
def get_attached_circle_title(self):
if self.learningcontentassignment_set.count() > 1:
# probably "Reflexion" which is attached to multiple circles
return ""
lp = self.find_attached_learning_content()
if lp and lp.get_parent_circle():
return lp.get_parent_circle().title
return ""
class AssignmentCompletionStatus(Enum):
IN_PROGRESS = "IN_PROGRESS"

View File

@ -277,6 +277,14 @@ class LearningContent(CourseBasePage):
return "ERROR: could not parse slug"
return f"/course/{m.group('coursePart')}/learn/{m.group('circlePart')}/{m.group('lcPart')}"
def get_parent_circle(self):
try:
return self.get_ancestors().exact_type(Circle).first()
except Exception:
# noop
pass
return None
def save(self, clean=True, user=None, log_action=False, **kwargs):
self.slug = find_slug_with_parent_prefix(self, "lc")
super().save(**kwargs)