From 916e8aa7d16a71c7601d30f57e30c85204a99950 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 24 Oct 2021 17:35:52 +0200 Subject: [PATCH] Try implementing sidebar generation --- frontend/classes.py | 27 +++++++++-- frontend/features.py | 29 +++++++++++ frontend/templatetags/navigation.py | 75 ++--------------------------- 3 files changed, 57 insertions(+), 74 deletions(-) diff --git a/frontend/classes.py b/frontend/classes.py index b1adb1c..d614155 100644 --- a/frontend/classes.py +++ b/frontend/classes.py @@ -7,12 +7,31 @@ class NavSection: def add_item(self, item): self.items.append(item) - def get_html(self): - pass + def get_html(self, active=None): + html = f""" + + + """ + + self.items.sort(key=lambda x: x.order) + + for item in self.items: + html += f""" + + + """ + + return html class NavItem: - def __init__(self, name, url, icon="fas fa-fw fa-smile", title=None): + def __init__(self, name, url, icon="fas fa-fw fa-smile", title=None, order=100): self.name = name self.url = url self.icon = icon - self.title = title or name \ No newline at end of file + self.title = title or name + self.order = order \ No newline at end of file diff --git a/frontend/features.py b/frontend/features.py index e69de29..32b4990 100644 --- a/frontend/features.py +++ b/frontend/features.py @@ -0,0 +1,29 @@ +from frontend.classes import NavSection, NavItem + +from django.urls import reverse_lazy + +mood_section = NavSection("Mood") + +mood_items = { + "mood_status_list": NavItem("Status List", reverse_lazy("mood:status_list")), + "mood_activity_list": NavItem("Activities", reverse_lazy("mood:activity_list")), + "mood_mood_list": NavItem("Moods", reverse_lazy("mood:mood_list")), + "mood_notification_list": NavItem("Notifications", reverse_lazy("mood:notification_list")), + "mood_statistics": NavItem("Statistics", reverse_lazy("mood:statistics")) +} + +for _, item in mood_items.items(): + mood_section.add_item(item) + +dreams_section = NavSection("Dreams") + +dreams_items = { + "dreams_dream_list": NavItem("Dream List", reverse_lazy("dreams:dream_list")), + "dreams_theme_list": NavItem("Themes", reverse_lazy("dreams:theme_list")), + "dreams_notification_list": NavItem("Notifications", reverse_lazy("dreams:notification_list")) +} + +for _, item in dreams_items.items(): + dreams_section.add_item(item) + +NAV_SECTIONS = [mood_section, dreams_section] \ No newline at end of file diff --git a/frontend/templatetags/navigation.py b/frontend/templatetags/navigation.py index c6406e5..15505da 100644 --- a/frontend/templatetags/navigation.py +++ b/frontend/templatetags/navigation.py @@ -12,6 +12,10 @@ def sidebar_nav(): for module in settings.CORE_MODULES + settings.ENABLED_MODULES: try: features = import_module(f"{module}.features") + try: + sections += features.NAV_SECTIONS + except: + pass except: pass @@ -24,73 +28,4 @@ def sidebar_nav(): - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - """ \ No newline at end of file + """ + section.get_html() for section in sections \ No newline at end of file