diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 754cca79e..3ebc11689 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -40,7 +40,7 @@ from sapl.utils import (autor_label, autor_modal, ChoiceWithoutValidationField, FilterOverridesMetaMixin, FileFieldCheckMixin, ImageThumbnailFileInput, qs_override_django_filter, RANGE_ANOS, YES_NO_CHOICES, choice_tipos_normas, - GoogleRecapthaMixin, parlamentares_ativos, RANGE_MESES, is_weak_password) + GoogleRecapthaMixin, parlamentares_ativos, RANGE_MESES, is_weak_password, delete_cached_entry) from .models import AppConfig, CasaLegislativa @@ -921,13 +921,17 @@ class CasaLegislativaForm(FileFieldCheckMixin, ModelForm): # chama __clean de FileFieldCheckMixin # por estar em clean de campo super(CasaLegislativaForm, self)._check() - logotipo = self.cleaned_data.get('logotipo') - if logotipo: - if logotipo.size > MAX_IMAGE_UPLOAD_SIZE: - raise ValidationError("Imagem muito grande. ( > 2MB )") + if logotipo and logotipo.size > MAX_IMAGE_UPLOAD_SIZE: + raise ValidationError("Imagem muito grande. ( > 2MB )") return logotipo + def save(self, commit=True): + casa = super(CasaLegislativaForm, self).save(commit=commit) + delete_cached_entry("site-title") + return casa + + class LoginForm(AuthenticationForm): username = forms.CharField( diff --git a/sapl/context_processors.py b/sapl/context_processors.py index 2b8a422cb..b3f1631de 100644 --- a/sapl/context_processors.py +++ b/sapl/context_processors.py @@ -1,14 +1,13 @@ import logging -from django.conf import settings from django.utils.translation import ugettext_lazy as _ -from sapl.utils import google_recaptcha_configured as google_recaptcha_configured_utils, sapn_is_enabled +from sapl.utils import google_recaptcha_configured as \ + google_recaptcha_configured_utils, sapn_is_enabled, cached_call, get_base_url from sapl.utils import mail_service_configured as mail_service_configured_utils def parliament_info(request): - from sapl.base.views import get_casalegislativa casa = get_casalegislativa() if casa: @@ -18,7 +17,6 @@ def parliament_info(request): def mail_service_configured(request): - if not mail_service_configured_utils(request): logger = logging.getLogger(__name__) logger.warning(_('Servidor de email não configurado.')) @@ -27,7 +25,6 @@ def mail_service_configured(request): def google_recaptcha_configured(request): - if not google_recaptcha_configured_utils(): logger = logging.getLogger(__name__) logger.warning(_('Google Recaptcha não configurado.')) @@ -35,10 +32,19 @@ def google_recaptcha_configured(request): return {'google_recaptcha_configured': True} +@cached_call("site-title", timeout=2 * 60) def enable_sapn(request): + verbose_name = _('Sistema de Apoio ao Processo Legislativo') \ + if not sapn_is_enabled() \ + else _('Sistema de Apoio à Publicação de Leis e Normas') + + from sapl.base.models import CasaLegislativa + casa_legislativa = CasaLegislativa.objects.first() + if casa_legislativa: + verbose_name = casa_legislativa.nome + return { 'sapl_as_sapn': sapn_is_enabled(), - 'nome_sistema': _('Sistema de Apoio ao Processo Legislativo') - if not sapn_is_enabled() - else _('Sistema de Apoio à Publicação de Leis e Normas') + 'nome_sistema': verbose_name, + 'base_url': get_base_url(request), } diff --git a/sapl/settings.py b/sapl/settings.py index 5e379f861..b1c1abba5 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -194,6 +194,7 @@ CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 'LOCATION': '/var/tmp/django_cache', + 'OPTIONS': {"MAX_ENTRIES": 1000}, } } diff --git a/sapl/templates/base.html b/sapl/templates/base.html index 4bc85410c..de36fe06e 100644 --- a/sapl/templates/base.html +++ b/sapl/templates/base.html @@ -13,6 +13,14 @@