Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions menu/migrations/0003_add_staff_required.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('menu', '0001_initial'),
('menu', '0002_booleandefaults'),
]

operations = [
migrations.AddField(
model_name='menuitem',
name='staff_required',
field=models.BooleanField(default=False, help_text='Should this item only be shown to members of staff?', verbose_name='Staff required'),
),
]
7 changes: 7 additions & 0 deletions menu/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ class MenuItem(models.Model):
help_text=_(u'Should this item only be shown to authenticated users?')
)

staff_required = models.BooleanField(
_(u'Staff required'),
blank=True,
default=False,
help_text=_(u'Should this item only be shown to members of staff?')
)

anonymous_only = models.BooleanField(
_(u'Anonymous only'),
blank=True,
Expand Down
7 changes: 5 additions & 2 deletions menu/templatetags/menubuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ def get_items(menu_name, current_path, user):

if user:
is_authenticated = user.is_authenticated
is_staff = user.is_staff
is_anonymous = user.is_anonymous
else:
is_authenticated = False
is_staff = False
is_anonymous = True

if cache_time >= 0 and not debug:
cache_key = 'django-menu-items/%s/%s/%s' % (menu_name, current_path, is_authenticated)
cache_key = 'django-menu-items/%s/%s/%s/%s' % (menu_name, current_path, is_authenticated, is_staff)
menuitems = cache.get(cache_key, [])
if menuitems:
return menuitems
Expand All @@ -102,7 +104,8 @@ def get_items(menu_name, current_path, user):

show_anonymous = i.anonymous_only and is_anonymous
show_auth = i.login_required and is_authenticated
if (not (i.login_required or i.anonymous_only)) or (i.login_required and show_auth) or (i.anonymous_only and show_anonymous):
show_staff = i.staff_required and is_staff
if (not (i.login_required or i.anonymous_only or i.staff_required)) or (i.login_required and show_auth) or (i.anonymous_only and show_anonymous) or (i.staff_required and show_staff == True):
menuitems.append({'url': i.link_url, 'title': i.title, 'current': current,})

if cache_time >= 0 and not debug:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fnmatch import fnmatchcase
from setuptools import setup, find_packages

version = '0.1.10'
version = '0.1.11'

# Provided as an attribute, so you can append to these instead
# of replicating them:
Expand Down