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), 'Components':BsNavBarItem('Components', reverse('parts-components'), False), 'Stocks':BsNavBarItem('Stocks', reverse('parts-stocks'), False), } try: items[active_entry].active = True except: pass navitems = [ items['Main'], items['Components'], items['Stocks'], #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')