From 465fa6d27428b9c87e027dd03948f499b3c5d7f5 Mon Sep 17 00:00:00 2001 From: Felipe Vieira Date: Fri, 25 Nov 2011 19:18:08 +0000 Subject: [PATCH] mudancas do model de casas legislativas para comportar o formato de contatos dos diagnosticos --- sigi/apps/casas/admin.py | 30 ++++++++++++++++----------- sigi/apps/casas/models.py | 43 +++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 16 deletions(-) diff --git a/sigi/apps/casas/admin.py b/sigi/apps/casas/admin.py index b466119..443d5d0 100644 --- a/sigi/apps/casas/admin.py +++ b/sigi/apps/casas/admin.py @@ -2,8 +2,8 @@ from django.contrib import admin from django.contrib.contenttypes import generic from sigi.apps.casas.forms import CasaLegislativaForm -from sigi.apps.casas.models import CasaLegislativa -from sigi.apps.contatos.models import Contato, Telefone +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 @@ -13,14 +13,21 @@ from sigi.apps.casas.views import report_complete, labels_report, export_csv, \ adicionar_casas_carrinho from sigi.apps.utils import queryset_ascii -class ContatosInline(generic.GenericTabularInline): - model = Contato - extra = 2 - raw_id_fields = ('municipio',) - class TelefonesInline(generic.GenericTabularInline): model = Telefone - extra = 2 + extra = 1 + +class PresidenteInline(admin.StackedInline): + model = Presidente + exclude = ['cargo','funcao'] + extra = 1 + max_num = 1 + inlines = (TelefonesInline) + +class FuncionariosInline(admin.StackedInline): + model = Funcionario + extra = 1 + inlines = (TelefonesInline) class ConveniosInline(admin.TabularInline): model = Convenio @@ -32,16 +39,15 @@ class CasaLegislativaAdmin(admin.ModelAdmin): change_form_template = 'casas/change_form.html' change_list_template = 'casas/change_list.html' actions = ['adicionar_casas',] - inlines = (TelefonesInline, ContatosInline, ConveniosInline) - list_display = ('nome','municipio','presidente','logradouro') + inlines = (TelefonesInline, PresidenteInline, FuncionariosInline, ConveniosInline) + list_display = ('nome','municipio','logradouro') list_display_links = ('nome',) list_filter = ('tipo', 'municipio') ordering = ('nome','municipio__uf') queyrset = queryset_ascii fieldsets = ( (None, { - 'fields': ('tipo', 'nome', 'telefone', 'cnpj', - 'presidente'), + 'fields': ('tipo', 'nome', 'cnpj',) }), ('Endereço', { 'fields': ('logradouro', 'bairro', 'municipio', 'cep', 'pagina_web','email'), diff --git a/sigi/apps/casas/models.py b/sigi/apps/casas/models.py index 52aab33..1bf1c68 100644 --- a/sigi/apps/casas/models.py +++ b/sigi/apps/casas/models.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from django.db import models from django.contrib.contenttypes import generic -from sigi.apps.mesas.models import MesaDiretora, MembroMesaDiretora from sigi.apps.parlamentares.models import Parlamentar from sigi.apps.utils import SearchField @@ -35,7 +34,6 @@ class CasaLegislativa(models.Model): tipo = models.ForeignKey(TipoCasaLegislativa, verbose_name="Tipo") cnpj = models.CharField('CNPJ', max_length=32, blank=True) observacoes = models.TextField(u'observações', blank=True) - presidente = models.CharField('Presidente', max_length=150, blank=True) # Informações de contato logradouro = models.CharField( @@ -56,7 +54,6 @@ class CasaLegislativa(models.Model): blank=True, verify_exists=False ) - telefone = models.CharField('Telefone', max_length=100, blank=True) telefones = generic.GenericRelation('contatos.Telefone') foto = models.ImageField( @@ -68,7 +65,6 @@ class CasaLegislativa(models.Model): foto_largura = models.SmallIntegerField(editable=False, null=True) foto_altura = models.SmallIntegerField(editable=False, null=True) - contatos = generic.GenericRelation('contatos.Contato') class Meta: ordering = ('nome',) @@ -78,3 +74,42 @@ class CasaLegislativa(models.Model): def __unicode__(self): return self.nome + +class Funcionario(models.Model): + """ Modelo para registrar contatos vinculados às + Casas Legislativas + """ + casa_legislativa = models.ForeignKey(CasaLegislativa) + nome = models.CharField('nome completo', max_length=60) + nome.alphabetic_filter = True + nota = models.CharField(max_length=70, blank=True) + email = models.EmailField('e-mail', blank=True) + telefones = generic.GenericRelation('contatos.Telefone') + endereco = generic.GenericRelation('contatos.Endereco') + cargo = models.CharField(max_length=100, null=True, blank=True) + funcao = models.CharField(u'função', max_length=100, null=True, blank=True) + tempo_de_servico = models.CharField(u'tempo de serviço', max_length=50, null=True, blank=True) + + class Meta: + ordering = ('nome',) + verbose_name = 'contato Casa Legislativa' + verbose_name_plural = 'contatos Casas Legislativa' + + def __unicode__(self): + return self.nome + +class PresidenteManager(models.Manager): + def get_query_set(self): + qs = super(PresidenteManager, self).get_query_set() + qs = qs.filter(cargo='Presidente') + return qs + +class Presidente(Funcionario): + class Meta: + proxy = True + + objects = PresidenteManager() + + def save(self, *args, **kwargs): + self.cargo = 'Presidente' + return super(Presidente, self).save(*args, **kwargs)