forked from django-oscar/django-oscar
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
111 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from django.core.urlresolvers import reverse | ||
|
||
_nodes = [] | ||
|
||
|
||
class Node(object): | ||
|
||
def __init__(self, label, url_name=None, url_args=None, url_kwargs=None, access_fn=None): | ||
self.label = label | ||
self.url_name = url_name | ||
self.url_args = url_args | ||
self.url_kwargs = url_kwargs | ||
self.access_fn = access_fn | ||
self.children = [] | ||
|
||
@property | ||
def is_heading(self): | ||
return self.url_name is None | ||
|
||
@property | ||
def url(self): | ||
return reverse(self.url_name, args=self.url_args, kwargs=self.url_kwargs) | ||
|
||
def add_child(self, node): | ||
self.children.append(node) | ||
|
||
def is_visible(self, user): | ||
if not self.access_fn: | ||
return True | ||
return self.access_fn(user) | ||
|
||
def filter(self, user): | ||
if not self.is_visible(user): | ||
return None | ||
node = Node(self.label, self.url_name, self.access_fn) | ||
for child in self.children: | ||
if child.is_visible(node): | ||
node.add_child(child) | ||
return node | ||
|
||
def has_children(self): | ||
return len(self.children) > 0 | ||
|
||
def register(node): | ||
_nodes.append(node) | ||
|
||
def flush(): | ||
_nodes = [] | ||
|
||
def get_nodes(user): | ||
nodes = [] | ||
for node in _nodes: | ||
filtered_node = node.filter(user) | ||
if filtered_node: | ||
nodes.append(node) | ||
return nodes | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters