kumify/frontend/classes.py
Kumi 5c7586bb9a
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.
2024-11-18 10:49:04 +01:00

55 lines
1.4 KiB
Python

from django.template.loader import render_to_string
class NavSection:
def __init__(self, name, order=100):
self.name = name
self.order = order
self.items = []
def add_item(self, item):
self.items.append(item)
def get_html(self, active=None):
html = f"""
<!-- Heading -->
<div class="sidebar-heading">{self.name}</div>
"""
self.items.sort(key=lambda x: x.order)
for item in self.items:
html += (
"""
<!-- Nav Item -->
<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
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)