Browse Source

Definindo o tempo para cachear as paginas de detalhes da categoria, para que ao dar um atualizar na página, os dados salvos via AJAX sejam trazidos, ao invés de ir ao cache e trazer informações já desatualizados.

diagnosticos
Gilson Filho 13 years ago
parent
commit
a678cd25f2
  1. 6
      sigi/apps/casas/forms.py
  2. 7
      sigi/apps/diagnosticos/forms.py
  3. 13
      sigi/apps/diagnosticos/views.py

6
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']

7
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')

13
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,7 +77,7 @@ 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()
@ -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)

Loading…
Cancel
Save