From a678cd25f2e1b9a477f17bb756ce7ebf0d6d7764 Mon Sep 17 00:00:00 2001 From: Gilson Filho Date: Wed, 30 Nov 2011 19:23:52 +0000 Subject: [PATCH] =?UTF-8?q?Definindo=20o=20tempo=20para=20cachear=20as=20p?= =?UTF-8?q?aginas=20de=20detalhes=20da=20categoria,=20para=20que=20ao=20da?= =?UTF-8?q?r=20um=20atualizar=20na=20p=C3=A1gina,=20os=20dados=20salvos=20?= =?UTF-8?q?via=20AJAX=20sejam=20trazidos,=20ao=20inv=C3=A9s=20de=20ir=20ao?= =?UTF-8?q?=20cache=20e=20trazer=20informa=C3=A7=C3=B5es=20j=C3=A1=20desat?= =?UTF-8?q?ualizados.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/casas/forms.py | 6 +++++- sigi/apps/diagnosticos/forms.py | 7 ++++--- sigi/apps/diagnosticos/views.py | 15 +++++++++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/sigi/apps/casas/forms.py b/sigi/apps/casas/forms.py index d300b4f..603fbed 100644 --- a/sigi/apps/casas/forms.py +++ b/sigi/apps/casas/forms.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- from django import forms -from django.contrib.localflavor.br.forms import BRCNPJField, BRZipCodeField +from django.contrib.localflavor.br.forms import BRZipCodeField from sigi.apps.casas.models import CasaLegislativa + class CasaLegislativaForm(forms.ModelForm): #cnpj = BRCNPJField( # label='CNPJ', @@ -14,3 +15,6 @@ class CasaLegislativaForm(forms.ModelForm): class Meta: model = CasaLegislativa + + def clean(self): + print self.cleaned_data['bairro'] diff --git a/sigi/apps/diagnosticos/forms.py b/sigi/apps/diagnosticos/forms.py index dab2281..9118829 100644 --- a/sigi/apps/diagnosticos/forms.py +++ b/sigi/apps/diagnosticos/forms.py @@ -7,6 +7,7 @@ from sigi.apps.casas.models import CasaLegislativa, Funcionario from sigi.apps.diagnosticos.models import Diagnostico from eav.forms import BaseDynamicEntityForm + class DiagnosticoForm(BaseDynamicEntityForm): """Classe responsável por contruir o formulário, vinculando ao modelo Diagnostico @@ -69,7 +70,7 @@ class DiagnosticoMobileForm(BaseDynamicEntityForm): defaults.update({'queryset': schema.get_choices(), 'initial': choice.pk if choice else None, # if schema is required remove --------- from ui - 'empty_label' : None if schema.required else u"---------"}) + 'empty_label': None if schema.required else u"---------"}) extra = self.FIELD_EXTRA.get(datatype, {}) if hasattr(extra, '__call__'): @@ -84,14 +85,14 @@ class DiagnosticoMobileForm(BaseDynamicEntityForm): if value and not datatype in (schema.TYPE_ONE, schema.TYPE_MANY): # choices are already done above self.initial[schema.name] = value + class CasaLegislativaMobileForm(forms.ModelForm): - pass class Meta: model = CasaLegislativa fields = ('cnpj', 'logradouro', 'bairro', 'cep', 'email', 'pagina_web') + class FuncionariosMobileForm(forms.ModelForm): - pass class Meta: model = Funcionario fields = ('nome', 'email', 'cargo', 'funcao', 'tempo_de_servico') diff --git a/sigi/apps/diagnosticos/views.py b/sigi/apps/diagnosticos/views.py index fbdcd7e..d090090 100644 --- a/sigi/apps/diagnosticos/views.py +++ b/sigi/apps/diagnosticos/views.py @@ -2,7 +2,7 @@ from django.shortcuts import render_to_response from django.template import RequestContext -from django.core.urlresolvers import reverse +from django.views.decorators.cache import cache_page from sigi.apps.utils.decorators import login_required from sigi.apps.diagnosticos.models import Diagnostico, Categoria @@ -38,6 +38,7 @@ def categorias(request, id_diagnostico): context) +@cache_page(5) @login_required(login_url='/mobile/diagnosticos/login') def categoria_detalhes(request, id_diagnostico, id_categoria): """Captura as perguntas da categoria @@ -51,7 +52,7 @@ def categoria_detalhes(request, id_diagnostico, id_categoria): context = RequestContext(request) return render_to_response('mobile/404.html', {}) - if request.method =="POST": + if request.method == "POST": form = DiagnosticoMobileForm(request.POST, instance=diagnostico, category=id_categoria) if form.is_valid(): @@ -65,6 +66,9 @@ def categoria_detalhes(request, id_diagnostico, id_categoria): return render_to_response('diagnosticos/diagnosticos_categorias_form.html', context) + +@cache_page(5) +@login_required(login_url='/mobile/diagnosticos/login') def categoria_casa_legislativa(request, id_diagnostico): try: diagnostico = Diagnostico.objects.get(pk=id_diagnostico) @@ -73,10 +77,10 @@ def categoria_casa_legislativa(request, id_diagnostico): context = RequestContext(request) return render_to_response('mobile/404.html', {}) - if request.method =="POST": + if request.method == "POST": form = CasaLegislativaMobileForm(request.POST, instance=casa_legislativa) if form.is_valid(): - form.save() + form.save() else: form = CasaLegislativaMobileForm(instance=casa_legislativa) @@ -85,6 +89,9 @@ def categoria_casa_legislativa(request, id_diagnostico): return render_to_response('diagnosticos/diagnosticos_categoria_casa_legislativa_form.html', context) + +@cache_page(5) +@login_required(login_url='/mobile/diagnosticos/login') def categoria_contatos(request, id_diagnostico): try: diagnostico = Diagnostico.objects.get(pk=id_diagnostico)