Skip to content

Commit 13e9bde

Browse files
author
Michael Angeletti
committed
Removed menu item registration requirement
1 parent 2344097 commit 13e9bde

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ links (or whose parents are active) for Django 1.5+
77
Usage
88
-----
99

10-
Firstly, add `'active_menu'` to `settings.INSTALLED_APPS`. Don't worry, there
11-
are no models included with Active Menu. This simply allows you to use
12-
`{% load active_menu_tags %}` in your templates.
10+
Optionally, add `'active_menu'` to `settings.INSTALLED_APPS`. This isn't required,
11+
and there are no models included in Active Menu. This simply allows you to use
12+
`{% load active_menu_tags %}` in your templates. You can use instead use
13+
`add_to_builtins('active_menu.templatetags.active_menu_tags')`, if desired.
1314

1415
```python
1516
# urls.py (or anywhere where they'll be run before your views are called)
@@ -58,6 +59,8 @@ nor the `account` menu items are active, using the above example.
5859
</p>
5960
```
6061

62+
### Pro Tip
63+
6164
If you don't care about nesting, but you want the tag to add the active class
6265
when a view name matches the *current * request's view name, you can skip the
6366
registration step.

active_menu/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from active_menu.utils import isactive, menu_item
22

33

4-
VERSION = (0, 9, 2)
4+
VERSION = (0, 9, 3)

active_menu/menu.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,22 @@ def isactive(self, request, view_name):
7373
Returns whether the menu item represented by the provided view name or
7474
any of its parent menu items represent the provided request's view.
7575
"""
76-
# Get the menu item for the provided view name
77-
menu_item = self.get_item(view_name)
78-
7976
# Get the provided request's view name
8077
request_view_name = request.resolver_match.view_name
8178

79+
# Return True, if the view name matches the request's view name
80+
if view_name == request_view_name:
81+
return True
82+
83+
# Get the menu item for the provided view name
84+
menu_item = self.get_item(view_name)
85+
8286
# Get the provided request's menu item or return False
8387
try:
8488
request_menu_item = self.get_item(request_view_name)
8589
except MenuError:
8690
return False
8791

88-
# Return True, if the view name matches the request's view name
89-
if view_name == request_view_name:
90-
return True
91-
9292
# Return whether the menu item matching the provided view name is in
9393
# the list of ancestors of the provided request's menu item
9494
return menu_item in self.get_ancesters(request_menu_item)

0 commit comments

Comments
 (0)