removed unused 'title' from subsubmenus

This commit is contained in:
fonfon 2014-12-15 15:54:40 +01:00
parent 61fefcff01
commit ae83566653
6 changed files with 25 additions and 46 deletions

View File

@ -34,11 +34,10 @@ from plinth import cfg
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
subsubmenu = {'title': _('PageKite'), subsubmenu = [{'url': reverse_lazy('pagekite:index'),
'items': [{'url': reverse_lazy('pagekite:index'), 'text': _('About PageKite')},
'text': _('About PageKite')}, {'url': reverse_lazy('pagekite:configure'),
{'url': reverse_lazy('pagekite:configure'), 'text': _('Configure PageKite')}]
'text': _('Configure PageKite')}]}
def init(): def init():
@ -194,7 +193,7 @@ def _apply_changes(request, old_status, new_status):
def _run(arguments, superuser=True): def _run(arguments, superuser=True):
"""Run an given command and raise exception if there was an error""" """Run a given command and raise exception if there was an error"""
command = 'pagekite-configure' command = 'pagekite-configure'
if superuser: if superuser:

View File

@ -28,18 +28,14 @@ from django.views.generic import ListView
from gettext import gettext as _ from gettext import gettext as _
# TODO: we do not use the title anymore, and 'items' is also a python keyword. subsubmenu = [{'url': reverse_lazy('users:index'),
# For all subsubmenus: let's remove title and just use the items list directly. 'text': _('Users')},
# Make sure to update the tests too. {'url': reverse_lazy('users:create'),
subsubmenu = {'title': _('Users and Groups'), 'text': _('Create User')}]
'items': [{'url': reverse_lazy('users:index'),
'text': _('Users')},
{'url': reverse_lazy('users:create'),
'text': _('Create User')}]}
class ContextMixin(object): class ContextMixin(object):
"""View to add 'subsubmenu' and 'title' to the context.""" """Mixin to add 'subsubmenu' and 'title' to the context."""
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
"""Use self.title and the module-level subsubmenu""" """Use self.title and the module-level subsubmenu"""
context = super(ContextMixin, self).get_context_data(**kwargs) context = super(ContextMixin, self).get_context_data(**kwargs)

View File

@ -30,23 +30,12 @@ from plinth import service
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
subsubmenu = { subsubmenu = [{'url': reverse_lazy('xmpp:index'),
'title': _('XMPP'), 'text': _('About')},
'items': [ {'url': reverse_lazy('xmpp:configure'),
{ 'text': _('Configure XMPP Server')},
'url': reverse_lazy('xmpp:index'), {'url': reverse_lazy('xmpp:register'),
'text': _('About'), 'text': _('Register XMPP Account')}]
},
{
'url': reverse_lazy('xmpp:configure'),
'text': _('Configure XMPP Server'),
},
{
'url': reverse_lazy('xmpp:register'),
'text': _('Register XMPP Account'),
}
]
}
def init(): def init():

View File

@ -18,7 +18,7 @@
{% endcomment %} {% endcomment %}
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
{% for urlitem in subsubmenu.items %} {% for urlitem in subsubmenu %}
<li {% if urlitem.active %} class="active"{% endif %} <li {% if urlitem.active %} class="active"{% endif %}
role="presentation"> role="presentation">
<a href="{{ urlitem.url }}">{{ urlitem.text }}</a> <a href="{{ urlitem.url }}">{{ urlitem.text }}</a>

View File

@ -25,9 +25,7 @@ def mark_active_menuitem(menu, path):
"""Mark the best-matching menu item with 'active' """Mark the best-matching menu item with 'active'
Input: a menu dict in the form of: Input: a menu dict in the form of:
{'title': 'foo menu', [{'url': '/path/to/choice1/', 'text': 'choice 1'}, {'url': ...}]
'items': [{'url': '/path/to/choice1/', 'text': 'choice 1'}, {'url': ...}]
}
URL paths are expected to end with a slash for matches to work properly. URL paths are expected to end with a slash for matches to work properly.
@ -39,7 +37,7 @@ def mark_active_menuitem(menu, path):
best_match = '' best_match = ''
best_match_item = None best_match_item = None
for urlitem in menu['items']: for urlitem in menu:
urlitem['active'] = False urlitem['active'] = False
if not path.startswith(str(urlitem['url'])): if not path.startswith(str(urlitem['url'])):
continue continue

View File

@ -24,7 +24,7 @@ class TestShowSubSubMenu(unittest.TestCase):
"""Verify that the highlighting of the subsubmenu is working correctly""" """Verify that the highlighting of the subsubmenu is working correctly"""
def assert_active_url(self, menu, url): def assert_active_url(self, menu, url):
"""Verify that only the given url is set as 'active' in the menu""" """Verify that only the given url is set as 'active' in the menu"""
for item in menu['items']: for item in menu:
if item['url'] == url: if item['url'] == url:
self.assertTrue(item['active']) self.assertTrue(item['active'])
else: else:
@ -32,17 +32,14 @@ class TestShowSubSubMenu(unittest.TestCase):
def _verify_active_menuitems(self, menu): def _verify_active_menuitems(self, menu):
"""Verify that one and only one menuitem is marked as active""" """Verify that one and only one menuitem is marked as active"""
return sum([item['active'] for item in menu['items']]) == 1 return sum([item['active'] for item in menu]) == 1
def test_highlighting(self): def test_highlighting(self):
"""Test detection of active subsubmenu items using request.path""" """Test detection of active subsubmenu items using request.path"""
menu = { menu = [{'url': '/abc/123/abc/', 'text': 'abc'},
'text': 'blubb', {'url': '/abc/123/', 'text': 'overview'},
'items': [{'url': '/abc/123/abc/', 'text': 'abc'}, {'url': '/abc/123/crunch/', 'text': 'crunch'},
{'url': '/abc/123/', 'text': 'overview'}, {'url': '/abc/123/create/', 'text': 'create'}]
{'url': '/abc/123/crunch/', 'text': 'crunch'},
{'url': '/abc/123/create/', 'text': 'create'}]
}
tests = [['/abc/123/crunch/new/', '/abc/123/crunch/'], tests = [['/abc/123/crunch/new/', '/abc/123/crunch/'],
['/abc/123/create/', '/abc/123/create/'], ['/abc/123/create/', '/abc/123/create/'],