From 11a6358bd94e8348acf29ac3582967e2abe19911 Mon Sep 17 00:00:00 2001 From: joao Date: Mon, 30 Jan 2023 23:50:20 -0500 Subject: [PATCH] feat: insere o campo Ano para compor a numeracao das audiencias publicas, tornando ao numero unico por Ano --- sapl/audiencia/forms.py | 7 ++--- .../migrations/0017_audienciapublica_ano.py | 27 +++++++++++++++++++ sapl/audiencia/models.py | 7 ++--- sapl/audiencia/views.py | 12 ++++----- sapl/templates/audiencia/layouts.yaml | 4 +-- 5 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 sapl/audiencia/migrations/0017_audienciapublica_ano.py diff --git a/sapl/audiencia/forms.py b/sapl/audiencia/forms.py index 72f3e9c35..ba339e7fa 100755 --- a/sapl/audiencia/forms.py +++ b/sapl/audiencia/forms.py @@ -13,6 +13,7 @@ from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa from sapl.parlamentares.models import Parlamentar from sapl.utils import timezone, FileFieldCheckMixin, validar_arquivo + class AudienciaForm(FileFieldCheckMixin, forms.ModelForm): logger = logging.getLogger(__name__) data_atual = timezone.now() @@ -53,7 +54,7 @@ class AudienciaForm(FileFieldCheckMixin, forms.ModelForm): class Meta: model = AudienciaPublica - fields = ['tipo', 'numero', 'nome', + fields = ['tipo', 'numero', 'ano', 'nome', 'tema', 'data', 'hora_inicio', 'hora_fim', 'observacao', 'audiencia_cancelada', 'parlamentar_autor', 'requerimento', 'url_audio', 'url_video', 'upload_pauta', 'upload_ata', @@ -115,13 +116,13 @@ class AudienciaForm(FileFieldCheckMixin, forms.ModelForm): raise ValidationError(msg) if not cleaned_data['numero']: - ultima_audiencia = AudienciaPublica.objects.all().order_by('numero').last() + ultima_audiencia = AudienciaPublica.objects.all().order_by('-ano', 'numero').last() if ultima_audiencia: cleaned_data['numero'] = ultima_audiencia.numero + 1 else: cleaned_data['numero'] = 1 else: - if AudienciaPublica.objects.filter(numero=cleaned_data['numero']).exclude(pk=self.instance.pk).exists(): + if AudienciaPublica.objects.filter(numero=cleaned_data['numero'], ano=cleaned_data['ano']).exclude(pk=self.instance.pk).exists(): raise ValidationError(f"Já existe uma audiência com a numeração {cleaned_data['numero']}.") if self.cleaned_data['hora_inicio'] and self.cleaned_data['hora_fim']: diff --git a/sapl/audiencia/migrations/0017_audienciapublica_ano.py b/sapl/audiencia/migrations/0017_audienciapublica_ano.py new file mode 100644 index 000000000..958d82fc5 --- /dev/null +++ b/sapl/audiencia/migrations/0017_audienciapublica_ano.py @@ -0,0 +1,27 @@ +# Generated by Django 2.2.28 on 2023-01-31 03:01 + +from django.db import migrations, models + + +def preencher_ano(apps, schema_editor): + AudienciaPublica = apps.get_model('audiencia', 'AudienciaPublica') + for audiencia in AudienciaPublica.objects.all(): + audiencia.ano = audiencia.data.year + audiencia.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('audiencia', '0016_auto_20201013_1126'), + ] + + operations = [ + migrations.AddField( + model_name='audienciapublica', + name='ano', + field=models.PositiveSmallIntegerField(choices=[(2024, 2024), (2023, 2023), (2022, 2022), (2021, 2021), (2020, 2020), (2019, 2019), (2018, 2018), (2017, 2017), (2016, 2016), (2015, 2015), (2014, 2014), (2013, 2013), (2012, 2012), (2011, 2011), (2010, 2010), (2009, 2009), (2008, 2008), (2007, 2007), (2006, 2006), (2005, 2005), (2004, 2004), (2003, 2003), (2002, 2002), (2001, 2001), (2000, 2000), (1999, 1999), (1998, 1998), (1997, 1997), (1996, 1996), (1995, 1995), (1994, 1994), (1993, 1993), (1992, 1992), (1991, 1991), (1990, 1990), (1989, 1989), (1988, 1988), (1987, 1987), (1986, 1986), (1985, 1985), (1984, 1984), (1983, 1983), (1982, 1982), (1981, 1981), (1980, 1980), (1979, 1979), (1978, 1978), (1977, 1977), (1976, 1976), (1975, 1975), (1974, 1974), (1973, 1973), (1972, 1972), (1971, 1971), (1970, 1970), (1969, 1969), (1968, 1968), (1967, 1967), (1966, 1966), (1965, 1965), (1964, 1964), (1963, 1963), (1962, 1962), (1961, 1961), (1960, 1960), (1959, 1959), (1958, 1958), (1957, 1957), (1956, 1956), (1955, 1955), (1954, 1954), (1953, 1953), (1952, 1952), (1951, 1951), (1950, 1950), (1949, 1949), (1948, 1948), (1947, 1947), (1946, 1946), (1945, 1945), (1944, 1944), (1943, 1943), (1942, 1942), (1941, 1941), (1940, 1940), (1939, 1939), (1938, 1938), (1937, 1937), (1936, 1936), (1935, 1935), (1934, 1934), (1933, 1933), (1932, 1932), (1931, 1931), (1930, 1930), (1929, 1929), (1928, 1928), (1927, 1927), (1926, 1926), (1925, 1925), (1924, 1924), (1923, 1923), (1922, 1922), (1921, 1921), (1920, 1920), (1919, 1919), (1918, 1918), (1917, 1917), (1916, 1916), (1915, 1915), (1914, 1914), (1913, 1913), (1912, 1912), (1911, 1911), (1910, 1910), (1909, 1909), (1908, 1908), (1907, 1907), (1906, 1906), (1905, 1905), (1904, 1904), (1903, 1903), (1902, 1902), (1901, 1901), (1900, 1900), (1899, 1899), (1898, 1898), (1897, 1897), (1896, 1896), (1895, 1895), (1894, 1894), (1893, 1893), (1892, 1892), (1891, 1891), (1890, 1890)], default=2000, verbose_name='Ano'), + preserve_default=False, + ), + migrations.RunPython(preencher_ano), + ] diff --git a/sapl/audiencia/models.py b/sapl/audiencia/models.py index d74f0b6e3..2dbea1f48 100755 --- a/sapl/audiencia/models.py +++ b/sapl/audiencia/models.py @@ -5,7 +5,7 @@ from model_utils import Choices from sapl.materia.models import MateriaLegislativa from sapl.parlamentares.models import (CargoMesa, Parlamentar) -from sapl.utils import (YES_NO_CHOICES, SaplGenericRelation, +from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES, SaplGenericRelation, restringe_tipos_de_arquivo_txt, texto_upload_path, OverwriteStorage) @@ -39,7 +39,6 @@ class TipoAudienciaPublica(models.Model): tipo = models.CharField( max_length=1, verbose_name=_('Tipo de Audiência Pública'), choices=TIPO_AUDIENCIA_CHOICES, default='A') - class Meta: verbose_name = _('Tipo de Audiência Pública') verbose_name_plural = _('Tipos de Audiência Pública') @@ -62,6 +61,8 @@ class AudienciaPublica(models.Model): blank=True, verbose_name=_('Tipo de Audiência Pública')) numero = models.PositiveIntegerField(blank=True, verbose_name=_('Número')) + ano = models.PositiveSmallIntegerField(verbose_name=_('Ano'), + choices=RANGE_ANOS) nome = models.CharField( max_length=100, verbose_name=_('Nome da Audiência Pública')) tema = models.CharField( @@ -123,7 +124,7 @@ class AudienciaPublica(models.Model): class Meta: verbose_name = _('Audiência Pública') verbose_name_plural = _('Audiências Públicas') - ordering = ['nome', 'numero', 'tipo'] + ordering = ['ano', 'numero', 'nome', 'tipo'] def __str__(self): return self.nome diff --git a/sapl/audiencia/views.py b/sapl/audiencia/views.py index a35add9c2..296a5d7aa 100755 --- a/sapl/audiencia/views.py +++ b/sapl/audiencia/views.py @@ -19,8 +19,8 @@ class AudienciaCrud(Crud): public = [RP_LIST, RP_DETAIL, ] class BaseMixin(Crud.BaseMixin): - list_field_names = [ 'nome', 'tipo', 'materia', 'data'] - ordering = '-data', 'nome', 'numero', 'tipo' + list_field_names = ['numero', 'nome', 'tipo', 'materia', 'data'] + ordering = '-ano', '-numero', '-data', 'nome', 'tipo' class ListView(Crud.ListView): paginate_by = 10 @@ -28,20 +28,20 @@ class AudienciaCrud(Crud): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - audiencia_materia = { str(a.id): (a.materia, a.numero) for a in context['object_list'] } + audiencia_materia = {str(a.id): (a.materia, a.numero, a.ano) for a in context['object_list']} for row in context['rows']: audiencia_id = row[0][1].split('/')[-1] - tema = str(audiencia_materia[audiencia_id][1]) + ' - ' + row[0][0] + tema = str(audiencia_materia[audiencia_id][1]) + '/' + str(audiencia_materia[audiencia_id][2]) row[0] = (tema, row[0][1]) - coluna_materia = row[2] # Se mudar a ordem de listagem, mudar aqui. + coluna_materia = row[3] # Se mudar a ordem de listagem, mudar aqui. if coluna_materia[0]: materia = audiencia_materia[audiencia_id][0] if materia is not None: url_materia = reverse('sapl.materia:materialegislativa_detail', kwargs={'pk': materia.id}) else: url_materia = None - row[2] = (coluna_materia[0], url_materia) # Se mudar a ordem de listagem, mudar aqui. + row[3] = (coluna_materia[0], url_materia) # Se mudar a ordem de listagem, mudar aqui. return context class CreateView(Crud.CreateView): diff --git a/sapl/templates/audiencia/layouts.yaml b/sapl/templates/audiencia/layouts.yaml index b8d0a43d3..916bfa287 100644 --- a/sapl/templates/audiencia/layouts.yaml +++ b/sapl/templates/audiencia/layouts.yaml @@ -1,7 +1,7 @@ {% load i18n %} AudienciaPublica: {% trans 'Audiência Pública' %}: - - nome:10 numero + - nome:8 numero ano - tema {% trans 'Dados' %}: - tipo_materia numero_materia ano_materia @@ -14,7 +14,7 @@ AudienciaPublica: AudienciaPublicaDetail: {% trans 'Audiência Pública' %}: - - nome:10 numero + - nome:10 numero ano - tema {% trans 'Dados' %}: - materia tipo