Skip to content

Commit

Permalink
separa por ano materias normas documentos_acessorios
Browse files Browse the repository at this point in the history
  • Loading branch information
DtiLegBG authored and LeandroJatai committed May 12, 2017
1 parent ffac0bc commit 285d32e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
19 changes: 12 additions & 7 deletions sapl/materia/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
EM_TRAMITACAO = [(1, 'Sim'),
(0, 'Não')]


def grupo_autor():
try:
grupo = Group.objects.get(name='Autor')
except Group.DoesNotExist:
return None
return grupo.id


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

def materia_upload_path(instance, filename):
return texto_upload_path(instance, filename, subpath=instance.ano)

def anexo_upload_path(instance, filename):
return texto_upload_path(instance, filename, subpath=instance.materia.ano)

@reversion.register()
class MateriaLegislativa(models.Model):

tipo = models.ForeignKey(TipoMateriaLegislativa,
on_delete=models.PROTECT,
verbose_name=_('Tipo'))
Expand Down Expand Up @@ -194,7 +197,7 @@ class MateriaLegislativa(models.Model):
texto_original = models.FileField(
blank=True,
null=True,
upload_to=texto_upload_path,
upload_to=materia_upload_path,
verbose_name=_('Texto Original'),
validators=[restringe_tipos_de_arquivo_txt])

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


def data_entrada_protocolo(self):
'''
Expand All @@ -231,7 +235,7 @@ def data_entrada_protocolo(self):
pass

return ''

def delete(self, using=None, keep_parents=False):
if self.texto_original:
self.texto_original.delete()
Expand All @@ -255,6 +259,7 @@ def save(self, force_insert=False, force_update=False, using=None,
force_update=force_update,
using=using,
update_fields=update_fields)



@reversion.register()
Expand Down Expand Up @@ -392,7 +397,7 @@ class DocumentoAcessorio(models.Model):
arquivo = models.FileField(
blank=True,
null=True,
upload_to=texto_upload_path,
upload_to=anexo_upload_path,
verbose_name=_('Texto Integral'),
validators=[restringe_tipos_de_arquivo_txt])

Expand Down Expand Up @@ -625,7 +630,7 @@ class Proposicao(models.Model):
('I', 'Incorporada')),
verbose_name=_('Status Proposição'))
texto_original = models.FileField(
upload_to=texto_upload_path,
upload_to=materia_upload_path,
blank=True,
null=True,
verbose_name=_('Texto Original'),
Expand Down
5 changes: 4 additions & 1 deletion sapl/norma/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Meta:
def __str__(self):
return self.descricao

def norma_upload_path(instance, filename):
return texto_upload_path(instance, filename, subpath=instance.ano)

@reversion.register()
class NormaJuridica(models.Model):
Expand All @@ -67,10 +69,11 @@ class NormaJuridica(models.Model):
('F', 'federal', _('Federal')),
('M', 'municipal', _('Municipal')),
)

texto_integral = models.FileField(
blank=True,
null=True,
upload_to=texto_upload_path,
upload_to=norma_upload_path,
verbose_name=_('Texto Integral'),
validators=[restringe_tipos_de_arquivo_txt])
tipo = models.ForeignKey(
Expand Down
6 changes: 3 additions & 3 deletions sapl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ def texto_upload_path(instance, filename, subpath=''):
seguida para armazenar o arquivo.
"""

if subpath and '/' not in subpath:
subpath = subpath + '/'
# if subpath and '/' not in subpath:
# subpath = subpath + '/'

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

path = './sapl/%(prefix)s/%(model_name)s/%(pk)s/%(subpath)s%(filename)s' %\
path = './sapl/%(prefix)s/%(model_name)s/%(subpath)s/%(pk)s/%(filename)s' %\
{
'prefix': prefix,
'model_name': instance._meta.model_name,
Expand Down

0 comments on commit 285d32e

Please sign in to comment.