Skip to content

Commit

Permalink
Added options to URL diff without GET params.
Browse files Browse the repository at this point in the history
  • Loading branch information
flaiming committed Dec 11, 2014
1 parent 22f0a7b commit 6b6bc4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions django_activeurl/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ class ActiveUrlConf(AppConf):
'menu': 'yes'
}

# check url without GET parameters
WITHOUT_GET_PARAMS = True

class Meta:
prefix = 'active_url'
8 changes: 8 additions & 0 deletions django_activeurl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def get_cache_key(content, css_class, parent_tag, full_path, menu):

def check_active(url, element, full_path, css_class, menu):
'''check "active" url, apply css_class'''

if settings.ACTIVE_URL_WITHOUT_GET_PARAMS:
# cut off GET params
full_path = re.sub(r'\?.+', '', full_path)

# django > 1.5 template boolean\None variables feature
if isinstance(menu, bool):
if menu:
Expand All @@ -77,6 +82,9 @@ def check_active(url, element, full_path, css_class, menu):
href = url.attrib['href'].strip()
# cut off hashtag (anchor)
href = re.sub(r'\#.+', '', href)
if settings.ACTIVE_URL_WITHOUT_GET_PARAMS:
# cut off GET params
href = re.sub(r'\?.+', '', href)
# check empty href
if href == '':
# replace href with current location
Expand Down

1 comment on commit 6b6bc4d

@hellysmile
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I have ideas about this feature on my roadmap

hellysmile#9

Any plans about pull request + tests?

What about replace regex with https://docs.python.org/2/library/urlparse.html ?

Please sign in to comment.