2024-11-18 09:49:04 +00:00
|
|
|
from django.template.loader import render_to_string
|
|
|
|
|
|
|
|
|
2021-10-24 14:51:04 +00:00
|
|
|
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)
|
|
|
|
|
2021-10-24 15:35:52 +00:00
|
|
|
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:
|
2024-11-18 09:49:04 +00:00
|
|
|
html += (
|
|
|
|
"""
|
2021-10-24 15:35:52 +00:00
|
|
|
<!-- Nav Item -->
|
2024-11-18 09:49:04 +00:00
|
|
|
<li class="nav-item"""
|
|
|
|
+ (" active" if item.name == active else "")
|
|
|
|
+ f"""">
|
2021-10-24 15:35:52 +00:00
|
|
|
<a class="nav-link" href="{item.url}">
|
|
|
|
<i class="{item.icon}"></i>
|
|
|
|
<span>{item.name}</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
"""
|
2024-11-18 09:49:04 +00:00
|
|
|
)
|
2021-10-24 15:35:52 +00:00
|
|
|
|
|
|
|
return html
|
2021-10-24 14:51:12 +00:00
|
|
|
|
2024-11-18 09:49:04 +00:00
|
|
|
|
2021-10-24 14:51:04 +00:00
|
|
|
class NavItem:
|
2021-10-24 15:35:52 +00:00
|
|
|
def __init__(self, name, url, icon="fas fa-fw fa-smile", title=None, order=100):
|
2021-10-24 14:51:04 +00:00
|
|
|
self.name = name
|
|
|
|
self.url = url
|
|
|
|
self.icon = icon
|
2021-10-24 15:35:52 +00:00
|
|
|
self.title = title or name
|
2024-11-18 09:49:04 +00:00
|
|
|
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)
|