Source code for superdjango.ui.runtime.menus

# Classes


[docs]class Location(object): """A location of menus and their items for use in templates."""
[docs] def __init__(self, name, sort_order=1): """Initialize a menu location. :param name: The location name. :type name: str :param sort_order: The order in which the location appears next to other locations. :type sort_order: str """ self.items = list() self.name = name self.sort_order = sort_order
def __iter__(self): return iter(self.items) def __repr__(self): return "<%s:Runtime %s. %s (%s)>" % (self.__class__.__name__, self.sort_order, self.name, len(self.items))
[docs] def append(self, item): """Add a menu or item to the location. :param item: The item to be added. :type item: Item | Menu """ self.items.append(item)
[docs]class Item(object): """An individual menu item. .. note:: This class is typically used in situations where a registered menu item contains only one model. """
[docs] def __init__(self, label, name, icon=None, sort_order=1, url=None, **kwargs): """Initialize an item. :param label: The label of the menu item as shown to users. :type label: str :param name: The programmatic name of the item. :type name: str :param icon: The icon to display as part of the item label. :type icon: str :param sort_order: The sort order of the item within a menu. :type sort_order: int :param url: The URL of the item. :type url: str Additional kwargs are available as properties of the item instance. """ self.icon = icon self.items = None self.label = label self.name = name self.sort_order = sort_order self.url = url self._kwargs = kwargs
def __getattr__(self, item): return self._kwargs.get(item) def __repr__(self): return "<%s:Runtime %s. %s (%s)>" % (self.__class__.__name__, self.sort_order, self.name, self.label) @property def is_separator(self): """Runtime item instances are never used as separators. :rtype: bool """ return False