From efe360fb8cc6e994fe526d6e16fa001e5b4461e7 Mon Sep 17 00:00:00 2001 From: Sesostris Vieira Date: Wed, 10 Oct 2012 20:03:33 +0000 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=B5es=20no=20tratamento=20de=20er?= =?UTF-8?q?ros=20da=20interface=20mobile,=20no=20m=C3=B3dulo=20de=20identi?= =?UTF-8?q?fica=C3=A7=C3=A3o=20de=20responsabilidades.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diagnosticos_categorias_form.js | 3 ++- sigi/apps/casas/models.py | 2 +- sigi/apps/contatos/models.py | 2 +- sigi/apps/diagnosticos/views.py | 19 +++++++++++++++---- .../diagnosticos_categoria_contatos_form.html | 6 +++--- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/media/js/diagnosticos/diagnosticos_categorias_form.js b/media/js/diagnosticos/diagnosticos_categorias_form.js index 7825d8c..f1e1219 100644 --- a/media/js/diagnosticos/diagnosticos_categorias_form.js +++ b/media/js/diagnosticos/diagnosticos_categorias_form.js @@ -22,7 +22,8 @@ $('#page').live('pageinit', function(event){ $("span.errors").html(""); if (data.mensagem == "erro") { for (var campo in data.erros) { - $("#"+ campo + " span").html(data.erros[campo].join('\n')) + error = $("#" + campo); + error.html(data.erros[campo].join('\n')); } } }, diff --git a/sigi/apps/casas/models.py b/sigi/apps/casas/models.py index 376507b..1df934e 100644 --- a/sigi/apps/casas/models.py +++ b/sigi/apps/casas/models.py @@ -239,7 +239,7 @@ class Funcionario(models.Model): nome.alphabetic_filter = True sexo = models.CharField(max_length=1, choices=SEXO_CHOICES, default="M") nota = models.CharField(max_length=70, null=True, blank=True) - email = models.EmailField('e-mail', null=True, blank=True) + email = models.CharField('e-mail', max_length=75, blank=True) telefones = generic.GenericRelation('contatos.Telefone') endereco = generic.GenericRelation('contatos.Endereco') cargo = models.CharField(max_length=100, null=True, blank=True) diff --git a/sigi/apps/contatos/models.py b/sigi/apps/contatos/models.py index 24b21c7..97a4c83 100644 --- a/sigi/apps/contatos/models.py +++ b/sigi/apps/contatos/models.py @@ -138,7 +138,7 @@ class Telefone(models.Model): class Meta: ordering = ('numero',) - unique_together = ('numero', 'tipo') +# unique_together = ('numero', 'tipo') def __unicode__(self): return unicode(self.numero) diff --git a/sigi/apps/diagnosticos/views.py b/sigi/apps/diagnosticos/views.py index aa85539..571905b 100644 --- a/sigi/apps/diagnosticos/views.py +++ b/sigi/apps/diagnosticos/views.py @@ -15,6 +15,7 @@ from sigi.apps.diagnosticos.models import Diagnostico, Categoria, Pergunta from sigi.apps.casas.models import Funcionario from sigi.apps.diagnosticos.forms import (DiagnosticoMobileForm, CasaLegislativaMobileForm, FuncionariosMobileForm) +from sigi.apps.contatos.models import Telefone from sigi.shortcuts import render_to_pdf @@ -172,11 +173,20 @@ def categoria_contatos(request, id_diagnostico): else: # Montando a estrutura das mensagens de erro no formato JSON resposta['mensagem'] = 'erro' - resposta['erros'].update(form.errors) + for key, value in form.errors.iteritems(): + resposta['erros'][form.prefix + '-' + key + '-errors'] = value + for form_telefones in form.telefones.forms: - for key, value in form_telefones.errors.iteritems(): - key = form_telefones.prefix + "-" + key - resposta['erros'][key] = value + if not form_telefones.is_valid(): + if (form_telefones.fields['id'].initial is not None + and form_telefones.fields['tipo'].initial == 'I' + and form_telefones.fields['numero'].initial is None): + Telefone.objects.get(pk=form_telefones.fields['id'].initial).delete() + resposta['erros'][form_telefones.prefix + "-id-errors"] = u'Este telefone foi excluĂ­do da base de dados' + else: + for key, value in form_telefones.errors.iteritems(): + key = form_telefones.prefix + "-id-errors" + resposta['erros'][key] = value json = simplejson.dumps(resposta) return HttpResponse(json, mimetype="application/json") @@ -222,6 +232,7 @@ def diagnostico_pdf(request, id_diagnostico): }) return render_to_pdf('diagnosticos/diagnostico_pdf.html', context) + #return render_to_response('diagnosticos/diagnostico_pdf.html', context) def graficos(request): categorias = Categoria.objects.all() diff --git a/sigi/templates/diagnosticos/diagnosticos_categoria_contatos_form.html b/sigi/templates/diagnosticos/diagnosticos_categoria_contatos_form.html index 11778da..0fdceb9 100644 --- a/sigi/templates/diagnosticos/diagnosticos_categoria_contatos_form.html +++ b/sigi/templates/diagnosticos/diagnosticos_categoria_contatos_form.html @@ -24,16 +24,16 @@
{{ field }} - +
{% endfor %}

Telefones

{% for form in form.telefones.forms %}
- {{ form.tipo }} {{ form.numero}} + {{ form.tipo }} {{ form.numero }} {% for field in form.hidden_fields %} {{ field }} - + {% endfor %}
{% endfor %}