Skip to content

Commit 285d32e

Browse files
DtiLegBGLeandroJatai
authored andcommitted
separa por ano materias normas documentos_acessorios
1 parent ffac0bc commit 285d32e

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

sapl/materia/models.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@
2222
EM_TRAMITACAO = [(1, 'Sim'),
2323
(0, 'Não')]
2424

25-
2625
def grupo_autor():
2726
try:
2827
grupo = Group.objects.get(name='Autor')
2928
except Group.DoesNotExist:
3029
return None
3130
return grupo.id
3231

33-
3432
@reversion.register()
3533
class TipoProposicao(models.Model):
3634
descricao = models.CharField(max_length=50, verbose_name=_('Descrição'))
@@ -120,10 +118,15 @@ def __str__(self):
120118
TIPO_APRESENTACAO_CHOICES = Choices(('O', 'oral', _('Oral')),
121119
('E', 'escrita', _('Escrita')))
122120

121+
def materia_upload_path(instance, filename):
122+
return texto_upload_path(instance, filename, subpath=instance.ano)
123123

124+
def anexo_upload_path(instance, filename):
125+
return texto_upload_path(instance, filename, subpath=instance.materia.ano)
126+
124127
@reversion.register()
125128
class MateriaLegislativa(models.Model):
126-
129+
127130
tipo = models.ForeignKey(TipoMateriaLegislativa,
128131
on_delete=models.PROTECT,
129132
verbose_name=_('Tipo'))
@@ -194,7 +197,7 @@ class MateriaLegislativa(models.Model):
194197
texto_original = models.FileField(
195198
blank=True,
196199
null=True,
197-
upload_to=texto_upload_path,
200+
upload_to=materia_upload_path,
198201
verbose_name=_('Texto Original'),
199202
validators=[restringe_tipos_de_arquivo_txt])
200203

@@ -215,6 +218,7 @@ class Meta:
215218
def __str__(self):
216219
return _('%(tipo)s nº %(numero)s de %(ano)s') % {
217220
'tipo': self.tipo, 'numero': self.numero, 'ano': self.ano}
221+
218222

219223
def data_entrada_protocolo(self):
220224
'''
@@ -231,7 +235,7 @@ def data_entrada_protocolo(self):
231235
pass
232236

233237
return ''
234-
238+
235239
def delete(self, using=None, keep_parents=False):
236240
if self.texto_original:
237241
self.texto_original.delete()
@@ -255,6 +259,7 @@ def save(self, force_insert=False, force_update=False, using=None,
255259
force_update=force_update,
256260
using=using,
257261
update_fields=update_fields)
262+
258263

259264

260265
@reversion.register()
@@ -392,7 +397,7 @@ class DocumentoAcessorio(models.Model):
392397
arquivo = models.FileField(
393398
blank=True,
394399
null=True,
395-
upload_to=texto_upload_path,
400+
upload_to=anexo_upload_path,
396401
verbose_name=_('Texto Integral'),
397402
validators=[restringe_tipos_de_arquivo_txt])
398403

@@ -625,7 +630,7 @@ class Proposicao(models.Model):
625630
('I', 'Incorporada')),
626631
verbose_name=_('Status Proposição'))
627632
texto_original = models.FileField(
628-
upload_to=texto_upload_path,
633+
upload_to=materia_upload_path,
629634
blank=True,
630635
null=True,
631636
verbose_name=_('Texto Original'),

sapl/norma/models.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class Meta:
5959
def __str__(self):
6060
return self.descricao
6161

62+
def norma_upload_path(instance, filename):
63+
return texto_upload_path(instance, filename, subpath=instance.ano)
6264

6365
@reversion.register()
6466
class NormaJuridica(models.Model):
@@ -67,10 +69,11 @@ class NormaJuridica(models.Model):
6769
('F', 'federal', _('Federal')),
6870
('M', 'municipal', _('Municipal')),
6971
)
72+
7073
texto_integral = models.FileField(
7174
blank=True,
7275
null=True,
73-
upload_to=texto_upload_path,
76+
upload_to=norma_upload_path,
7477
verbose_name=_('Texto Integral'),
7578
validators=[restringe_tipos_de_arquivo_txt])
7679
tipo = models.ForeignKey(

sapl/utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,8 @@ def texto_upload_path(instance, filename, subpath=''):
605605
seguida para armazenar o arquivo.
606606
"""
607607

608-
if subpath and '/' not in subpath:
609-
subpath = subpath + '/'
608+
# if subpath and '/' not in subpath:
609+
# subpath = subpath + '/'
610610

611611
""" TODO: Verifique possibilidade de otimização do código de normalização
612612
do filename...
@@ -624,7 +624,7 @@ def texto_upload_path(instance, filename, subpath=''):
624624
if isinstance(instance, (DocumentoAdministrativo, Proposicao)):
625625
prefix = 'private'
626626

627-
path = './sapl/%(prefix)s/%(model_name)s/%(pk)s/%(subpath)s%(filename)s' %\
627+
path = './sapl/%(prefix)s/%(model_name)s/%(subpath)s/%(pk)s/%(filename)s' %\
628628
{
629629
'prefix': prefix,
630630
'model_name': instance._meta.model_name,

0 commit comments

Comments
 (0)