From 9fa823374a2d0d8cadb9b2df9fb185a20f94243f Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Thu, 25 May 2017 07:50:44 -0300 Subject: [PATCH] Fixes #1125 --- sapl/sessao/models.py | 6 +++--- sapl/utils.py | 9 +++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/sapl/sessao/models.py b/sapl/sessao/models.py index 4d7c22ca1..f79eee6b1 100644 --- a/sapl/sessao/models.py +++ b/sapl/sessao/models.py @@ -86,17 +86,17 @@ def get_sessao_media_path(instance, subpath, filename): def pauta_upload_path(instance, filename): - return texto_upload_path(instance, filename, subpath='pauta') + return texto_upload_path(instance, filename, subpath='pauta', pk_first=True) # return get_sessao_media_path(instance, 'pauta', filename) def ata_upload_path(instance, filename): - return texto_upload_path(instance, filename, subpath='ata') + return texto_upload_path(instance, filename, subpath='ata', pk_first=True) # return get_sessao_media_path(instance, 'ata', filename) def anexo_upload_path(instance, filename): - return texto_upload_path(instance, filename, subpath='anexo') + return texto_upload_path(instance, filename, subpath='anexo', pk_first=True) # return get_sessao_media_path(instance, 'anexo', filename) diff --git a/sapl/utils.py b/sapl/utils.py index 618a3f4f8..50b7faffc 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -498,7 +498,7 @@ def generic_relations_for_model(model): )) -def texto_upload_path(instance, filename, subpath=''): +def texto_upload_path(instance, filename, subpath='', pk_first=False): """ O path gerado por essa função leva em conta a pk de instance. isso não é possível naturalmente em uma inclusão pois a implementação @@ -539,7 +539,12 @@ def texto_upload_path(instance, filename, subpath=''): if isinstance(instance, (DocumentoAdministrativo, Proposicao)): prefix = 'private' - path = './sapl/%(prefix)s/%(model_name)s/%(subpath)s/%(pk)s/%(filename)s' %\ + str_path = './sapl/%(prefix)s/%(model_name)s/%(subpath)s/%(pk)s/%(filename)s' + + if pk_first: + str_path = './sapl/%(prefix)s/%(model_name)s/%(pk)s/%(subpath)s/%(filename)s' + + path = str_path %\ { 'prefix': prefix, 'model_name': instance._meta.model_name,