expephalon/core/classes/navigation.py

81 lines
2 KiB
Python
Raw Normal View History

from django.urls import reverse
class NavItem:
2020-06-03 15:05:18 +00:00
def __init__(self, name: str, icon: str, path: str, permissions: list=[]):
self.__name = name
self.__icon = icon
self.__path = path
2020-06-03 15:05:18 +00:00
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)
2020-06-03 15:05:18 +00:00
@property
def permissions(self):
return self.__permissions
class NavSection:
2020-06-03 15:05:18 +00:00
def __init__(self, name: str, icon: str = "", permissions: list=[]):
self.__items = []
self.__name = name
self.__icon = icon
2020-06-03 15:05:18 +00:00
self.__permissions = permissions
@property
def name(self):
return self.__name
@property
def icon(self):
return self.__icon
2020-06-03 15:05:18 +00:00
@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