feat: Modularizes dashboard structure

Introduces DashboardSection class to encapsulate dashboard logic,
enabling easier extension and customization. Adds separate mood
and dreams dashboard templates to streamline content rendering.

Refactors main dashboard template to dynamically render content
from enabled modules using a new template tag system, improving
flexibility and maintainability.
This commit is contained in:
Kumi 2024-11-18 10:49:04 +01:00
parent 3c3cfc38ba
commit 5c7586bb9a
Signed by: kumi
GPG key ID: ECBCC9082395383F
7 changed files with 254 additions and 185 deletions

View file

@ -1,3 +1,6 @@
from django.template.loader import render_to_string
class NavSection:
def __init__(self, name, order=100):
self.name = name
@ -16,22 +19,37 @@ class NavSection:
self.items.sort(key=lambda x: x.order)
for item in self.items:
html += """
html += (
"""
<!-- Nav Item -->
<li class="nav-item""" + (" active" if item.name == active else "") + f"""">
<li class="nav-item"""
+ (" active" if item.name == active else "")
+ f"""">
<a class="nav-link" href="{item.url}">
<i class="{item.icon}"></i>
<span>{item.name}</span>
</a>
</li>
"""
)
return html
class NavItem:
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
self.order = order
self.order = order
class DashboardSection:
def __init__(self, name, template, context=None):
self.name = name
self.template = template
self.context = context or {}
def get_html(self, request):
return render_to_string(self.template, self.context, request)