From aa77412623c0598326e4d70b27e9884e25465924 Mon Sep 17 00:00:00 2001 From: Edward Date: Wed, 12 Jul 2017 09:58:05 -0300 Subject: [PATCH] Adiciona data_ultima_atualizacao em Norma, MateriaLegislativa e DocumentoAcessorio (#1270) Este campo permite que se se use o comando do haystack ./manage.py update_index --age=2 para indexar somente os registros que foram modificados nas ultimas duas horas. --- sapl/base/search_indexes.py | 9 +++++++ .../migrations/0009_auto_20170712_0951.py | 25 +++++++++++++++++++ sapl/materia/models.py | 10 ++++++++ ...6_normajuridica_data_ultima_atualizacao.py | 20 +++++++++++++++ sapl/norma/models.py | 7 +++++- 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 sapl/materia/migrations/0009_auto_20170712_0951.py create mode 100644 sapl/norma/migrations/0006_normajuridica_data_ultima_atualizacao.py diff --git a/sapl/base/search_indexes.py b/sapl/base/search_indexes.py index bee7a54e3..e614a2f79 100644 --- a/sapl/base/search_indexes.py +++ b/sapl/base/search_indexes.py @@ -28,6 +28,9 @@ class DocumentoAcessorioIndex(indexes.SearchIndex, indexes.Indexable): def index_queryset(self, using=None): return self.get_model().objects.all() + def get_updated_field(self): + return 'data_ultima_atualizacao' + def solr_extraction(self, arquivo): extracted_data = self._get_backend(None).extract_file_contents( arquivo)['contents'] @@ -111,6 +114,9 @@ class MateriaLegislativaIndex(DocumentoAcessorioIndex): model = MateriaLegislativa template_name = 'materia/materialegislativa_text.txt' + def get_updated_field(self): + return 'data_ultima_atualizacao' + class NormaJuridicaIndex(DocumentoAcessorioIndex): text = indexes.CharField(document=True, use_template=True) @@ -118,3 +124,6 @@ class NormaJuridicaIndex(DocumentoAcessorioIndex): filename = 'texto_integral' model = NormaJuridica template_name = 'norma/normajuridica_text.txt' + + def get_updated_field(self): + return 'data_ultima_atualizacao' diff --git a/sapl/materia/migrations/0009_auto_20170712_0951.py b/sapl/materia/migrations/0009_auto_20170712_0951.py new file mode 100644 index 000000000..ecec298a9 --- /dev/null +++ b/sapl/materia/migrations/0009_auto_20170712_0951.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.11 on 2017-07-12 09:51 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0008_auto_20170622_1527'), + ] + + operations = [ + migrations.AddField( + model_name='documentoacessorio', + name='data_ultima_atualizacao', + field=models.DateTimeField(auto_now=True, null=True, verbose_name='Data'), + ), + migrations.AddField( + model_name='materialegislativa', + name='data_ultima_atualizacao', + field=models.DateTimeField(auto_now=True, null=True, verbose_name='Data'), + ), + ] diff --git a/sapl/materia/models.py b/sapl/materia/models.py index ec17e1ded..8d9eae4f5 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -225,6 +225,11 @@ class MateriaLegislativa(models.Model): through_fields=('materia', 'autor'), symmetrical=False,) + data_ultima_atualizacao = models.DateTimeField( + blank=True, null=True, + auto_now=True, + verbose_name=_('Data')) + class Meta: verbose_name = _('Matéria Legislativa') verbose_name_plural = _('Matérias Legislativas') @@ -421,6 +426,11 @@ class DocumentoAcessorio(models.Model): proposicao = GenericRelation( 'Proposicao', related_query_name='proposicao') + data_ultima_atualizacao = models.DateTimeField( + blank=True, null=True, + auto_now=True, + verbose_name=_('Data')) + class Meta: verbose_name = _('Documento Acessório') verbose_name_plural = _('Documentos Acessórios') diff --git a/sapl/norma/migrations/0006_normajuridica_data_ultima_atualizacao.py b/sapl/norma/migrations/0006_normajuridica_data_ultima_atualizacao.py new file mode 100644 index 000000000..9f5d5faba --- /dev/null +++ b/sapl/norma/migrations/0006_normajuridica_data_ultima_atualizacao.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.11 on 2017-07-12 09:51 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('norma', '0005_merge'), + ] + + operations = [ + migrations.AddField( + model_name='normajuridica', + name='data_ultima_atualizacao', + field=models.DateTimeField(auto_now=True, null=True, verbose_name='Data'), + ), + ] diff --git a/sapl/norma/models.py b/sapl/norma/models.py index 20166e7f5..a80f5a564 100644 --- a/sapl/norma/models.py +++ b/sapl/norma/models.py @@ -69,7 +69,7 @@ class NormaJuridica(models.Model): ('F', 'federal', _('Federal')), ('M', 'municipal', _('Municipal')), ) - + texto_integral = models.FileField( blank=True, null=True, @@ -121,6 +121,11 @@ class NormaJuridica(models.Model): texto_articulado = GenericRelation( TextoArticulado, related_query_name='texto_articulado') + data_ultima_atualizacao = models.DateTimeField( + blank=True, null=True, + auto_now=True, + verbose_name=_('Data')) + class Meta: verbose_name = _('Norma Jurídica') verbose_name_plural = _('Normas Jurídicas')