From 1f84e0077addabcc6cd246248a583bf8fd65f388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Wed, 2 Jun 2021 00:09:49 -0300 Subject: [PATCH] Novo mapa usando leaflet e openstreetmap --- sigi/apps/metas/templates/metas/openmap.html | 306 ++++++++++++++++++ .../metas/templates/metas/openmapdetail.html | 23 ++ sigi/apps/metas/urls.py | 5 +- sigi/apps/metas/views.py | 72 ++++- 4 files changed, 401 insertions(+), 5 deletions(-) create mode 100644 sigi/apps/metas/templates/metas/openmap.html create mode 100644 sigi/apps/metas/templates/metas/openmapdetail.html diff --git a/sigi/apps/metas/templates/metas/openmap.html b/sigi/apps/metas/templates/metas/openmap.html new file mode 100644 index 0000000..6f05c56 --- /dev/null +++ b/sigi/apps/metas/templates/metas/openmap.html @@ -0,0 +1,306 @@ +{% load admin_static bootstrapped_goodies_tags %} +{% load i18n %} + + + + {% trans 'SIGI' %} + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+

Filtros

+ Total de Órgãos selecionados: - +
+ +
+
+ {% for o in tipos_orgao %} +
+ + +
+ {% endfor %} +
+
+
+
+ +
+
+
+ + +
+ {% for s in tipos_servico %} +
+ + +
+ {% endfor %} +
+
+
+
+ +
+
+
+ + +
+ {% for c in tipos_convenio %} +
+ + +
+ {% endfor %} +
+
+
+
+ +
+
+ {% for s, n, ufs in regioes %} +
+ + +
+
+ {% for uf in ufs %} +
+ + +
+ {% endfor %} +
+ {% endfor %} +
+
+
+
+ +
+
+
+ + +
+ {% for g in gerentes %} +
+ + +
+ {% endfor %} +
+
+
+ {% comment %}
+
+
+
+
{% endcomment %} +
+
+
+
+ +
+ +
+ +
+ + + + diff --git a/sigi/apps/metas/templates/metas/openmapdetail.html b/sigi/apps/metas/templates/metas/openmapdetail.html new file mode 100644 index 0000000..4945662 --- /dev/null +++ b/sigi/apps/metas/templates/metas/openmapdetail.html @@ -0,0 +1,23 @@ +
+
+ {{ orgao.nome }} +
+
+ + + {% if orgao.data_instalacao %}{% endif %} + + {% if orgao.telefones.all %}{% endif %} + {% if orgao.email %}{% endif %} + {% if orgao.convenio_set.all %} + + {% endif %} + {% if orgao.servico_set.all %} + + {% endif %} + {% if orgao.gerentes_interlegis.all %} + + {% endif %} +
CNPJ{{ orgao.cnpj }}
Data de instalação{{ orgao.data_instalacao }}
Endereço
{{ orgao.logradouro }}, {{ orgao.bairro }}, {{ orgao.municipio.nome }}, {{ orgao.municipio.uf.sigla }}, CEP: {{ orgao.cep }}
Telefones{% for telefone in orgao.telefones.all %}{{ telefone.numero }}{% if not forloop.last %}, {% endif %}{% endfor %}
E-mail{{ orgao.email }}
Convênios{% for c in orgao.convenio_set.all %}{{ c }}{% if not forloop.last %}, {% endif %}{% endfor %}
Serviços{% for s in orgao.servico_set.all %}{% if s.url %}{{ s }}{% else %}{{ s }}{% endif %}{% if not forloop.last %}, {% endif %}{% endfor %}
Gerentes{% for g in orgao.gerentes_interlegis.all %}{{ g.nome_completo }}{% if not forloop.last %}, {% endif %} {% endfor %}
+
+
\ No newline at end of file diff --git a/sigi/apps/metas/urls.py b/sigi/apps/metas/urls.py index 3d89a57..9f5dcce 100644 --- a/sigi/apps/metas/urls.py +++ b/sigi/apps/metas/urls.py @@ -1,11 +1,14 @@ # coding: utf-8 from django.conf.urls import patterns, url - +from django.views.generic import TemplateView urlpatterns = patterns( 'sigi.apps.metas.views', url(r'^$', 'dashboard', name='metas-dashboardsss'), # tagerror + url(r'^openmap/$', 'openmap', name='openmap'), + url(r'^openmapdata/$', 'openmapdata', name='openmapdata'), + url(r'^openmapdetail/(?P\w+)/$', 'openmapdetail', name='openmapdetail'), url(r'^mapa/$', 'mapa', name='metas-mapa'), # tagerror url(r'^mapdata/$', 'map_data', name='metas-map_data'), url(r'^mapsearch/$', 'map_search', name='metas-map_search'), diff --git a/sigi/apps/metas/views.py b/sigi/apps/metas/views.py index 0cf636c..58b98a6 100644 --- a/sigi/apps/metas/views.py +++ b/sigi/apps/metas/views.py @@ -6,20 +6,21 @@ import time from functools import reduce from django.contrib.auth.decorators import login_required +from django.core import serializers from django.core.exceptions import PermissionDenied from django.db.models import Q from django.db.models.aggregates import Sum -from django.http import HttpResponse -from django.shortcuts import render, render_to_response +from django.http import HttpResponse, JsonResponse +from django.shortcuts import get_object_or_404, render, render_to_response from django.template import RequestContext from django.utils.datastructures import SortedDict from django.utils.translation import ugettext as _ from django.views.decorators.cache import cache_page from easy_thumbnails.templatetags.thumbnail import thumbnail_url -from sigi.apps.casas.models import Orgao +from sigi.apps.casas.models import Orgao, TipoOrgao from sigi.apps.contatos.models import UnidadeFederativa -from sigi.apps.convenios.models import Projeto +from sigi.apps.convenios.models import Convenio, Projeto from sigi.apps.financeiro.models import Desembolso from sigi.apps.servicos.models import TipoServico from sigi.apps.utils import to_ascii @@ -62,6 +63,69 @@ def dashboard(request): extra_context = {'desembolsos': matriz, 'desembolsos_max': desembolsos_max, 'meses': meses, 'colors': ','.join(colors[:len(matriz)])} return render_to_response('metas/dashboard.html', extra_context, context_instance=RequestContext(request)) +def openmap(request): + context = { + 'tipos_orgao': TipoOrgao.objects.filter(legislativo=True), + 'tipos_servico': TipoServico.objects.all(), + 'tipos_convenio': Projeto.objects.all(), + 'gerentes': Servidor.objects.exclude(casas_que_gerencia=None), + 'regioes': [(s, n, UnidadeFederativa.objects.filter(regiao=s)) + for s, n in UnidadeFederativa.REGIAO_CHOICES], + + } + return render(request, 'metas/openmap.html', context) + +def openmapdata(request): + tipos_orgao = request.GET.getlist('tipo_orgao', None) + tipos_servico = request.GET.getlist('tipo_servico', None) + tipos_convenio = request.GET.getlist('tipo_convenio', None) + ufs = request.GET.getlist('uf', None) + gerentes = request.GET.getlist('gerente', None) + reptype = request.GET.get('reptype', None) + + print reptype + print request.GET + + dados = Orgao.objects.all() + + if tipos_orgao: + dados = dados.filter(tipo__sigla__in=tipos_orgao) + else: + dados = dados.filter(tipo__legislativo=True) + + if tipos_servico: + if "none" in tipos_servico: + dados = dados.filter(servico=None) + else: + dados = dados.filter(servico__tipo_servico__sigla__in=tipos_servico) + + if tipos_convenio: + if "none" in tipos_convenio: + dados = dados.filter(convenio=None) + else: + dados = dados.filter(convenio__projeto__sigla__in=tipos_convenio) + + if ufs: + dados = dados.filter(municipio__uf__sigla__in=ufs) + + if gerentes: + if "none" in gerentes: + dados = dados.filter(gerentes_interlegis=None) + else: + dados = dados.filter(gerentes_interlegis__id__in=gerentes) + + dados = dados.distinct("nome") + + if not reptype: + dados = dados.values_list("id", "nome", "municipio__latitude", + "municipio__longitude") + return JsonResponse(list(dados), safe=False) + else: + return JsonResponse({'result': 'todo-feature'}) + +def openmapdetail(request, orgao_id): + orgao = get_object_or_404(Orgao, id=orgao_id) + return render(request, "metas/openmapdetail.html", {'orgao': orgao}) def mapa(request): """