Browse Source

Replace treemenus with a yaml config and simple rederization

TO DO: Maybe use some sort of cache
producao
Marcio Mazza 10 years ago
parent
commit
29970fdc35
  1. 1
      requirements/dev.txt
  2. 1
      requirements/producao.txt
  3. 0
      sigi/apps/home/__init__.py
  4. 6
      sigi/apps/home/templates/menus/menu.html
  5. 17
      sigi/apps/home/templates/menus/menu_item.html
  6. 0
      sigi/apps/home/templatetags/__init__.py
  7. 97
      sigi/apps/home/templatetags/menu_conf.yaml
  8. 21
      sigi/apps/home/templatetags/menus.py
  9. 3
      sigi/settings/base.py
  10. 4
      templates/admin/base.html
  11. 2
      templates/admin/base_site.html
  12. 9
      templates/treemenus/menu.html
  13. 20
      templates/treemenus/menu_item.html

1
requirements/dev.txt

@ -8,6 +8,7 @@ django-dynamic-fixture==1.7.0
coverage==3.7.1 coverage==3.7.1
pytest-cov==1.8.0 pytest-cov==1.8.0
pyPdf==1.13 pyPdf==1.13
pyquery==1.2.9
# para desevolvimento # para desevolvimento
django-debug-toolbar==1.2.1 django-debug-toolbar==1.2.1

1
requirements/producao.txt

@ -5,7 +5,6 @@ django-autoslug==1.7.2
django-extensions==1.4.0 django-extensions==1.4.0
git+git://github.com/jacobian/django-googlecharts.git@c542996cf9a7a097b447e1ce5a1a6b66bdad254f#egg=django_googlecharts git+git://github.com/jacobian/django-googlecharts.git@c542996cf9a7a097b447e1ce5a1a6b66bdad254f#egg=django_googlecharts
django-localflavor==1.0 django-localflavor==1.0
django-treemenus==0.9.1
eav-django==1.4.7 eav-django==1.4.7
html5lib==0.999 html5lib==0.999
pisa==3.0.33 pisa==3.0.33

0
sigi/apps/home/__init__.py

6
sigi/apps/home/templates/menus/menu.html

@ -0,0 +1,6 @@
{% load menus %}
<ul class="nav navbar-nav">
{% for menu_item in menu_items %}
{% show_menu_item menu_item base_url %}
{% endfor %}
</ul>

17
sigi/apps/home/templates/menus/menu_item.html

@ -0,0 +1,17 @@
{% load menus %}
{% if menu_item.children %}
<li class="dropdown">
{% if menu_item.url %}
<a href="{{base_url}}{{ menu_item.url }}" class="dropdown-toggle" data-toggle="dropdown">{{ menu_item.title }}</a>
{% else %}
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ menu_item.title }} <span class="caret"></span></a>
{% endif %}
<ul class="dropdown-menu" role="menu">
{% for child in menu_item.children %}
{% show_menu_item child base_url %}
{% endfor %}
</ul>
</li>
{% else %}
<li><a href="{{base_url}}{{ menu_item.url }}">{{ menu_item.title }}</a></li>
{% endif %}

0
sigi/apps/home/templatetags/__init__.py

97
sigi/apps/home/templatetags/menu_conf.yaml

@ -0,0 +1,97 @@
main_menu:
- title: Gráficos
url: ''
- title: Municípios
url: admin:contatos/municipio/
children:
- title: Municípios
url: contatos/municipio/
- title: Unidades Federativas
url: contatos/unidadefederativa/
- title: Casas Legislativas
url: casas/casalegislativa/
children:
- title: Todas
url: casas/casalegislativa/
- title: Câmaras Municipais
url: casas/casalegislativa/?tipo__id__exact=1
- title: Assembléias Legislativas
url: casas/casalegislativa/?tipo__id__exact=2
- title: Legislaturas
url: mesas/legislatura/
children:
- title: Todas
url: mesas/legislatura/
- title: Parlamentares
url: parlamentares/parlamentar/
- title: Tabela de cargos
url: mesas/cargo/
- title: Tabela de partidos
url: parlamentares/partido/
- title: Diagnósticos
url: diagnosticos/diagnostico/
children:
- title: Administração
url: diagnosticos/diagnostico/
- title: Coleta de dados
url: diagnosticos/mobile/
- title: Gráficos e estatísticas
url: diagnosticos-graficos
- title: Convênios
url: convenios/convenio/
children:
- title: Convênios
url: convenios/convenio/
- title: Planos diretores
url: metas/planodiretor/
- title: Inventário
url: inventario/bem/
children:
- title: Bens
url: inventario/bem/
- title: Fornecedores
url: inventario/fornecedor/
- title: Equipamentos
url: inventario/equipamento/
- title: Fabricantes
url: inventario/fabricante/
- title: Tipos de equipamentos
url: inventario/tipoequipamento/
- title: Modelos de equipamentos
url: inventario/modeloequipamento/
- title: Servidores
url: servidores/servidor/?user__is_active__exact=1
children:
- title: Pessoal
url: servidores/servidor/?user__is_active__exact=1
- title: Funções
url: servidores/funcao
- title: Férias
url: servidores/ferias/
- title: Licenças
url: servidores/licenca/
- title: Serviços SEIT
url: servicos/casaatendida/
children:
- title: Tipos de serviço
url: servicos/tiposervico/
- title: Casas atendidas
url: servicos/casaatendida/
- title: Lista de serviços
url: servicos/servico/
- title: Ocorrências
url: ocorrencias/ocorrencia/?grupo=S&status__in=1,2
children:
- title: Registro de ocorrências
url: ocorrencias/ocorrencia/?grupo=S&status__in=1,2
- title: Tabela de categorias
url: ocorrencias/categoria/
- title: Tipos de contato
url: ocorrencias/tipocontato/
- title: Financeiro
url: financeiro/desembolso/
children:
- title: Desembolsos
url: financeiro/desembolso/
- title: Dashboard
url: metas-dashboardsss

