From 845038b50130a9a3863e6d22dd75426a6bad6f99 Mon Sep 17 00:00:00 2001 From: Gilson Filho Date: Thu, 1 Dec 2011 19:20:44 +0000 Subject: [PATCH] Inserindo mensagem de erro via AJAX --- .../diagnosticos/diagnosticos_categorias_form.css | 5 +++++ .../diagnosticos/diagnosticos_categorias_form.js | 11 +++++++++-- setup.sh | 15 ++++++++++++++- sigi/apps/diagnosticos/decorators.py | 4 ++++ sigi/apps/diagnosticos/views.py | 9 ++------- .../diagnosticos_categorias_form.html | 1 + 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/media/css/diagnosticos/diagnosticos_categorias_form.css b/media/css/diagnosticos/diagnosticos_categorias_form.css index a7dec81..0632557 100644 --- a/media/css/diagnosticos/diagnosticos_categorias_form.css +++ b/media/css/diagnosticos/diagnosticos_categorias_form.css @@ -2,3 +2,8 @@ width: 80%; display: inline-block; } + +span.errors { + display: block; + color: red; +} diff --git a/media/js/diagnosticos/diagnosticos_categorias_form.js b/media/js/diagnosticos/diagnosticos_categorias_form.js index 9da8d09..9fbca4c 100644 --- a/media/js/diagnosticos/diagnosticos_categorias_form.js +++ b/media/js/diagnosticos/diagnosticos_categorias_form.js @@ -4,11 +4,18 @@ $('#page').live('pageinit', function(event){ url: $(location).attr('href'), cache: false, type: 'POST', - success: function() { + success: function(data) { + //Retirando o span existente + $("span.errors").html(""); + if (data.mensagem == "erro") { + for (var campo in data.erros) { + $("#"+ campo + " span").html(data.erros[campo].join('\n')) + } + } }, error: function(msg) { $("#open-dialog").click() - } + }, }); // remove a resposta vazia da interface diff --git a/setup.sh b/setup.sh index f7e6104..0d1cdfb 100755 --- a/setup.sh +++ b/setup.sh @@ -19,7 +19,6 @@ requirements="requirements.txt" easy_install=`find /usr/bin/ -name easy_install` pip=`find /usr/bin/ -name pip` git=`find /usr/bin/ -name git` - if [ ! -f $easy_install ] || [ ! -f $pip ]; then echo "O aplicativo pip é obrigatório. Favor instalar para continuar a configuração do SIGI." @@ -54,6 +53,20 @@ else sleep 2 cd django-googlecharts python setup.py install + + # Instalando o django-geraldo + echo + echo "Fazendo o checkout do projeto django-geraldo..." + echo + sleep 2 + git clone https://github.com/marinho/geraldo.git + + echo + echo "Instalando o django-geraldo..." + echo + cd geraldo + python setup.py install + cp -Rvf reporting geraldo /usr/local/lib/python2.7/site-packages fi else echo diff --git a/sigi/apps/diagnosticos/decorators.py b/sigi/apps/diagnosticos/decorators.py index 776299f..39b909e 100644 --- a/sigi/apps/diagnosticos/decorators.py +++ b/sigi/apps/diagnosticos/decorators.py @@ -1,8 +1,12 @@ # -*- coding: utf8 -*- +from django.template import RequestContext +from django.shortcuts import render_to_response + from sigi.apps.diagnosticos.models import Diagnostico from sigi.apps.servidores.models import Servidor + def validate_diagnostico(func): def decorator(request, id_diagnostico, *args, **kwargs): """ Retorna 404 caso o diagnostico esteja publicado diff --git a/sigi/apps/diagnosticos/views.py b/sigi/apps/diagnosticos/views.py index 9f7a30e..a3a929c 100644 --- a/sigi/apps/diagnosticos/views.py +++ b/sigi/apps/diagnosticos/views.py @@ -76,15 +76,10 @@ def categoria_detalhes(request, id_diagnostico, id_categoria): if form.is_valid(): form.save() else: - erros = [] - for field in form: - if field.errors: - campo = field.name - erros.append(field.errors) + # Montando a estrutura das mensagens de erro no formato JSON resposta = { 'mensagem': 'erro', - 'campo': campo, - 'erros': erros + 'erros': form.errors } json = simplejson.dumps(resposta) print json diff --git a/sigi/templates/diagnosticos/diagnosticos_categorias_form.html b/sigi/templates/diagnosticos/diagnosticos_categorias_form.html index 703621a..4035e66 100644 --- a/sigi/templates/diagnosticos/diagnosticos_categorias_form.html +++ b/sigi/templates/diagnosticos/diagnosticos_categorias_form.html @@ -25,6 +25,7 @@
{{ field }} +
{% endfor %}