diff --git a/sigi/apps/casas/admin.py b/sigi/apps/casas/admin.py index 6c4aa5d..083c7ed 100644 --- a/sigi/apps/casas/admin.py +++ b/sigi/apps/casas/admin.py @@ -15,17 +15,20 @@ from sigi.apps.utils import queryset_ascii class TelefonesInline(generic.GenericTabularInline): model = Telefone + readonly_fields = ('ult_alteracao',) extra = 1 class PresidenteInline(admin.StackedInline): model = Presidente exclude = ['cargo','funcao'] + readonly_fields = ('ult_alteracao',) extra = 1 max_num = 1 inlines = (TelefonesInline) class FuncionariosInline(admin.StackedInline): model = Funcionario + readonly_fields = ('ult_alteracao',) extra = 1 inlines = (TelefonesInline) def queryset(self, request): @@ -42,18 +45,19 @@ class CasaLegislativaAdmin(admin.ModelAdmin): change_list_template = 'casas/change_list.html' actions = ['adicionar_casas',] inlines = (TelefonesInline, PresidenteInline, FuncionariosInline, ConveniosInline) - list_display = ('nome','municipio','logradouro') + readonly_fields = ('ult_alt_endereco',) + list_display = ('nome','municipio','logradouro', 'ult_alt_endereco') list_display_links = ('nome',) list_filter = ('tipo', 'municipio') ordering = ('nome','municipio__uf') queyrset = queryset_ascii fieldsets = ( (None, { - 'fields': ('tipo', 'nome', 'cnpj',) + 'fields': ('tipo', 'nome', 'cnpj') }), ('Endereço', { 'fields': ('data_instalacao', 'logradouro', 'bairro', - 'municipio', 'cep', 'pagina_web','email'), + 'municipio', 'cep', 'pagina_web','email', 'ult_alt_endereco'), }), ('Outras informações', { 'classes': ('collapse',), diff --git a/sigi/apps/casas/models.py b/sigi/apps/casas/models.py index 1acc639..b198576 100644 --- a/sigi/apps/casas/models.py +++ b/sigi/apps/casas/models.py @@ -3,6 +3,7 @@ from django.db import models from django.contrib.contenttypes import generic from sigi.apps.parlamentares.models import Parlamentar from sigi.apps.utils import SearchField +from datetime import datetime class TipoCasaLegislativa(models.Model): """ Modelo para representar o tipo da Casa Legislativa @@ -54,6 +55,7 @@ class CasaLegislativa(models.Model): blank=True, verify_exists=False ) + ult_alt_endereco = models.DateTimeField(u'Última alteração do endereço', null=True, blank=True, editable=False) telefones = generic.GenericRelation('contatos.Telefone') foto = models.ImageField( @@ -95,6 +97,24 @@ class CasaLegislativa(models.Model): def __unicode__(self): return self.nome + + def save(self, *args, **kwargs): + address_changed = False + + if self.pk is not None: + original = CasaLegislativa.objects.get(pk=self.pk) + if (self.logradouro != original.logradouro or + self.bairro != original.bairro or + self.municipio != original.municipio or + self.cep != original.cep): + address_changed = True + else: + address_changed = True + + if address_changed: + self.ult_alt_endereco = datetime.now() + + return super(CasaLegislativa, self).save(*args, **kwargs) class Funcionario(models.Model): """ Modelo para registrar contatos vinculados às @@ -123,6 +143,7 @@ class Funcionario(models.Model): funcao = models.CharField(u'função', max_length=100, null=True, blank=True) setor = models.CharField(max_length=100, choices = SETOR_CHOICES, default="outros") tempo_de_servico = models.CharField(u'tempo de serviço', max_length=50, null=True, blank=True) + ult_alteracao = models.DateTimeField(u'Última alteração', null=True, blank=True, editable=False, auto_now=True) class Meta: ordering = ('nome',) diff --git a/sigi/apps/contatos/models.py b/sigi/apps/contatos/models.py index 7718cbd..24b21c7 100644 --- a/sigi/apps/contatos/models.py +++ b/sigi/apps/contatos/models.py @@ -128,6 +128,7 @@ class Telefone(models.Model): default= 'I' ) nota = models.CharField(max_length=70, null=True, blank=True) + ult_alteracao = models.DateTimeField(u'Última alteração', null=True, blank=True, editable=False, auto_now=True) # guarda o tipo do objeto (classe) vinculado a esse registro content_type = models.ForeignKey(ContentType) diff --git a/sigi/settings.py b/sigi/settings.py index 2487a1c..7ba55b3 100644 --- a/sigi/settings.py +++ b/sigi/settings.py @@ -37,13 +37,14 @@ EMAIL_HOST_USER = '' EMAIL_HOST_PASSWORD = '' #EMAIL_USE_TLS = True -#DATABASE_ENGINE = 'postgresql_psycopg2' -DATABASE_ENGINE = 'sqlite3' -DATABASE_NAME = 'devel.db' -#DATABASE_USER = 'sigi' -#DATABASE_PASSWORD = '123456' -#DATABASE_HOST = 'localhost' -#DATABASE_PORT = '5432' +DATABASE_ENGINE = 'postgresql_psycopg2' +#DATABASE_ENGINE = 'sqlite3' +DATABASE_NAME = 'sigi' +#DATABASE_NAME = 'devel.db' +DATABASE_USER = 'sigi' +DATABASE_PASSWORD = '123456' +DATABASE_HOST = 'localhost' +DATABASE_PORT = '5432' TIME_ZONE = 'Brazil/East' LANGUAGE_CODE = 'pt-br'