Skip to content
This repository
file 72 lines (55 sloc) 1.824 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72


class Menu(object):
    nodes = []

    def get_nodes(self, request):
        raise NotImplementedError
    
    def get_node_by_id(self, id):
        for node in self.nodes:
            if node.id == id:
                return node
    
class Modifier(object):
    pre_cut = True
    post_cut = False
    
    def set_nodes(self, nodes):
        self.nodes = nodes
    
    def modify(self, request, nodes, namespace, post_cut):
        pass
    
    def modify_all(self, request, nodes, namespace, post_cut):
        pass
    
    def remove_node(self, node):
        self.nodes.remove(node)
        if node.parent:
            node.parent.children.remove(node)
    
class NavigationNode(object):
    title = None
    url = None
    auth_required = False
    required_group_id = None
    attr = {}
    namespace = None
    id = None
    softroot = False
    parent_id = None
    parent_namespace = None
    parent = None # do not touch
   
    selected = False
    
    def __init__(self, title, url, namespace, id, parent_id=None, parent_namespace=None, attr=None, softroot=False, auth_required=False, required_group_id=None):
        self.children = [] # do not touch
        self.title = title
        self.url = url
        self.id = id
        self.softroot = softroot
        self.namespace = namespace
        self.parent_id = parent_id
        self.parent_namespace = parent_namespace
        self.auth_required = auth_required
        self.required_group_id = required_group_id
        if attr:
            self.attr = attr
            
    def __repr__(self):
        return "<Navigation Node: %s>" % self.title
    
    def get_menu_title(self):
        return self.title
    
    def get_absolute_url(self):
        return self.url
    
    def get_attribute(self, name):
        return self.attr[name]
    
Something went wrong with that request. Please try again.