diff --git a/menu/migrations/0003_add_staff_required.py b/menu/migrations/0003_add_staff_required.py new file mode 100644 index 0000000..7a600f8 --- /dev/null +++ b/menu/migrations/0003_add_staff_required.py @@ -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'), + ), + ] diff --git a/menu/models.py b/menu/models.py index 4117ba6..ab91f4b 100644 --- a/menu/models.py +++ b/menu/models.py @@ -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, diff --git a/menu/templatetags/menubuilder.py b/menu/templatetags/menubuilder.py index 96fdb75..af412d7 100644 --- a/menu/templatetags/menubuilder.py +++ b/menu/templatetags/menubuilder.py @@ -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 @@ -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: diff --git a/setup.py b/setup.py index ffce182..35abaf6 100644 --- a/setup.py +++ b/setup.py @@ -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: