Add comment to the Link class, move remove_from_query inside keep_query, doesn't make sense to have it outside this context
This commit is contained in:
@@ -142,16 +142,15 @@ class Link(object):
|
|||||||
query_string = urlparse.urlparse(previous_path).query
|
query_string = urlparse.urlparse(previous_path).query
|
||||||
parsed_query_string = urlparse.parse_qs(query_string)
|
parsed_query_string = urlparse.parse_qs(query_string)
|
||||||
|
|
||||||
for key in self.remove_from_query:
|
# If this link has a required permission check that the user have it
|
||||||
try:
|
# too
|
||||||
del parsed_query_string[key]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if self.permissions:
|
if self.permissions:
|
||||||
try:
|
try:
|
||||||
Permission.objects.check_permissions(request.user, self.permissions)
|
Permission.objects.check_permissions(request.user, self.permissions)
|
||||||
except PermissionDenied:
|
except PermissionDenied:
|
||||||
|
# If the user doesn't have the permission, and we are passed
|
||||||
|
# an instance, check to see if the user has at least ACL
|
||||||
|
# access to the instance.
|
||||||
if resolved_object:
|
if resolved_object:
|
||||||
try:
|
try:
|
||||||
AccessEntry.objects.check_access(self.permissions, request.user, resolved_object)
|
AccessEntry.objects.check_access(self.permissions, request.user, resolved_object)
|
||||||
@@ -160,7 +159,9 @@ class Link(object):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Check to see if link has conditional display
|
# Check to see if link has conditional display function and only
|
||||||
|
# display it if the result of the conditional display function is
|
||||||
|
# True
|
||||||
if self.condition:
|
if self.condition:
|
||||||
if not self.condition(context):
|
if not self.condition(context):
|
||||||
return None
|
return None
|
||||||
@@ -179,21 +180,35 @@ class Link(object):
|
|||||||
|
|
||||||
kwargs = {key: Variable(value) for key, value in self.kwargs.iteritems()}
|
kwargs = {key: Variable(value) for key, value in self.kwargs.iteritems()}
|
||||||
|
|
||||||
|
# Use Django's exact {% url %} code to resolve the link
|
||||||
node = URLNode(view_name=view_name, args=args, kwargs={}, asvar=None)
|
node = URLNode(view_name=view_name, args=args, kwargs={}, asvar=None)
|
||||||
|
|
||||||
|
# If we were passed an instance of the view context object we are
|
||||||
|
# resolving, inject it into the context. This help resolve links for
|
||||||
|
# object lists.
|
||||||
if resolved_object:
|
if resolved_object:
|
||||||
context['resolved_object'] = resolved_object
|
context['resolved_object'] = resolved_object
|
||||||
|
|
||||||
resolved_link.url = node.render(context)
|
resolved_link.url = node.render(context)
|
||||||
|
|
||||||
|
# This is for links that should be displayed but that are not clickable
|
||||||
if self.conditional_disable:
|
if self.conditional_disable:
|
||||||
resolved_link.disabled = self.conditional_disable(context)
|
resolved_link.disabled = self.conditional_disable(context)
|
||||||
else:
|
else:
|
||||||
resolved_link.disabled = False
|
resolved_link.disabled = False
|
||||||
|
|
||||||
|
# Lets a new link keep the same URL query string of the current URL
|
||||||
if self.keep_query:
|
if self.keep_query:
|
||||||
|
# Sometimes we are required to remove a key from the URL QS
|
||||||
|
for key in self.remove_from_query:
|
||||||
|
try:
|
||||||
|
del parsed_query_string[key]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
resolved_link.url = '%s?%s' % (urlquote(resolved_link.url), urlencode(parsed_query_string, doseq=True))
|
resolved_link.url = '%s?%s' % (urlquote(resolved_link.url), urlencode(parsed_query_string, doseq=True))
|
||||||
|
|
||||||
|
# Helps highligh in the UI the current link in effect
|
||||||
resolved_link.active = self.view == current_view
|
resolved_link.active = self.view == current_view
|
||||||
|
|
||||||
return resolved_link
|
return resolved_link
|
||||||
|
|||||||
Reference in New Issue
Block a user