From b83391f7ce3ac5d10976b684baed99bf4537df8e Mon Sep 17 00:00:00 2001 From: Breno Teixeira Date: Wed, 23 Apr 2014 16:08:58 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=A3o=20dos=20imports=20da=20app?= =?UTF-8?q?=20forms=5Fbuilder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/metas/urls.py | 12 ++++---- sigi/apps/pesquisas/admin.py | 10 ++++--- sigi/apps/pesquisas/forms.py | 2 +- sigi/apps/pesquisas/models.py | 6 ++-- .../templatetags/forms_builder_tags.py | 2 +- sigi/apps/pesquisas/views.py | 30 +++++++++++++++---- 6 files changed, 43 insertions(+), 19 deletions(-) diff --git a/sigi/apps/metas/urls.py b/sigi/apps/metas/urls.py index e6a3107..a1c47a4 100644 --- a/sigi/apps/metas/urls.py +++ b/sigi/apps/metas/urls.py @@ -3,10 +3,10 @@ from django.conf.urls import patterns, url urlpatterns = patterns('sigi.apps.metas.views', - url(r'^$', 'dashboard', name='metas-dashboardsss'), #tagerror - 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'), - url(r'^mapsum/$', 'map_sum', name='metas-map_sum'), - url(r'^maplist/$', 'map_list', name='metas-map_list'), + url(r'^$', 'dashboard', name='metas-dashboardsss'), #tagerror + 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'), + url(r'^mapsum/$', 'map_sum', name='metas-map_sum'), + url(r'^maplist/$', 'map_list', name='metas-map_list'), ) \ No newline at end of file diff --git a/sigi/apps/pesquisas/admin.py b/sigi/apps/pesquisas/admin.py index 65ef533..feacc2d 100644 --- a/sigi/apps/pesquisas/admin.py +++ b/sigi/apps/pesquisas/admin.py @@ -1,15 +1,17 @@ -# -*- coding: utf-8 -*- - +# coding: utf-8 from django.contrib import admin -from sigi.forms_builder.forms.admin import FieldAdmin, FormAdmin from sigi.apps.pesquisas.models import Pesquisa, Pergunta, Formulario, Resposta +from forms_builder.forms.admin import FieldAdmin, FormAdmin + + class PerguntaAdmin(FieldAdmin): model = Pergunta + class PesquisaAdmin(FormAdmin): formentry_model = Formulario fieldentry_model = Resposta inlines = (PerguntaAdmin,) -admin.site.register(Pesquisa, PesquisaAdmin) \ No newline at end of file +admin.site.register(Pesquisa, PesquisaAdmin) diff --git a/sigi/apps/pesquisas/forms.py b/sigi/apps/pesquisas/forms.py index c4ba969..f529f33 100644 --- a/sigi/apps/pesquisas/forms.py +++ b/sigi/apps/pesquisas/forms.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from sigi.forms_builder.forms.forms import FormForForm +from forms_builder.forms.forms import FormForForm from sigi.apps.pesquisas.models import Formulario, Resposta class PesquisaForm(FormForForm): diff --git a/sigi/apps/pesquisas/models.py b/sigi/apps/pesquisas/models.py index 7854b66..d41d7d0 100644 --- a/sigi/apps/pesquisas/models.py +++ b/sigi/apps/pesquisas/models.py @@ -2,7 +2,7 @@ from django.db import models from django.utils.translation import ungettext, ugettext_lazy as _ -from sigi.forms_builder.forms.models import AbstractForm, AbstractField, AbstractFormEntry, AbstractFieldEntry +from forms_builder.forms.models import AbstractForm, AbstractField, AbstractFormEntry, AbstractFieldEntry from sigi.apps.casas.models import CasaLegislativa from sigi.apps.servidores.models import Servidor @@ -32,6 +32,7 @@ class Pergunta(AbstractField): fields_after.update(order=models.F("order") - 1) super(Pergunta, self).delete(*args, **kwargs) + class Formulario(AbstractFormEntry): form = models.ForeignKey("Pesquisa", related_name="entries") casa_legislativa = models.ForeignKey(CasaLegislativa, verbose_name=u"Casa legislativa") @@ -39,6 +40,7 @@ class Formulario(AbstractFormEntry): class Meta(AbstractFormEntry.Meta): unique_together = ('form', 'casa_legislativa') - + + class Resposta(AbstractFieldEntry): entry = models.ForeignKey("Formulario", related_name="fields") \ No newline at end of file diff --git a/sigi/apps/pesquisas/templatetags/forms_builder_tags.py b/sigi/apps/pesquisas/templatetags/forms_builder_tags.py index d26181c..4fc6468 100644 --- a/sigi/apps/pesquisas/templatetags/forms_builder_tags.py +++ b/sigi/apps/pesquisas/templatetags/forms_builder_tags.py @@ -1,5 +1,5 @@ from django import template -from sigi.forms_builder.forms.templatetags.forms_builder_tags import BuiltFormNode +from forms_builder.forms.templatetags.forms_builder_tags import BuiltFormNode from sigi.apps.pesquisas.models import Pesquisa from sigi.apps.pesquisas.forms import PesquisaForm diff --git a/sigi/apps/pesquisas/views.py b/sigi/apps/pesquisas/views.py index 6328f67..9a644fc 100644 --- a/sigi/apps/pesquisas/views.py +++ b/sigi/apps/pesquisas/views.py @@ -1,15 +1,35 @@ -# -*- coding: utf-8 -*- +# coding: utf-8 +from django.views.generic.base import TemplateView +from django.db.models import Count -from forms_builder.forms.views import FormDetail, FormSent -from sigi.apps.pesquisas.models import Pesquisa +from sigi.apps.pesquisas.models import Pesquisa, Pergunta, Resposta from sigi.apps.pesquisas.forms import PesquisaForm +from forms_builder.forms.views import FormDetail, FormSent + + class PesquisaDetail(FormDetail): form_class = Pesquisa form_for_form_class = PesquisaForm - + + class PesquisaSent(FormSent): form_class = Pesquisa form_detail = PesquisaDetail.as_view() -form_sent = PesquisaSent.as_view() \ No newline at end of file +form_sent = PesquisaSent.as_view() + + +class ChartView(TemplateView): + template_name = 'pesquisas/chart.html' + + def get_context_data(self, **kwargs): + context = super(ChartView, self).get_context_data(**kwargs) + field_id = self.kwargs['field_id'] + context['label'] = Pergunta.objects.filter(id=field_id) + dados = Resposta.objects.filter(field_id=field_id).values('value').annotate(total=Count('value')) + context['dados'] = dados + context['field_id'] = field_id + return context + +chart_view = ChartView.as_view() \ No newline at end of file