Browse Source

Adicionado suporte a etiquetas para as casas.

0.2
Guilherme Gondim 15 years ago
parent
commit
4332294af0
  1. 8
      sigi/apps/casas/admin.py
  2. 13
      sigi/apps/casas/models.py
  3. 40
      sigi/apps/casas/reports.py
  4. 12
      sigi/apps/casas/templates/casas/change_form.html
  5. 15
      sigi/apps/casas/templates/casas/change_list.html
  6. 22
      sigi/apps/casas/views.py
  7. 1
      sigi/settings.py
  8. 10
      sigi/urls.py

8
sigi/apps/casas/admin.py

@ -16,6 +16,8 @@ class TelefonesInline(generic.GenericTabularInline):
class CasaLegislativaAdmin(admin.ModelAdmin): class CasaLegislativaAdmin(admin.ModelAdmin):
form = CasaLegislativaForm form = CasaLegislativaForm
change_form_template = 'casas/change_form.html'
change_list_template = 'casas/change_list.html'
inlines = (TelefonesInline, ContatosInline) inlines = (TelefonesInline, ContatosInline)
list_display = ('nome', 'email', 'pagina_web', 'municipio') list_display = ('nome', 'email', 'pagina_web', 'municipio')
list_display_links = ('nome',) list_display_links = ('nome',)
@ -37,4 +39,10 @@ class CasaLegislativaAdmin(admin.ModelAdmin):
'cep', 'municipio__nome', 'municipio__uf__nome', 'cep', 'municipio__nome', 'municipio__uf__nome',
'municipio__codigo_ibge', 'pagina_web', 'observacoes') 'municipio__codigo_ibge', 'pagina_web', 'observacoes')
def changelist_view(self, request, extra_context=None):
return super(CasaLegislativaAdmin, self).changelist_view(
request,
extra_context={'query_str': '?' + request.META['QUERY_STRING']}
)
admin.site.register(CasaLegislativa, CasaLegislativaAdmin) admin.site.register(CasaLegislativa, CasaLegislativaAdmin)

