From 1f1e7a1d9ee778567591ba5ca0b5b0205b476a01 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Wed, 13 Jan 2016 16:55:08 -0200 Subject: [PATCH] Add cache to header and fix QA --- base/views.py | 10 ++++++++++ materia/views.py | 4 ++-- protocoloadm/views.py | 9 ++++++--- sapl/context_processors.py | 9 ++------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/base/views.py b/base/views.py index 9c0685eae..59dd2a43b 100644 --- a/base/views.py +++ b/base/views.py @@ -1,4 +1,5 @@ import os +from functools import lru_cache from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, ButtonHolder, Fieldset, Layout, Submit @@ -15,6 +16,11 @@ import sapl from .models import CasaLegislativa +@lru_cache(maxsize=1) +def get_casalegislativa(): + return CasaLegislativa.objects.first() + + class HelpView(TemplateView): # XXX treat non existing template as a 404!!!! @@ -199,6 +205,10 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView): casa_save.save() else: form.save() + + # Invalida cache de consulta + get_casalegislativa.cache_clear() + return self.form_valid(form) else: return self.render_to_response({'form': form}) diff --git a/materia/views.py b/materia/views.py index 54b032e16..30506e878 100644 --- a/materia/views.py +++ b/materia/views.py @@ -1488,8 +1488,8 @@ class TramitacaoView(FormMixin, GenericView): 'error': 'A origem da nova tramitação \ deve ser igual ao destino da última adicionada!'}) - corpo_email = ('A tramitação da matéria\ - %s foi alterada.' % materia) + corpo_email = ('A tramitação da matéria %s foi alterada.' % materia + ) destinatarios = AcompanharMateria.objects.values_list( 'email', flat=True).filter( materia_cadastrada=materia) diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 2c274d18c..03265372f 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -2,7 +2,8 @@ from datetime import date, datetime from re import sub from crispy_forms.helper import FormHelper -from crispy_forms.layout import ButtonHolder, HTML, Field, Fieldset, Layout, Submit +from crispy_forms.layout import (HTML, ButtonHolder, Field, Fieldset, Layout, + Submit) from django import forms from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse @@ -330,8 +331,10 @@ class AnularProcoloAdmForm(forms.Form): row2, HTML(" "), ButtonHolder(Submit('submit', 'Anular', - css_class='button primary')) - ) + css_class='button primary' + ) + ) + ) ) super(AnularProcoloAdmForm, self).__init__( *args, **kwargs) diff --git a/sapl/context_processors.py b/sapl/context_processors.py index 1adf9890a..d21d67d50 100644 --- a/sapl/context_processors.py +++ b/sapl/context_processors.py @@ -1,10 +1,5 @@ -from base.models import CasaLegislativa - - -# TODO: this need to be cached and retrieved once!!! -def query_database(): - return CasaLegislativa.objects.first() +from base.views import get_casalegislativa def parliament_info(request): @@ -21,7 +16,7 @@ def parliament_info(request): 'url_email': '#', } - casa_legislativa = query_database() + casa_legislativa = get_casalegislativa() if casa_legislativa: context['parliament_type'] = casa_legislativa.nome