From 44ad5f0124c7c9ee6ab060088aa37a77b6e91635 Mon Sep 17 00:00:00 2001 From: Edward Date: Mon, 4 Dec 2017 17:08:24 -0200 Subject: [PATCH] Fixes #1619 (#1622) --- .../migrations/0003_auto_20171204_1658.py | 19 +++++++++++++ sapl/comissoes/models.py | 1 + .../migrations/0020_auto_20171204_1658.py | 27 +++++++++++++++++++ sapl/materia/models.py | 19 ++++++++++++- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 sapl/comissoes/migrations/0003_auto_20171204_1658.py create mode 100644 sapl/materia/migrations/0020_auto_20171204_1658.py diff --git a/sapl/comissoes/migrations/0003_auto_20171204_1658.py b/sapl/comissoes/migrations/0003_auto_20171204_1658.py new file mode 100644 index 000000000..340249cfa --- /dev/null +++ b/sapl/comissoes/migrations/0003_auto_20171204_1658.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.11 on 2017-12-04 18:58 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('comissoes', '0002_auto_20170809_1236'), + ] + + operations = [ + migrations.AlterModelOptions( + name='comissao', + options={'ordering': ['nome'], 'verbose_name': 'Comissão', 'verbose_name_plural': 'Comissões'}, + ), + ] diff --git a/sapl/comissoes/models.py b/sapl/comissoes/models.py index 0b3c664ee..510071d4f 100644 --- a/sapl/comissoes/models.py +++ b/sapl/comissoes/models.py @@ -95,6 +95,7 @@ class Comissao(models.Model): class Meta: verbose_name = _('Comissão') verbose_name_plural = _('Comissões') + ordering = ['nome'] def __str__(self): return self.sigla + ' - ' + self.nome diff --git a/sapl/materia/migrations/0020_auto_20171204_1658.py b/sapl/materia/migrations/0020_auto_20171204_1658.py new file mode 100644 index 000000000..dce162b47 --- /dev/null +++ b/sapl/materia/migrations/0020_auto_20171204_1658.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.11 on 2017-12-04 18:58 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0019_auto_20171127_1500'), + ] + + operations = [ + migrations.AlterModelOptions( + name='orgao', + options={'ordering': ['nome'], 'verbose_name': 'Órgão', 'verbose_name_plural': 'Órgãos'}, + ), + migrations.AlterModelOptions( + name='tipodocumento', + options={'ordering': ['descricao'], 'verbose_name': 'Tipo de Documento', 'verbose_name_plural': 'Tipos de Documento'}, + ), + migrations.AlterModelOptions( + name='unidadetramitacao', + options={'verbose_name': 'Unidade de Tramitação', 'verbose_name_plural': 'Unidades de Tramitação'}, + ), + ] diff --git a/sapl/materia/models.py b/sapl/materia/models.py index d3cfebd28..0aade9df3 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -5,6 +5,7 @@ from django.contrib.contenttypes.fields import GenericRelation from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.db import models +from django.db.models.functions import Concat from django.utils import formats, timezone from django.utils.translation import ugettext_lazy as _ from model_utils import Choices @@ -402,6 +403,7 @@ class TipoDocumento(models.Model): class Meta: verbose_name = _('Tipo de Documento') verbose_name_plural = _('Tipos de Documento') + ordering = ['descricao'] def __str__(self): return self.descricao @@ -545,6 +547,7 @@ class Orgao(models.Model): class Meta: verbose_name = _('Órgão') verbose_name_plural = _('Órgãos') + ordering = ['nome'] def __str__(self): return _( @@ -790,6 +793,19 @@ class StatusTramitacao(models.Model): 'descricao': self.descricao} +class UnidadeTramitacaoManager(models.Manager): + """ + Esta classe permite ordenar alfabeticamente a unidade de tramitacao + através da concatenação de 3 fields + """ + def get_queryset(self): + return super(UnidadeTramitacaoManager, self).get_queryset().annotate( + nome_composto=Concat('orgao__nome', + 'comissao__sigla', + 'parlamentar__nome_parlamentar') + ).order_by('nome_composto') + + @reversion.register() class UnidadeTramitacao(models.Model): comissao = models.ForeignKey( @@ -802,10 +818,11 @@ class UnidadeTramitacao(models.Model): Parlamentar, blank=True, null=True, on_delete=models.PROTECT, verbose_name=_('Parlamentar')) + objects = UnidadeTramitacaoManager() + class Meta: verbose_name = _('Unidade de Tramitação') verbose_name_plural = _('Unidades de Tramitação') - ordering = ['orgao', 'comissao', 'parlamentar'] def __str__(self): if self.orgao and self.comissao and self.parlamentar: