Browse Source

Add cache to header and fix QA

pull/153/head
Edward Ribeiro 9 years ago
parent
commit
1f1e7a1d9e
  1. 10
      base/views.py
  2. 4
      materia/views.py
  3. 9
      protocoloadm/views.py
  4. 9
      sapl/context_processors.py

10
base/views.py

@ -1,4 +1,5 @@
import os import os
from functools import lru_cache
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, ButtonHolder, Fieldset, Layout, Submit from crispy_forms.layout import HTML, ButtonHolder, Fieldset, Layout, Submit
@ -15,6 +16,11 @@ import sapl
from .models import CasaLegislativa from .models import CasaLegislativa
@lru_cache(maxsize=1)
def get_casalegislativa():
return CasaLegislativa.objects.first()
class HelpView(TemplateView): class HelpView(TemplateView):
# XXX treat non existing template as a 404!!!! # XXX treat non existing template as a 404!!!!
@ -199,6 +205,10 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView):
casa_save.save() casa_save.save()
else: else:
form.save() form.save()
# Invalida cache de consulta
get_casalegislativa.cache_clear()
return self.form_valid(form) return self.form_valid(form)
else: else:
return self.render_to_response({'form': form}) return self.render_to_response({'form': form})

4
materia/views.py

@ -1488,8 +1488,8 @@ class TramitacaoView(FormMixin, GenericView):
'error': 'A origem da nova tramitação \ 'error': 'A origem da nova tramitação \
deve ser igual ao destino da última adicionada!'}) deve ser igual ao destino da última adicionada!'})
corpo_email = ('A tramitação da matéria\ corpo_email = ('A tramitação da matéria %s foi alterada.' % materia
%s foi alterada.' % materia) )
destinatarios = AcompanharMateria.objects.values_list( destinatarios = AcompanharMateria.objects.values_list(
'email', flat=True).filter( 'email', flat=True).filter(
materia_cadastrada=materia) materia_cadastrada=materia)

9
protocoloadm/views.py

@ -2,7 +2,8 @@ from datetime import date, datetime
from re import sub from re import sub
from crispy_forms.helper import FormHelper 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 import forms
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
@ -330,8 +331,10 @@ class AnularProcoloAdmForm(forms.Form):
row2, row2,
HTML(" "), HTML(" "),
ButtonHolder(Submit('submit', 'Anular', ButtonHolder(Submit('submit', 'Anular',
css_class='button primary')) css_class='button primary'
) )
)
)
) )
super(AnularProcoloAdmForm, self).__init__( super(AnularProcoloAdmForm, self).__init__(
*args, **kwargs) *args, **kwargs)

9
sapl/context_processors.py

@ -1,10 +1,5 @@
from base.models import CasaLegislativa from base.views import get_casalegislativa
# TODO: this need to be cached and retrieved once!!!
def query_database():
return CasaLegislativa.objects.first()
def parliament_info(request): def parliament_info(request):
@ -21,7 +16,7 @@ def parliament_info(request):
'url_email': '#', 'url_email': '#',
} }
casa_legislativa = query_database() casa_legislativa = get_casalegislativa()
if casa_legislativa: if casa_legislativa:
context['parliament_type'] = casa_legislativa.nome context['parliament_type'] = casa_legislativa.nome

Loading…
Cancel
Save