mirror of https://github.com/interlegis/sigi.git
Guilherme Gondim
15 years ago
8 changed files with 114 additions and 9 deletions
@ -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') |
@ -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 %} |
@ -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 %} |
@ -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 |
Loading…
Reference in new issue