diff --git a/sapl/sessao/migrations/0044_auto_20190816_1336.py b/sapl/sessao/migrations/0044_auto_20190816_1336.py new file mode 100644 index 000000000..c6d74d88a --- /dev/null +++ b/sapl/sessao/migrations/0044_auto_20190816_1336.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-08-16 16:36 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sessao', '0043_auto_20190712_1053'), + ] + + operations = [ + migrations.AlterModelOptions( + name='tipoexpediente', + options={'ordering': ['ordenacao'], 'verbose_name': 'Tipo de Expediente', 'verbose_name_plural': 'Tipos de Expediente'}, + ), + migrations.AddField( + model_name='tipoexpediente', + name='ordenacao', + field=models.PositiveIntegerField(blank=True, null=True, verbose_name='Ordenação'), + ), + ] diff --git a/sapl/sessao/migrations/0045_auto_20190816_1337.py b/sapl/sessao/migrations/0045_auto_20190816_1337.py new file mode 100644 index 000000000..e835b5998 --- /dev/null +++ b/sapl/sessao/migrations/0045_auto_20190816_1337.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-08-16 16:37 +from __future__ import unicode_literals + +from django.db import migrations + + +def migra_ordenacao_tipos(apps, schema_editor): + TipoExpediente = apps.get_model('sessao', 'TipoExpediente') + + for i,tipo in enumerate(TipoExpediente.objects.all().order_by('nome')): + tipo.ordenacao=i+1 + tipo.save() + +class Migration(migrations.Migration): + + dependencies = [ + ('sessao', '0044_auto_20190816_1336'), + ] + + operations = [ + migrations.RunPython(migra_ordenacao_tipos) + ] diff --git a/sapl/sessao/models.py b/sapl/sessao/models.py index 9afc5a562..be9ae9ac1 100644 --- a/sapl/sessao/models.py +++ b/sapl/sessao/models.py @@ -350,11 +350,15 @@ class ExpedienteMateria(AbstractOrdemDia): @reversion.register() class TipoExpediente(models.Model): nome = models.CharField(max_length=100, verbose_name=_('Tipo')) + ordenacao = models.PositiveIntegerField( + blank=True, + null=True, + verbose_name=_("Ordenação")) class Meta: verbose_name = _('Tipo de Expediente') verbose_name_plural = _('Tipos de Expediente') - ordering = ['nome'] + ordering = ['ordenacao'] def __str__(self): return self.nome diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index f2d4aa39c..60831f938 100755 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -2081,16 +2081,14 @@ class ExpedienteView(FormMixin, DetailView): def get(self, request, *args, **kwargs): self.object = self.get_object() context = self.get_context_data(object=self.object) - tipos = TipoExpediente.objects.all().order_by('nome') + tipos = TipoExpediente.objects.all().order_by('ordenacao', 'nome') expedientes_sessao = ExpedienteSessao.objects.filter( - sessao_plenaria_id=self.object.id).order_by('tipo__nome') + sessao_plenaria_id=self.object.id).order_by('tipo__ordenacao', 'tipo__nome') - expedientes_salvos = [] - for e in expedientes_sessao: - expedientes_salvos.append(e.tipo) + expedientes_salvos = [e.tipo.id for e in expedientes_sessao] + + tipos_null = TipoExpediente.objects.all().exclude(id__in=expedientes_salvos).order_by('ordenacao', 'nome') - tipos_null = list(set(tipos) - set(expedientes_salvos)) - tipos_null.sort(key=lambda x: x.nome) expedientes = [] for e, t in zip(expedientes_sessao, tipos): diff --git a/sapl/templates/sessao/layouts.yaml b/sapl/templates/sessao/layouts.yaml index caeafc963..9f08885b8 100644 --- a/sapl/templates/sessao/layouts.yaml +++ b/sapl/templates/sessao/layouts.yaml @@ -27,7 +27,7 @@ TipoResultadoVotacao: TipoExpediente: {% trans 'Tipo de Expediente' %}: - - nome + - nome ordenacao RegistroVotacao: {% trans 'Votação Simbólica' %}: