Browse Source

Use pentaho for Saberes dashboards

producao
Marcio Mazza 10 years ago
parent
commit
4473e9d865
  1. 1
      requirements/requirements.txt
  2. 9
      sigi/apps/home/templatetags/menu_conf.yaml
  3. 16
      sigi/apps/saberes/templates/saberes/dashboard.html
  4. 8
      sigi/apps/saberes/urls.py
  5. 61
      sigi/apps/saberes/views.py
  6. 10
      sigi/urls.py
  7. 5
      sigiStatic/css/base_site.css

1
requirements/requirements.txt

@ -16,4 +16,5 @@ psycopg2==2.5.4
python-memcached==1.53
PyYAML==3.11
reportlab==2.7
requests==2.7.0
six==1.9.0

9
sigi/apps/home/templatetags/menu_conf.yaml

@ -1,6 +1,4 @@
main_menu:
- title: Gráficos
url: ''
- title: Municípios
url: contatos/municipio/
children:
@ -95,3 +93,10 @@ main_menu:
children:
- title: Desembolsos
url: financeiro/desembolso/
- title: Saberes
url: '/'
children:
- title: Dashboard
url: saberes/dashboard/
- title: Cursos sem Tutoria
url: saberes/dashboard/cursos-sem-turoria/

16
sigi/apps/saberes/templates/saberes/dashboard.html

@ -1,20 +1,10 @@
{% extends "admin/base_site.html" %}
{% block extrastyle %}
{% block extrahead %}
{{ block.super }}
<style>
td.number {
text-align: right;
}
.panel-body {
max-height: 400px;
overflow: auto;
}
</style>
{{ headers|safe }}
{% endblock %}
{% block content %}
<div id="content-main">
{% include "saberes/snippets.html" %}
</div>
{{ content|safe }}
{% endblock %}

8
sigi/apps/saberes/urls.py

@ -1,9 +1,13 @@
# coding: utf-8
from django.conf.urls import patterns, url
from .views import cursos_sem_tutoria, dashboard, pentaho_proxy
urlpatterns = patterns(
'sigi.apps.saberes.views',
url(r'^dashboard/$', 'dashboard', name="saberes-dashboard-view"),
url(r'^dashboard/(?P<area>\w+)/$', 'detail', name="saberes-dashboard-detail"),
url(r'^dashboard/cursos-sem-turoria/?$', cursos_sem_tutoria, name="saberes-dashboard-detail"),
url(r'^dashboard/?$', dashboard, name="saberes-dashboard-view"),
url(r'^(?P<path>(plugin|api)/.*)$', pentaho_proxy),
)

61
sigi/apps/saberes/views.py

@ -1,31 +1,56 @@
# -*- coding: utf-8 -*-
from collections import OrderedDict
from django.utils.translation import ugettext as _
from django.db.models import Sum, Avg
import requests
from django.http import HttpResponse
from django.shortcuts import render, render_to_response, get_object_or_404
from django.template import RequestContext
from sigi.apps.mdl.models import User, CourseStats
from sigi.apps.saberes.models import CategoriasInteresse, PainelItem
from django.utils.translation import ugettext as _
from django.views.decorators.csrf import csrf_exempt
from requests.auth import HTTPBasicAuth
from sigi.apps.mdl.models import CourseStats
from sigi.apps.saberes.models import CategoriasInteresse
from sigi.settings import PENTAHO_SERVER, PENTAHO_DASHBOARDS, PENTAHO_USERNAME_PASSWORD
PENTAHO_CDF_URL = 'http://%s/pentaho/plugin/pentaho-cdf-dd/api/renderer/' % PENTAHO_SERVER
def get_dashboard_parts(dashboard_id, this_host):
params = PENTAHO_DASHBOARDS[dashboard_id]
params['root'] = this_host
return [requests.get(PENTAHO_CDF_URL + method,
params=params, auth=HTTPBasicAuth(*PENTAHO_USERNAME_PASSWORD)).content
for method in ('getHeaders', 'getContent')]
def make_dashboard(dashboard_id, adjust_content=lambda x: x):
def view(request):
headers, content = get_dashboard_parts(dashboard_id, request.META['HTTP_HOST'])
content = adjust_content(content)
return render(request, 'saberes/dashboard.html',
dict(headers=headers, content=content))
return view
def dashboard(request):
paineis = OrderedDict()
def use_to_container_fluid(content):
return content.replace("class='container'", "class='container-fluid'")
for p in PainelItem.objects.all():
if p.painel not in paineis:
paineis[p.painel] = {'titulo': p.painel, 'dados': []}
paineis[p.painel]['dados'].append(p)
for p in paineis:
try:
paineis[p]['area'] = CategoriasInteresse.objects.get(descricao=paineis[p]['titulo'])
except:
pass
dashboard = make_dashboard('saberes-geral')
cursos_sem_tutoria = make_dashboard('saberes-cursos-sem-tutoria', use_to_container_fluid)
extra_context = {'paineis': paineis}
return render_to_response('saberes/dashboard.html', extra_context, context_instance=RequestContext(request))
@csrf_exempt
def pentaho_proxy(request, path):
url = 'http://%s/pentaho/%s' % (PENTAHO_SERVER, path)
params = request.GET or request.POST
auth = HTTPBasicAuth(*PENTAHO_USERNAME_PASSWORD)
response = requests.get(url, params=params, auth=auth)
return HttpResponse(response.content,
status=response.status_code,
content_type=response.headers.get('Content-Type'))
def detail(request, area):

10
sigi/urls.py

@ -1,10 +1,13 @@
#-*- coding:utf-8 -*-
from django.conf.urls import patterns, include, url
from django.views.generic.base import TemplateView
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic.base import TemplateView
from sigi.apps.saberes.views import pentaho_proxy
admin.site.index_template = 'index.html'
admin.autodiscover()
@ -19,6 +22,7 @@ urlpatterns = patterns(
url(r'^servicos/', include('sigi.apps.servicos.urls')),
url(r'^saberes/', include('sigi.apps.saberes.urls')),
url(r'^dashboard/', include('sigi.apps.metas.urls')),
url(r'^pentaho/(?P<path>(plugin|api)/.*)$', pentaho_proxy),
url(r'^', include(admin.site.urls)),

5
sigiStatic/css/base_site.css

@ -6,11 +6,6 @@ a:hover {
color: #11488d;
}
/* HEADER */
#header {
background: #003351 url(../img/default-bg2.jpg);
}
#site-name a:hover {
text-decoration: none;
}

Loading…
Cancel
Save