diff --git a/colab/plugins/templates/plugins/menu_template.html b/colab/plugins/templates/plugins/menu_template.html index f24f797..1b9a38e 100644 --- a/colab/plugins/templates/plugins/menu_template.html +++ b/colab/plugins/templates/plugins/menu_template.html @@ -1,16 +1,16 @@ {% for title, links in menu_links.items %} {% if links|length == 1 %} - {% for text, link in links %} + {% for colab_url in links %}
  • - {{ title }} + {{ title }}
  • {% endfor %} {% else %} diff --git a/colab/plugins/templatetags/plugins.py b/colab/plugins/templatetags/plugins.py index bc62c90..ee34750 100644 --- a/colab/plugins/templatetags/plugins.py +++ b/colab/plugins/templatetags/plugins.py @@ -3,18 +3,22 @@ from collections import OrderedDict from django import template from django.core.cache import cache from django.template.loader import render_to_string -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import get_language register = template.Library() @register.simple_tag(takes_context=True) def plugins_menu(context): + if context['user'].is_authenticated(): cache_key = 'colab-proxy-menu-authenticated' else: cache_key = 'colab-proxy-menu-anonymous' + lang = get_language() + cache_key += '-{}'.format(lang) + menu_from_cache = cache.get(cache_key) if menu_from_cache: @@ -23,25 +27,25 @@ def plugins_menu(context): menu_links = OrderedDict() proxied_apps = context.get('proxy', {}) + # TODO: change name from proxied_apps to something with plugins =) for app_name, app in proxied_apps.items(): - if not app.get('menu'): + if not app.get('menu_urls'): continue - menu = app.get('menu') - title = menu.get('title', app_name) - links = menu.get('links', tuple()) - if context['user'].is_active: - links += menu.get('auth_links', tuple()) - - if not links: - continue + menu = app.get('menu_urls') + title = app.get('menu_title', app_name) if title not in menu_links: - menu_links[_(title)] = [] + menu_links[title] = [] + + for colab_url in menu: + if not context['user'].is_active and colab_url.auth: + continue + + menu_links[title].append(colab_url) - for text, link in links: - url = link - menu_links[_(title)].append((_(text), url)) + if not menu_links[title]: + del menu_links[title] menu = render_to_string('plugins/menu_template.html', {'menu_links': menu_links}) diff --git a/colab/plugins/urls.py b/colab/plugins/urls.py index 86aab09..a94e938 100644 --- a/colab/plugins/urls.py +++ b/colab/plugins/urls.py @@ -14,8 +14,8 @@ for app_name, app in settings.COLAB_APPS.items(): urls = app.get('urls') if not urls.get('include'): raise ImproperlyConfigured(undef_url_include_msg) - print urls['include'] urlpatterns += patterns('', url(urls.get('prefix', r''), include(urls['include'], namespace=urls.get('namespace'))), - ) \ No newline at end of file + ) + diff --git a/colab/plugins/utils/menu.py b/colab/plugins/utils/menu.py new file mode 100644 index 0000000..d071a2f --- /dev/null +++ b/colab/plugins/utils/menu.py @@ -0,0 +1,25 @@ +from django.core.urlresolvers import reverse_lazy + + +class ColabUrl(object): + def __init__(self, display, url, auth): + self.display = display + self.url = url + self.auth = auth + + +def colab_url_factory(namespace): + + def url(display, viewname, namespace=namespace, args=tuple(), + kwargs={}, auth=False): + + if namespace: + rev_viewname = ':'.join((namespace, viewname)) + else: + rev_viewname = viewname + + url = reverse_lazy(rev_viewname, args=args, kwargs=kwargs) + + return ColabUrl(display, url, auth) + + return url diff --git a/colab/utils/conf.py b/colab/utils/conf.py index b090ee0..484d301 100644 --- a/colab/utils/conf.py +++ b/colab/utils/conf.py @@ -140,8 +140,9 @@ def load_colab_apps(): if file_name.endswith('.py'): file_module = file_name.split('.')[0] py_settings_d = _load_py_file(file_module, plugins_dir) - fields = ['urls', 'menu', 'upstream', 'middlewares', - 'dependencies', 'context_processors'] + fields = ['verbose_name', 'upstream', 'urls', + 'menu_urls', 'middlewares', 'dependencies', + 'context_processors'] app_name = py_settings_d.get('name') if not app_name: @@ -149,6 +150,9 @@ def load_colab_apps(): continue COLAB_APPS[app_name] = {} + COLAB_APPS[app_name]['menu_title'] = \ + py_settings_d.get('menu_title') + for key in fields: value = py_settings_d.get(key) if value: -- libgit2 0.21.2