21
sigi/apps/home/templatetags/menus.py

@ -0,0 +1,21 @@
from os.path import dirname
import yaml
from django import template
register = template.Library()
menus = yaml.load(open(dirname(__file__) + '/menu_conf.yaml', 'r'))
@register.inclusion_tag('menus/menu.html', takes_context=True)
def show_menu(context, menu_id):
base_url = context['request'].build_absolute_uri('/')
menus = yaml.load(open(dirname(__file__) + '/menu_conf.yaml', 'r'))
return dict(menu_items=menus[menu_id], base_url=base_url)
@register.inclusion_tag('menus/menu_item.html')
def show_menu_item(menu_item, base_url):
return dict(menu_item=menu_item, base_url=base_url)

3
sigi/settings/base.py

@ -32,6 +32,7 @@ SITE_ID = 1
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + ( TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
'sigi.context_processors.charts_data', 'sigi.context_processors.charts_data',
'django.core.context_processors.request',
) )
# List of callables that know how to import templates from various sources. # List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = ('django.template.loaders.filesystem.Loader', TEMPLATE_LOADERS = ('django.template.loaders.filesystem.Loader',
@ -55,6 +56,7 @@ INSTALLED_APPS = (
'django.contrib.staticfiles', 'django.contrib.staticfiles',
# Local apps # Local apps
'sigi.apps.home',
'sigi.apps.contatos', 'sigi.apps.contatos',
'sigi.apps.servidores', 'sigi.apps.servidores',
'sigi.apps.parlamentares', 'sigi.apps.parlamentares',
@ -77,7 +79,6 @@ INSTALLED_APPS = (
'reporting', 'reporting',
'django_extensions', 'django_extensions',
'googlecharts', 'googlecharts',
'treemenus',
'easy_thumbnails', 'easy_thumbnails',
'image_cropping', 'image_cropping',

4
templates/admin/base.html

@ -1,6 +1,6 @@
{% load admin_static bootstrapped_goodies_tags %} {% load admin_static bootstrapped_goodies_tags %}
{% load tree_menu_tags %}
{% load i18n %} {% load i18n %}
{% load menus %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}> <html xmlns="http://www.w3.org/1999/xhtml" lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
<head> <head>
@ -134,7 +134,7 @@
</button> </button>
</div> </div>
<div class="navbar-collapse collapse"> <div class="navbar-collapse collapse">
{% show_menu "Barra de navegação" "unordered-list" %} {% show_menu "main_menu" %}
</div><!--/.nav-collapse --> </div><!--/.nav-collapse -->
</div><!--/.container-fluid --> </div><!--/.container-fluid -->
</div> </div>

2
templates/admin/base_site.html

@ -1,6 +1,5 @@
{% extends "admin/base.html" %} {% extends "admin/base.html" %}
{% load i18n %}{% load admin_static bootstrapped_goodies_tags %} {% load i18n %}{% load admin_static bootstrapped_goodies_tags %}
{% load tree_menu_tags %}
{% load static from staticfiles %} {% load static from staticfiles %}
{% block title %}{{ title }} | SIGI{% endblock %} {% block title %}{{ title }} | SIGI{% endblock %}
@ -39,7 +38,6 @@
<a data-toggle="dropdown" class="dropdown-toggle" href="#">{% trans 'Administração' %} <b class="caret"></b></a> <a data-toggle="dropdown" class="dropdown-toggle" href="#">{% trans 'Administração' %} <b class="caret"></b></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="/auth/">{% trans 'Usuários' %} &amp; {% trans 'Grupos' %}</a></li> <li><a href="/auth/">{% trans 'Usuários' %} &amp; {% trans 'Grupos' %}</a></li>
<li><a href="/treemenus/menu/">{% trans 'Menus' %}</a></li>
<li><a href="/sites/site/">{% trans 'Sites' %}</a></li> <li><a href="/sites/site/">{% trans 'Sites' %}</a></li>
<li><a href="/diagnosticos/">{% trans 'Diagnósticos' %}</a></li> <li><a href="/diagnosticos/">{% trans 'Diagnósticos' %}</a></li>
</ul> </ul>

9
templates/treemenus/menu.html

@ -1,9 +0,0 @@
{% load tree_menu_tags %}
{% ifequal menu_type "unordered-list" %}
<ul class="nav navbar-nav">
{% for menu_item in menu.root_item.children %}
{% show_menu_item menu_item %}
{% endfor %}
</ul>
{% endifequal %}

20
templates/treemenus/menu_item.html

@ -1,20 +0,0 @@
{% load tree_menu_tags %}
{% ifequal menu_type "unordered-list" %}
{% if menu_item.has_children %}
<li class="dropdown">
{% if menu_item.url %}
<a href="{{ menu_item.url }}" class="dropdown-toggle" data-toggle="dropdown">{{ menu_item.caption }}</a>
{% else %}
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ menu_item.caption }} <span class="caret"></span></a>
{% endif %}
<ul class="dropdown-menu" role="menu">
{% for child in menu_item.children %}
{% show_menu_item child %}
{% endfor %}
</ul>
</li>
{% else %}
<li><a href="{{ menu_item.url }}">{{ menu_item.caption }}</a></li>
{% endif %}
{% endifequal %}
Loading…
Cancel
Save