shimatta-kenkyusho/shimatta_kenkyusho/parts/navbar.py

75 lines
2.0 KiB
Python
Raw Permalink Normal View History

from django.urls import reverse
from django.conf import settings
class BsNavBarItem():
link = ''
name = ''
active = True
def __init__(self, name, link, active):
self.link = link
self.name = name
self.active = active
def active_class(self):
if self.active:
return "active"
else:
return ""
def __str__(self):
return self.name
class NavBar():
brand = ''
navitems = []
has_user = False
username = ''
show_admin = False
@staticmethod
def get_navbar(active_entry, user = None):
items = {
'Main': BsNavBarItem('Main', reverse('parts-main'), False),
2021-08-07 17:37:36 +02:00
'Components':BsNavBarItem('Components', reverse('parts-components'), False),
'Packages': BsNavBarItem('Packages', reverse('parts-packages'), False),
2021-08-07 17:37:36 +02:00
'Stocks':BsNavBarItem('Stocks', reverse('parts-stocks'), False),
'Distributors':BsNavBarItem('Distributors', reverse('parts-distributors'), False),
'Manufacturers':BsNavBarItem('Manufacturers', reverse('parts-manufacturers'), False),
}
try:
items[active_entry].active = True
except:
pass
navitems = [
items['Main'],
items['Components'],
items['Packages'],
items['Stocks'],
items['Distributors'],
items['Manufacturers'],
#items['Login'],
]
nb = NavBar()
nb.has_user = False
nb.show_admin = False
if user is not None:
if user.is_authenticated:
nb.has_user = True
nb.username = user.username
if user.is_superuser:
nb.show_admin = True
nb.navitems = navitems
nb.brand = NavBar.get_brand()
return nb
@staticmethod
def get_brand():
return getattr(settings, "SHIMATTA_KENKYUSHO_TITLE", 'Lab System')