From 60aca644d187347b68724c617b8d23393cd33b36 Mon Sep 17 00:00:00 2001 From: Sesostris Vieira Date: Thu, 1 Nov 2012 14:33:39 +0000 Subject: [PATCH] =?UTF-8?q?Mapa=20dos=20servi=C3=A7os=20SEIT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/servicos/views.py | 28 +++++++++ sigi/templates/servicos/mapa.html | 61 +++++++++++++++++++ .../snippets/modules/charts-convenios.html | 1 + sigi/urls.py | 5 +- 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 sigi/apps/servicos/views.py create mode 100644 sigi/templates/servicos/mapa.html diff --git a/sigi/apps/servicos/views.py b/sigi/apps/servicos/views.py new file mode 100644 index 0000000..73129f0 --- /dev/null +++ b/sigi/apps/servicos/views.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +from django.http import HttpResponse +from django.utils import simplejson +from django.db.models import Q +from sigi.apps.servicos.models import CasaAtendida + +def municipios_atendidos(self, servico): + municipios = [] + servico = servico.upper() + + query = Q() + + if servico != 'ALL': + for sigla in servico.split('_'): + query = query | Q(tipo_servico__sigla=sigla) + + query = Q(data_desativacao=None) & query + + for casa in CasaAtendida.objects.all(): + if casa.servico_set.filter(query).exists(): + m = casa.municipio + municipio = {'nome': casa.nome + ', ' + m.uf.sigla, + 'lat': str(m.latitude), + 'lng': str(m.longitude), + 'servicos': "",} + municipios.append(municipio) + + return HttpResponse(simplejson.dumps(municipios), mimetype="application/json") \ No newline at end of file diff --git a/sigi/templates/servicos/mapa.html b/sigi/templates/servicos/mapa.html new file mode 100644 index 0000000..71ed2dd --- /dev/null +++ b/sigi/templates/servicos/mapa.html @@ -0,0 +1,61 @@ +{% extends "admin/index.html" %} +{% load adminmedia %} + +{% block title %}SIGI{% endblock %} + +{% block extrahead %} + {{ block.super }} + + + + + +{% endblock %} + +{% block content %} +{% comment %} +
+
+{% for tipo in servicos %} + {{ tipo.nome }} +{% endfor %} +
+
+{% endcomment %} +
+{% endblock %} diff --git a/sigi/templates/snippets/modules/charts-convenios.html b/sigi/templates/snippets/modules/charts-convenios.html index 26460c3..3794c10 100644 --- a/sigi/templates/snippets/modules/charts-convenios.html +++ b/sigi/templates/snippets/modules/charts-convenios.html @@ -81,6 +81,7 @@ {% endif %} {% endfor %} +

Ver mapa

diff --git a/sigi/urls.py b/sigi/urls.py index 039f2c5..0a6cd2c 100644 --- a/sigi/urls.py +++ b/sigi/urls.py @@ -1,8 +1,9 @@ #-*- coding:utf-8 -*- from django.conf import settings from django.conf.urls.defaults import patterns, include, url -from django.views.generic.simple import redirect_to, direct_to_template +from django.views.generic.simple import redirect_to, direct_to_template import sites +from sigi.apps.servicos.models import TipoServico # register admin filters import admin.filterspecs @@ -90,6 +91,8 @@ urlpatterns = patterns( (r'^sigi/api/diagnosticos/$', 'sigi.apps.diagnosticos.views.grafico_api'), # Views dos serviços SEIT + (r'^sigi/servicos/mapa/(?P\w+)/$', direct_to_template, {'template': 'servicos/mapa.html', 'extra_context': {'servicos': TipoServico.objects.all()}}), + (r'^sigi/servicos/munatenjson/(?P\w+)/$', 'sigi.apps.servicos.views.municipios_atendidos'), # (r'^sigi/servicos/listacasas/(?P\w+)', # 'sigi.apps.servicos.views.casas_usam_servico'), # automatic interface based on admin