From 2e59d2464c86ca02b56fe9b0b944696199221e82 Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Fri, 2 Sep 2022 17:42:14 +0200 Subject: [PATCH] Add parent prefix to slugs --- client/src/components/MainNavigationBar.vue | 2 +- .../components/circle/LearningPathDiagram.vue | 2 +- client/src/stores/circle.ts | 4 +++- server/config/settings/base.py | 1 - server/vbv_lernwelt/learnpath/models.py | 23 +++++++++++++------ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/client/src/components/MainNavigationBar.vue b/client/src/components/MainNavigationBar.vue index b7823864..b4400703 100644 --- a/client/src/components/MainNavigationBar.vue +++ b/client/src/components/MainNavigationBar.vue @@ -141,7 +141,7 @@ const profileDropdownData = [ > diff --git a/client/src/components/circle/LearningPathDiagram.vue b/client/src/components/circle/LearningPathDiagram.vue index 8b9c6d44..aea2502a 100644 --- a/client/src/components/circle/LearningPathDiagram.vue +++ b/client/src/components/circle/LearningPathDiagram.vue @@ -63,7 +63,7 @@ export default { const newCircle = {} newCircle.pieData = pieData.reverse() newCircle.title = circle.title - newCircle.slug = circle.slug + newCircle.slug = circle.slug.replace(`${circle.parentLearningPath.slug}-circle-`, '') newCircle.id = circle.id internalCircles.push(newCircle) }) diff --git a/client/src/stores/circle.ts b/client/src/stores/circle.ts index f729b2c9..387966fc 100644 --- a/client/src/stores/circle.ts +++ b/client/src/stores/circle.ts @@ -33,7 +33,9 @@ export const useCircleStore = defineStore({ const learningPathStore = useLearningPathStore(); await learningPathStore.loadLearningPath(learningPathSlug); if (learningPathStore.learningPath) { - this.circle = learningPathStore.learningPath.circles.find(circle => circle.slug === circleSlug); + this.circle = learningPathStore.learningPath.circles.find((circle) => { + return circle.slug.endsWith(circleSlug); + }); } if (!this.circle) { diff --git a/server/config/settings/base.py b/server/config/settings/base.py index 46b932d6..b76eb030 100644 --- a/server/config/settings/base.py +++ b/server/config/settings/base.py @@ -106,7 +106,6 @@ LOCAL_APPS = [ "vbv_lernwelt.learnpath", "vbv_lernwelt.completion", "vbv_lernwelt.media_library", - ] # https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS diff --git a/server/vbv_lernwelt/learnpath/models.py b/server/vbv_lernwelt/learnpath/models.py index 71cc5528..6e6a4d13 100644 --- a/server/vbv_lernwelt/learnpath/models.py +++ b/server/vbv_lernwelt/learnpath/models.py @@ -54,7 +54,7 @@ class Topic(Page): # subpage_types = ['learnpath.Circle'] def full_clean(self, *args, **kwargs): - self.slug = find_available_slug(slugify(f'topic-{self.title}', allow_unicode=True)) + self.slug = find_slug_with_parent_prefix(self, 'topic') super(Topic, self).full_clean(*args, **kwargs) @classmethod @@ -114,7 +114,7 @@ class Circle(Page): ) def full_clean(self, *args, **kwargs): - self.slug = find_available_slug(slugify(self.title, allow_unicode=True)) + self.slug = find_slug_with_parent_prefix(self, 'circle') super(Circle, self).full_clean(*args, **kwargs) class Meta: @@ -155,7 +155,7 @@ class LearningSequence(Page): ''' def full_clean(self, *args, **kwargs): - self.slug = find_available_slug(slugify(f'ls-{self.title}', allow_unicode=True)) + self.slug = find_slug_with_parent_prefix(self, 'ls') super(LearningSequence, self).full_clean(*args, **kwargs) @@ -170,7 +170,7 @@ class LearningUnit(Page): return f"{self.title}" def full_clean(self, *args, **kwargs): - self.slug = find_available_slug(slugify(f'lu-{self.title}', allow_unicode=True)) + self.slug = find_slug_with_parent_prefix(self, 'lu') super(LearningUnit, self).full_clean(*args, **kwargs) @classmethod @@ -192,7 +192,7 @@ class LearningUnitQuestion(Page): return f"{self.title}" def full_clean(self, *args, **kwargs): - self.slug = find_available_slug(slugify(f'luq-{self.title}', allow_unicode=True)) + self.slug = find_slug_with_parent_prefix(self, 'luq') super(LearningUnitQuestion, self).full_clean(*args, **kwargs) @classmethod @@ -247,8 +247,7 @@ class LearningContent(Page): verbose_name = "Learning Content" def full_clean(self, *args, **kwargs): - self.slug = find_available_slug(slugify(f'lc-{self.title}', allow_unicode=True)) - print(self.slug) + self.slug = find_slug_with_parent_prefix(self, 'lc') super(LearningContent, self).full_clean(*args, **kwargs) @classmethod @@ -261,6 +260,16 @@ class LearningContent(Page): return f"{self.title}" +def find_slug_with_parent_prefix(page, type_prefix): + parent_slug = page.get_ancestors().exact_type(LearningPath, Circle).last().slug + if parent_slug: + slug_prefix = f"{parent_slug}-{type_prefix}" + else: + slug_prefix = type_prefix + + return find_available_slug(slugify(f'{slug_prefix}-{page.title}', allow_unicode=True)) + + def find_available_slug(requested_slug, ignore_page_id=None): """ Finds an available slug within the specified parent.