Source code for superdjango.ui.runtime.actions

# Exports

__all__ = (
    "Action",
)

# Classes


[docs]class Action(object): """Represents a specific instance of an action definition."""
[docs] def __init__(self, label, url, verb, icon=None, is_ajax=None, is_divider=None, is_primary=False, modal=False, target=None): """Initialize an action. :param label: The label of the action to be displayed to users. :type label: str :param url: The URL of the action. :type url: str :param verb: The verb which the action represents. :type verb: str :param icon: The icon to use for the action. :type icon: str :param is_ajax: Indicates the action is handled via an AJAX call. :type is_ajax: bool :param is_divider: Indicates the action is a divider. :type is_divider: bool :param is_primary: Indicates this is the primary action when included in a group of actions. :type is_primary: bool :param modal: Indicates the action triggers a modal window. :type modal: bool :param target: The link target of the action. :type target: str """ self.icon = icon self.is_ajax = is_ajax self.is_divider = is_divider self.is_primary = is_primary self.label = label self.modal = modal self.target = target self.url = url self.verb = verb
def __repr__(self): return "<Runtime %s %s>" % (self.__class__.__name__, self.label)
class Actions(object): """A collection of runtime action instances.""" def __init__(self, *actions, enabled=True, label=None, location=None): """Initialize the actions. :param items: A list of runtime action instances names to be included in the set. :type items: list[Action] :param enabled: Indicates the actions are available to users. This may be toggled programmatically. :type enabled: bool :param label: The label for this group of actions. Defaults to ``_("Actions")`` but may be disabled by passing an empty string. :type label: str :param location: The desired location of the actions. :type location: str """ self.enabled = enabled self.items = list(actions) self.label = label self.location = location def __iter__(self): return iter(self.items) def __len__(self): return len(self.items) def __repr__(self): return "<Runtime %s (%s)>" % (self.__class__.__name__, len(self.items)) def append(self, instance): """Append an action instance to the set. :param instance: The action instance. :type instance: Action """ self.items.append(instance) @property def count(self): return len(self.items) @property def first(self): return self.items[0]