diff --git a/sigi/apps/metas/views.py b/sigi/apps/metas/views.py index fb6c473..4336412 100644 --- a/sigi/apps/metas/views.py +++ b/sigi/apps/metas/views.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from django.http import HttpResponse +from django.core.exceptions import PermissionDenied from django.utils import simplejson from django.utils.datastructures import SortedDict from django.shortcuts import render_to_response @@ -12,10 +13,51 @@ from sigi.apps.convenios.models import Projeto, Convenio from sigi.apps.contatos.models import UnidadeFederativa from sigi.apps.casas.models import CasaLegislativa from sigi.apps.utils import to_ascii - +from apps.financeiro.models import Desembolso +from django.db.models.aggregates import Sum +from django.contrib.auth.decorators import user_passes_test, login_required from sigi.settings import MEDIA_ROOT + JSON_FILE_NAME = MEDIA_ROOT + 'apps/metas/map_data.json' +@login_required + +def dashboard(request): + if request.user.groups.filter(name__in=['SPDT-Servidores', 'SSPLF']).count() <= 0: + raise PermissionDenied + + desembolsos_max = 0 + matriz = SortedDict() + dados = SortedDict() + projetos = Projeto.objects.all() + meses = Desembolso.objects.dates('data', 'month', 'DESC')[:6] + colors = ['ffff00', 'cc7900', 'ff0000', '92d050', '006600', '0097cc', '002776', 'ae78d6', 'ff00ff', '430080', + '28d75c', '0000ff', 'fff200'] + + for date in reversed(meses): + mes_ano = '%s/%s' % (date.month, date.year) + dados[mes_ano] = 0 + + for p in projetos: + matriz[p.id] = (p.sigla, dados.copy()) + + g_desembolsos = {'labels': [], 'legends': [p.sigla for p in projetos], 'data': [], 'max': 0, 'coisa': [] } + for date in meses: + mes_ano = '%s/%s' % (date.month, date.year) + g_desembolsos['labels'].append(mes_ano) + data = {p.id: 0 for p in projetos} + for d in Desembolso.objects.filter(data__year=date.year, data__month=date.month).values('projeto').annotate(total_dolar=Sum('valor_dolar')): + data[d['projeto']] = int(d['total_dolar']) + if int(d['total_dolar']) > desembolsos_max: + desembolsos_max = int(d['total_dolar']) + p = Projeto.objects.get(pk=d['projeto']) + matriz[d['projeto']][1][mes_ano] += int(d['total_dolar']) + g_desembolsos['data'].append(data.values()) + + meses = ["%s/%s" % (m.month, m.year) for m in reversed(meses)] + 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 mapa(request): """ Mostra o mapa com filtros carregados com valores default diff --git a/sigi/templates/metas/dashboard.html b/sigi/templates/metas/dashboard.html new file mode 100644 index 0000000..6c0b909 --- /dev/null +++ b/sigi/templates/metas/dashboard.html @@ -0,0 +1,39 @@ +{% extends "admin/index.html" %} +{% load adminmedia %} + +{% block title %}SIGI{% endblock %} + +{% block extrahead %} + {{ block.super }} + +{% endblock %} + +{% block content_title %} +

Triggers e indicadores de progresso

+
+
+

Esta é a toolbar da changelist

+
+
+{% endblock %} + +{% block content %} +
+
+ + {% include "metas/snippets.html" %} + +
+
+{% endblock %} + +{% block sidebar %} + +{% endblock %} diff --git a/sigi/templates/metas/snippets.html b/sigi/templates/metas/snippets.html new file mode 100644 index 0000000..db58276 --- /dev/null +++ b/sigi/templates/metas/snippets.html @@ -0,0 +1,40 @@ +{% load charts %} + +{# ------------- Todas as metas ------------- #} +
+

Todas as metas

+

Estado das metas do contrato BID

+ + {% for meta in metas %} + + + + + + {% endfor %} +
{{ meta.titulo }} + + {{ meta.percentual_concluido }}%
+
+
 
Ruim
+
 
Preocupante
+
 
Bom
+
 
Atingido
+
+
+ +{# ------------- Evolução dos desembolsos ------------- #} +
+

Evolução dos desembolsos

+

Desembolsos últimos seis meses

+ +
+ +{% comment %} +{# ------------- Evolução dos desembolsos ------------- #} +
+

Todas as metas

+

Estado das metas do contrato BID

+
+{% endcomment %} \ No newline at end of file diff --git a/sigi/urls.py b/sigi/urls.py index 0bcc4cb..d9ed476 100644 --- a/sigi/urls.py +++ b/sigi/urls.py @@ -117,6 +117,7 @@ urlpatterns = patterns( (r'^sigi/dashboard/mapsearch/$', 'sigi.apps.metas.views.map_search'), (r'^sigi/dashboard/mapsum/$', 'sigi.apps.metas.views.map_sum'), (r'^sigi/dashboard/maplist/$', 'sigi.apps.metas.views.map_list'), + (r'^sigi/dashboard/$', 'sigi.apps.metas.views.dashboard'), # automatic interface based on admin #(r'^sigi/(.*)', sites.default.root), (r'^sigi/', include(sites.default.urls)),