13
sigi/apps/casas/models.py

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.db import models from django.db import models
from django.contrib.contenttypes import generic from django.contrib.contenttypes import generic
from sigi.apps.mesas.models import MesaDiretora from sigi.apps.mesas.models import MesaDiretora, MembroMesaDiretora
class CasaLegislativa(models.Model): class CasaLegislativa(models.Model):
CASA_CHOICES = ( CASA_CHOICES = (
@ -64,7 +64,12 @@ class CasaLegislativa(models.Model):
def __unicode__(self): def __unicode__(self):
return self.nome return self.nome
def get_presidente(self): def get_presidente_nome(self):
try:
mesa = MesaDiretora.objects.get(casa_legislativa=self) mesa = MesaDiretora.objects.get(casa_legislativa=self)
membro = mesa.membromesadiretora_set.get(cargo__descricao__iexact='presidente') membro = mesa.membromesadiretora_set.get(
return membro.parlamentar cargo__descricao__iexact='presidente'
)
except (MesaDiretora.DoesNotExist, MembroMesaDiretora.DoesNotExist):
return ''
return membro.parlamentar.nome_completo

40
sigi/apps/casas/reports.py

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
import reporting
from reportlab.lib.units import cm
from geraldo import Report, ReportBand, Label, ObjectValue
from sigi.apps.casas.models import CasaLegislativa
class CasasLegislativasLabels(Report):
"""
Usage example::
>>> from geraldo.generators import PDFGenerator
>>> queryset = CasaLegislativa.objects.filter(municipio__uf__sigla='MG')
>>> report = LabelsReport(queryset)
>>> report.generate_by(PDFGenerator, filename='./inline-detail-report.pdf')
"""
class band_detail(ReportBand):
width = 9.40*cm
height = 4.60*cm
# With this attribute as True, the band will try to align in
# the same line.
display_inline = True
elements = [
Label(text='A Sua Excelência o(a) Senhor(a)', top=0, left=0),
ObjectValue(
attribute_name='get_presidente_nome',
top=0.5*cm, left=0, width=9.00*cm,
get_value=lambda obj: obj.get_presidente_nome(),
),
ObjectValue(attribute_name='nome', top=1.0*cm, left=0, width=9.00*cm),
ObjectValue(attribute_name='logradouro', top=1.5*cm, left=0, width=9.00*cm),
ObjectValue(attribute_name='bairro', top=2*cm, left=0, width=9.00*cm),
ObjectValue(attribute_name='municipio', top=2.5*cm, left=0, width=9.00*cm),
ObjectValue(attribute_name='cep', top=3*cm, left=0, width=9.00*cm),
]
reporting.site.register(CasasLegislativasLabels, CasaLegislativa, 'etiquetas')

12
sigi/apps/casas/templates/casas/change_form.html

@ -0,0 +1,12 @@
{% extends "admin/change_form.html" %}
{% load i18n reporting_tags %}
{% block object-tools %}
{% if change %}{% if not is_popup %}
<ul class="object-tools">
<li><a href="labels/">Etiqueta</a></li>
<li><a href="history/" class="historylink">{% trans "History" %}</a></li>
{% if has_absolute_url %}<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
</ul>
{% endif %}{% endif %}
{% endblock %}

15
sigi/apps/casas/templates/casas/change_list.html

@ -0,0 +1,15 @@
{% extends "admin/change_list.html" %}
{% load i18n reporting_tags %}
{% block object-tools %}
{% if has_add_permission %}
<ul class="object-tools">
<li><a href="labels/{{ query_str }}">Etiquetas</a></li>
<li>
<a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">
{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
</a>
</li>
</ul>
{% endif %}
{% endblock %}

22
sigi/apps/casas/views.py

@ -0,0 +1,22 @@
from django.http import HttpResponse, HttpResponseRedirect
from geraldo.generators import PDFGenerator
from sigi.apps.casas.models import CasaLegislativa
from sigi.apps.casas.reports import CasasLegislativasLabels
def labels_report(request, id=None):
""" TODO: adicionar suporte para resultado de pesquisa do admin.
"""
qs = CasaLegislativa.objects.all()
if id:
qs = qs.filter(pk=id)
elif request.GET:
kwargs = {}
for k, v in request.GET.iteritems():
kwargs[str(k)] = v
qs = qs.filter(**kwargs)
if not qs:
return HttpResponseRedirect('../')
response = HttpResponse(mimetype='application/pdf')
report = CasasLegislativasLabels(queryset=qs)
report.generate_by(PDFGenerator, filename=response)
return response

1
sigi/settings.py

@ -88,6 +88,7 @@ INSTALLED_APPS = (
'django_extensions', # http://django-command-extensions.googlecode.com 'django_extensions', # http://django-command-extensions.googlecode.com
'googlecharts', # http://github.com/jacobian/django-googlecharts 'googlecharts', # http://github.com/jacobian/django-googlecharts
'treemenus', # http://django-treemenus.googlecode.com 'treemenus', # http://django-treemenus.googlecode.com
'reporting', # http://github.com/marinho/geraldo
'sigi.apps.casas', 'sigi.apps.casas',
'sigi.apps.contatos', 'sigi.apps.contatos',
'sigi.apps.convenios', 'sigi.apps.convenios',

10
sigi/urls.py

@ -1,17 +1,19 @@
from django.conf import settings from django.conf import settings
from django.conf.urls.defaults import * from django.conf.urls.defaults import *
from django.contrib import databrowse
from django.db.models import get_models
from sigi import sites from sigi import sites
# register admin filters # register admin filters
import sigi.admin.filterspecs import sigi.admin.filterspecs
map(databrowse.site.register, get_models())
urlpatterns = patterns( urlpatterns = patterns(
'', '',
# reports
(r'^casas/casalegislativa/labels/',
'sigi.apps.casas.views.labels_report'),
(r'^casas/casalegislativa/(?P<id>\w+)/labels/',
'sigi.apps.casas.views.labels_report'),
# automatic interface based on admin # automatic interface based on admin
(r'^(.*)', sites.default.root), (r'^(.*)', sites.default.root),
) )

Loading…
Cancel
Save