Commit 50b4dc1e9678fc5aff68b0f9060d823c484b979b

Authored by Sergio Oliveira
1 parent b2bdfcaa

Added template tag to dynamicly assemble the menu

colab/proxy/gitlab/apps.py
1 1  
  2 +from django.utils.translation import ugettext_lazy as _
  3 +
2 4 from ..utils.apps import ColabProxiedAppConfig
3 5  
4 6  
5 7 class ProxyGitlabAppConfig(ColabProxiedAppConfig):
6 8 name = 'colab.proxy.gitlab'
7 9 verbose_name = 'Gitlab Proxy'
  10 +
  11 + menu = {
  12 + 'title': _('Repository'),
  13 + 'links': (
  14 + (_('Public Projects'), 'public/projects'),
  15 + ),
  16 + 'auth_links': (
  17 + (_('Profile'), 'profile'),
  18 + (_('New Project'), 'projects/new'),
  19 + (_('Projects'), 'dashboard/projects'),
  20 + (_('Groups'), 'profile/groups'),
  21 + (_('Issues'), 'dashboard/issues'),
  22 + (_('Merge Requests'), 'dashboard/merge_requests'),
  23 +
  24 + ),
  25 + }
... ...
colab/proxy/gitlab/urls.py
... ... @@ -6,5 +6,5 @@ from .views import GitlabProxyView
6 6  
7 7 urlpatterns = patterns('',
8 8 # Gitlab URLs
9   - url(r'^(?P<path>.*)$', GitlabProxyView.as_view()),
  9 + url(r'^(?P<path>.*)$', GitlabProxyView.as_view(), name='gitlab'),
10 10 )
... ...
colab/proxy/gitlab/views.py
1 1  
2   -from django.conf import settings
3   -
4 2 from ..utils.views import ColabProxyView
5 3  
6 4  
... ...
colab/proxy/templatetags/__init__.py 0 → 100644
colab/proxy/templatetags/proxy.py 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +
  2 +from django.core.urlresolvers import reverse
  3 +from django import template
  4 +
  5 +register = template.Library()
  6 +
  7 +PROXY_MENU_TEMPLATE = """
  8 +<li class="dropdown">
  9 + <a href="#" class="dropdown-toggle" data-toggle="dropdown">{title}
  10 + <b class="caret"></b></a>
  11 + <ul class="dropdown-menu">
  12 + {items}
  13 + </ul>
  14 +</li>"""
  15 +
  16 +PROXY_MENU_ITEM_TEMPLATE = """
  17 + <li><a href="{link}">{link_title}</a></li>
  18 +"""
  19 +
  20 +
  21 +@register.simple_tag(takes_context=True)
  22 +def proxy_menu(context):
  23 + menu = ''
  24 + proxied_apps = context.get('proxy', {})
  25 +
  26 + for app in proxied_apps.values():
  27 + if not hasattr(app, 'menu'):
  28 + continue
  29 +
  30 + title = app.menu.get('title', app.label.title())
  31 + links = app.menu.get('links', tuple())
  32 + if context['user'].is_active:
  33 + links += app.menu.get('auth_links', tuple())
  34 +
  35 + if not links:
  36 + continue
  37 +
  38 + items = ''
  39 +
  40 + for text, link in links:
  41 + url = reverse(app.label, args=(link,))
  42 + items += PROXY_MENU_ITEM_TEMPLATE.format(link=url,
  43 + link_title=unicode(text))
  44 + menu += PROXY_MENU_TEMPLATE.format(title=unicode(title), items=items)
  45 +
  46 + return menu
... ...
colab/settings.py
... ... @@ -55,6 +55,7 @@ INSTALLED_APPS = (
55 55  
56 56 # Own apps
57 57 'colab.home',
  58 + 'colab.proxy',
58 59 'colab.super_archives',
59 60 'colab.api',
60 61 'colab.rss',
... ...
colab/templates/base.html
1 1 <!DOCTYPE html>
2   -{% load i18n browserid conversejs gravatar %}
  2 +{% load i18n browserid conversejs gravatar proxy %}
3 3 {% load static from staticfiles %}
4 4  
5 5 <html>
... ... @@ -100,22 +100,8 @@
100 100 </li>
101 101 {% endif %}
102 102  
103   - {% if proxy.gitlab %}
104   - <li class="dropdown">
105   - <a href="#" class="dropdown-toggle" data-toggle="dropdown">{% trans "Repository" %} <b class="caret"></b></a>
106   - <ul class="dropdown-menu">
107   - <li><a href="/gitlab/public/projects">{% trans "Public Projects" %}</a></li>
108   - {% if user.is_active %}
109   - <li><a href="/gitlab/profile">{% trans "Profile" %}</a></li>
110   - <li><a href="/gitlab/projects/new">{% trans "New Project" %}</a></li>
111   - <li><a href="/gitlab/dashboard/projects">{% trans "Projects" %}</a></li>
112   - <li><a href="/gitlab/profile/groups">{% trans "Groups" %}</a></li>
113   - <li><a href="/gitlab/dashboard/issues">{% trans "Issues" %}</a></li>
114   - <li><a href="/gitlab/dashboard/merge_requests">{% trans "Merge Requests" %}</a></li>
115   - {% endif %}
116   - </ul>
117   - </li>
118   - {% endif %}
  103 + {% proxy_menu %}
  104 +
119 105 {% if proxy.noosfero %}
120 106 <li class="dropdown">
121 107 <a href="#" class="dropdown-toggle" data-toggle="dropdown">
... ...