81 lines
No EOL
2 KiB
Python
81 lines
No EOL
2 KiB
Python
from django.urls import reverse
|
|
|
|
class NavItem:
|
|
def __init__(self, name: str, icon: str, path: str, permissions: list=[]):
|
|
self.__name = name
|
|
self.__icon = icon
|
|
self.__path = path
|
|
self.__permissions = permissions
|
|
|
|
@property
|
|
def name(self):
|
|
return self.__name
|
|
|
|
@property
|
|
def icon(self):
|
|
return self.__icon
|
|
|
|
@property
|
|
def path(self):
|
|
return self.__path if (self.__path.startswith("/") or "://" in self.__path) else reverse(self.__path)
|
|
|
|
@property
|
|
def permissions(self):
|
|
return self.__permissions
|
|
|
|
class NavSection:
|
|
def __init__(self, name: str, icon: str = "", permissions: list=[]):
|
|
self.__items = []
|
|
self.__name = name
|
|
self.__icon = icon
|
|
self.__permissions = permissions
|
|
|
|
@property
|
|
def name(self):
|
|
return self.__name
|
|
|
|
@property
|
|
def icon(self):
|
|
return self.__icon
|
|
|
|
@property
|
|
def permissions(self):
|
|
return self.__permissions
|
|
|
|
def add_item(self, item: NavItem):
|
|
if not item in self.__items:
|
|
self.__items.append(item)
|
|
|
|
def del_item(self, item: NavItem):
|
|
while item in self.__items:
|
|
self.__items.remove(item)
|
|
|
|
def del_item_by_name(self, name: str):
|
|
for item in self.__items:
|
|
if item.name == name:
|
|
del(item)
|
|
|
|
@property
|
|
def items(self):
|
|
return self.__items
|
|
|
|
class Navigation:
|
|
def __init__(self):
|
|
self.__sections = []
|
|
|
|
def add_section(self, section: NavSection):
|
|
if not section in self.__sections:
|
|
self.__sections.append(section)
|
|
|
|
def del_section(self, section: NavSection):
|
|
while section in self.__sections:
|
|
self.__sections.remove(section)
|
|
|
|
def del_section_by_name(self, name: str):
|
|
for section in self.__sections:
|
|
if section.name == name:
|
|
del(section)
|
|
|
|
@property
|
|
def sections(self):
|
|
return self.__sections |