diff --git a/sigi/apps/casas/admin.py b/sigi/apps/casas/admin.py index 8b16bed..0589ea1 100644 --- a/sigi/apps/casas/admin.py +++ b/sigi/apps/casas/admin.py @@ -1,17 +1,18 @@ # -*- coding: utf-8 -*- from django.contrib import admin from django.contrib.contenttypes import generic +from django.http import HttpResponse, HttpResponseRedirect +from geraldo.generators import PDFGenerator from sigi.apps.casas.forms import CasaLegislativaForm from sigi.apps.casas.models import CasaLegislativa, Presidente, Funcionario -from sigi.apps.contatos.models import Telefone -from sigi.apps.convenios.models import Projeto, Convenio, EquipamentoPrevisto, Anexo -from django.http import HttpResponse, HttpResponseRedirect from sigi.apps.casas.reports import CasasLegislativasLabels, CasasLegislativasReport -from geraldo.generators import PDFGenerator from sigi.apps.casas.views import report_complete, labels_report, export_csv, \ labels_report_sem_presidente, report, \ adicionar_casas_carrinho from sigi.apps.utils import queryset_ascii +from sigi.apps.contatos.models import Telefone +from sigi.apps.convenios.models import Projeto, Convenio, EquipamentoPrevisto, Anexo +from sigi.apps.mesas.models import Legislatura class TelefonesInline(generic.GenericTabularInline): model = Telefone @@ -41,13 +42,32 @@ class ConveniosInline(admin.TabularInline): model = Convenio exclude = ['equipada','conveniada','observacao'] extra = 1 + +class LegislaturaInline(admin.TabularInline): + model = Legislatura + fields = ['numero', 'data_inicio', 'data_fim', 'data_eleicao', 'total_parlamentares', 'link_parlamentares',] + readonly_fields = ['link_parlamentares',] + + def link_parlamentares(self, obj): + if obj.pk is None: + return "" + from django.core.urlresolvers import reverse + url = reverse('admin:%s_%s_change' %(obj._meta.app_label, obj._meta.module_name), args=[obj.pk] ) + url = url + '?_popup=1' + return """ + + Editar + """ % (obj.pk, obj.pk, url) + + link_parlamentares.short_description = 'Parlamentares' + link_parlamentares.allow_tags = True class CasaLegislativaAdmin(admin.ModelAdmin): form = CasaLegislativaForm change_form_template = 'casas/change_form.html' change_list_template = 'casas/change_list.html' actions = ['adicionar_casas',] - inlines = (TelefonesInline, PresidenteInline, FuncionariosInline, ConveniosInline) + inlines = (TelefonesInline, PresidenteInline, FuncionariosInline, ConveniosInline, LegislaturaInline, ) list_display = ('nome','municipio','logradouro', 'ult_alt_endereco') list_display_links = ('nome',) list_filter = ('tipo', 'municipio') diff --git a/sigi/apps/mesas/admin.py b/sigi/apps/mesas/admin.py index 5267db0..9980673 100644 --- a/sigi/apps/mesas/admin.py +++ b/sigi/apps/mesas/admin.py @@ -1,21 +1,41 @@ # -*- coding: utf-8 -*- from django.contrib import admin +from django.http import HttpResponse +from django.utils.html import escape, escapejs from sigi.apps.mesas.models import (Legislatura, Coligacao, ComposicaoColigacao, SessaoLegislativa, MesaDiretora, Cargo, MembroMesaDiretora) +from sigi.apps.parlamentares.models import Mandato +class MandatoInline(admin.TabularInline): + model = Mandato + raw_id_fields = ['parlamentar',] + class LegislaturaAdmin(admin.ModelAdmin): date_hierarchy = 'data_inicio' - list_display = ('casa_legislativa', 'numero', 'data_inicio', 'data_fim', 'data_eleicao', 'total_parlamentares') + list_display = ('numero', 'casa_legislativa', 'uf', 'data_inicio', 'data_fim', 'data_eleicao', 'total_parlamentares') raw_id_fields = ('casa_legislativa',) list_display_links = ('numero',) - list_filter = ('casa_legislativa', 'data_eleicao',) + list_filter = ('casa_legislativa', ) search_fields = ('numero', 'casa_legislativa') + inlines = (MandatoInline,) + def uf(self, obj): + return obj.casa_legislativa.municipio.uf.sigla + uf.short_description = 'UF' + uf.admin_order_field = 'casa_legislativa__municipio__uf' + def lookup_allowed(self, lookup, value): return super(LegislaturaAdmin, self).lookup_allowed(lookup, value) or \ lookup in ['casa_legislativa__municipio__uf__codigo_ibge__exact'] - + + def response_change(self, request, obj): + response = super(LegislaturaAdmin, self).response_change(request, obj) + if request.POST.has_key("_popup"): + response = HttpResponse('' % \ + # escape() calls force_unicode. + (escape(obj.pk), escapejs(obj))) + return response class ColigacaoAdmin(admin.ModelAdmin): list_display = ('nome', 'legislatura', 'numero_votos') diff --git a/sigi/apps/mesas/models.py b/sigi/apps/mesas/models.py index 573283d..25b2e4c 100644 --- a/sigi/apps/mesas/models.py +++ b/sigi/apps/mesas/models.py @@ -15,10 +15,10 @@ class Legislatura(models.Model): def meta(self): unique_together = (('casa_legislativa', 'numero')) - ordering = ['-data_inicio'] + ordering = ['casa_legislativa__municipio__uf__sigla', '-data_inicio'] def __unicode__(self): - return str(self.numero) + return "%sª legislatura da %s (%s-%s)" % (self.numero, self.casa_legislativa.__unicode__(), self.data_inicio.year, self.data_fim.year) class Coligacao(models.Model): nome = models.CharField(max_length=50) diff --git a/sigi/apps/parlamentares/admin.py b/sigi/apps/parlamentares/admin.py index a485074..087ce9a 100644 --- a/sigi/apps/parlamentares/admin.py +++ b/sigi/apps/parlamentares/admin.py @@ -4,7 +4,7 @@ from django.contrib.contenttypes import generic from sigi.apps.contatos.models import Telefone from sigi.apps.parlamentares.models import Partido, Parlamentar, Mandato -class MandatosInline(admin.StackedInline): +class MandatosInline(admin.TabularInline): model = Mandato extra = 1 raw_id_fields = ('legislatura', 'partido') diff --git a/sigi/apps/parlamentares/models.py b/sigi/apps/parlamentares/models.py index a65de4a..a45743c 100644 --- a/sigi/apps/parlamentares/models.py +++ b/sigi/apps/parlamentares/models.py @@ -74,6 +74,7 @@ class Mandato(models.Model): parlamentar = models.ForeignKey(Parlamentar) legislatura = models.ForeignKey('mesas.Legislatura') partido = models.ForeignKey(Partido) + cargo = models.ForeignKey('mesas.Cargo') inicio_mandato = models.DateField(u'início de mandato') fim_mandato = models.DateField('fim de mandato') is_afastado = models.BooleanField(