Skip to content

Commit

Permalink
Optionally consider query string and do not use url_for when
Browse files Browse the repository at this point in the history
determining whether or not a view is active.
  • Loading branch information
mbr committed Nov 23, 2016
1 parent 4b65aa5 commit 2dadd3d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions flask_nav/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, content, **attribs):


class View(Link):
ignore_query = True
"""Application-internal link.
The ``endpoint``, ``*args`` and ``**kwargs`` are passed on to
Expand All @@ -72,9 +73,22 @@ def get_url(self):

@property
def active(self):
# this is a better check than checking for request.endpoint
# because it takes arguments to the view into account
return request.path == self.get_url()
if not request.endpoint == self.endpoint:
return False

# rebuild the url and compare results. we can't rely on using get_url()
# because whether or not an external url is created depends on factors
# outside our control

_, url = request.url_rule.build(self.url_for_kwargs,
append_unknown=not self.ignore_query)

if self.ignore_query:
return url == request.path

# take query string into account.
# FIXME: ensure that the order of query parameters is consistent
return url == request.full_path


class Separator(NavigationItem):
Expand Down

0 comments on commit 2dadd3d

Please sign in to comment.