From 50b4dc1e9678fc5aff68b0f9060d823c484b979b Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Date: Tue, 11 Nov 2014 09:12:14 -0200 Subject: [PATCH] Added template tag to dynamicly assemble the menu --- colab/proxy/gitlab/apps.py | 18 ++++++++++++++++++ colab/proxy/gitlab/urls.py | 2 +- colab/proxy/gitlab/views.py | 2 -- colab/proxy/templatetags/__init__.py | 0 colab/proxy/templatetags/proxy.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ colab/settings.py | 1 + colab/templates/base.html | 20 +++----------------- 7 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 colab/proxy/templatetags/__init__.py create mode 100644 colab/proxy/templatetags/proxy.py diff --git a/colab/proxy/gitlab/apps.py b/colab/proxy/gitlab/apps.py index 11a6d40..5e89f7b 100644 --- a/colab/proxy/gitlab/apps.py +++ b/colab/proxy/gitlab/apps.py @@ -1,7 +1,25 @@ +from django.utils.translation import ugettext_lazy as _ + from ..utils.apps import ColabProxiedAppConfig class ProxyGitlabAppConfig(ColabProxiedAppConfig): name = 'colab.proxy.gitlab' verbose_name = 'Gitlab Proxy' + + menu = { + 'title': _('Repository'), + 'links': ( + (_('Public Projects'), 'public/projects'), + ), + 'auth_links': ( + (_('Profile'), 'profile'), + (_('New Project'), 'projects/new'), + (_('Projects'), 'dashboard/projects'), + (_('Groups'), 'profile/groups'), + (_('Issues'), 'dashboard/issues'), + (_('Merge Requests'), 'dashboard/merge_requests'), + + ), + } diff --git a/colab/proxy/gitlab/urls.py b/colab/proxy/gitlab/urls.py index 66d7516..827b541 100644 --- a/colab/proxy/gitlab/urls.py +++ b/colab/proxy/gitlab/urls.py @@ -6,5 +6,5 @@ from .views import GitlabProxyView urlpatterns = patterns('', # Gitlab URLs - url(r'^(?P.*)$', GitlabProxyView.as_view()), + url(r'^(?P.*)$', GitlabProxyView.as_view(), name='gitlab'), ) diff --git a/colab/proxy/gitlab/views.py b/colab/proxy/gitlab/views.py index 14f0d6c..4ce0edf 100644 --- a/colab/proxy/gitlab/views.py +++ b/colab/proxy/gitlab/views.py @@ -1,6 +1,4 @@ -from django.conf import settings - from ..utils.views import ColabProxyView diff --git a/colab/proxy/templatetags/__init__.py b/colab/proxy/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/colab/proxy/templatetags/__init__.py diff --git a/colab/proxy/templatetags/proxy.py b/colab/proxy/templatetags/proxy.py new file mode 100644 index 0000000..e7d3018 --- /dev/null +++ b/colab/proxy/templatetags/proxy.py @@ -0,0 +1,46 @@ + +from django.core.urlresolvers import reverse +from django import template + +register = template.Library() + +PROXY_MENU_TEMPLATE = """ +""" + +PROXY_MENU_ITEM_TEMPLATE = """ +
  • {link_title}
  • +""" + + +@register.simple_tag(takes_context=True) +def proxy_menu(context): + menu = '' + proxied_apps = context.get('proxy', {}) + + for app in proxied_apps.values(): + if not hasattr(app, 'menu'): + continue + + title = app.menu.get('title', app.label.title()) + links = app.menu.get('links', tuple()) + if context['user'].is_active: + links += app.menu.get('auth_links', tuple()) + + if not links: + continue + + items = '' + + for text, link in links: + url = reverse(app.label, args=(link,)) + items += PROXY_MENU_ITEM_TEMPLATE.format(link=url, + link_title=unicode(text)) + menu += PROXY_MENU_TEMPLATE.format(title=unicode(title), items=items) + + return menu diff --git a/colab/settings.py b/colab/settings.py index 033e54a..d543969 100644 --- a/colab/settings.py +++ b/colab/settings.py @@ -55,6 +55,7 @@ INSTALLED_APPS = ( # Own apps 'colab.home', + 'colab.proxy', 'colab.super_archives', 'colab.api', 'colab.rss', diff --git a/colab/templates/base.html b/colab/templates/base.html index 716073b..1709e93 100644 --- a/colab/templates/base.html +++ b/colab/templates/base.html @@ -1,5 +1,5 @@ -{% load i18n browserid conversejs gravatar %} +{% load i18n browserid conversejs gravatar proxy %} {% load static from staticfiles %} @@ -100,22 +100,8 @@ {% endif %} - {% if proxy.gitlab %} - - {% endif %} + {% proxy_menu %} + {% if proxy.noosfero %}