diff --git a/base/models.py b/base/models.py index aca2da222..3b5e5c872 100644 --- a/base/models.py +++ b/base/models.py @@ -3,7 +3,7 @@ from django.utils.translation import ugettext_lazy as _ def get_sessao_media_path(instance, subpath, filename): - return './casa/%s/%s/%s' % (instance.codigo, subpath, filename) + return './casa/%s/%s' % (subpath, filename) def get_casa_media_path(instance, filename): diff --git a/base/views.py b/base/views.py index 99601ba48..9c0685eae 100644 --- a/base/views.py +++ b/base/views.py @@ -183,8 +183,9 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView): if form.is_valid(): casa = CasaLegislativa.objects.first() - if casa is not None: - if "remover" in request.POST: + if casa: + if ("remover" in request.POST or + (form.cleaned_data['logotipo'] and casa.logotipo)): try: os.unlink(casa.logotipo.path) except OSError: @@ -196,7 +197,7 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView): instance=casa ).save(commit=False) casa_save.save() - elif casa is None: + else: form.save() return self.form_valid(form) else: