From 90b6cd5d3180482ff96bef6f838c5c6a23c525e7 Mon Sep 17 00:00:00 2001 From: Sesostris Vieira Date: Mon, 14 Apr 2014 14:52:11 -0300 Subject: [PATCH] App de pesquisas para Planejamento e Fomento --- sigi/apps/pesquisas/__init__.py | 0 sigi/apps/pesquisas/admin.py | 15 ++ sigi/apps/pesquisas/forms.py | 11 ++ sigi/apps/pesquisas/models.py | 44 +++++ .../templates/admin/forms/change_form.html | 30 ++++ .../templates/admin/forms/entries.html | 167 ++++++++++++++++++ .../templates/email_extras/base.html | 3 + .../pesquisas/templates/email_extras/base.txt | 3 + .../templates/email_extras/form_response.html | 13 ++ .../templates/email_extras/form_response.txt | 9 + .../email_extras/form_response_copies.html | 5 + .../email_extras/form_response_copies.txt | 5 + .../templates/forms/form_detail.html | 17 ++ .../pesquisas/templates/forms/form_sent.html | 17 ++ .../templates/forms/includes/built_form.html | 11 ++ sigi/apps/pesquisas/templatetags/__init__.py | 0 .../templatetags/forms_builder_tags.py | 33 ++++ sigi/apps/pesquisas/tests.py | 3 + sigi/apps/pesquisas/urls.py | 9 + sigi/apps/pesquisas/views.py | 15 ++ sigi/settings.py | 2 + sigi/urls.py | 1 + 22 files changed, 413 insertions(+) create mode 100644 sigi/apps/pesquisas/__init__.py create mode 100644 sigi/apps/pesquisas/admin.py create mode 100644 sigi/apps/pesquisas/forms.py create mode 100644 sigi/apps/pesquisas/models.py create mode 100644 sigi/apps/pesquisas/templates/admin/forms/change_form.html create mode 100644 sigi/apps/pesquisas/templates/admin/forms/entries.html create mode 100644 sigi/apps/pesquisas/templates/email_extras/base.html create mode 100644 sigi/apps/pesquisas/templates/email_extras/base.txt create mode 100644 sigi/apps/pesquisas/templates/email_extras/form_response.html create mode 100644 sigi/apps/pesquisas/templates/email_extras/form_response.txt create mode 100644 sigi/apps/pesquisas/templates/email_extras/form_response_copies.html create mode 100644 sigi/apps/pesquisas/templates/email_extras/form_response_copies.txt create mode 100644 sigi/apps/pesquisas/templates/forms/form_detail.html create mode 100644 sigi/apps/pesquisas/templates/forms/form_sent.html create mode 100644 sigi/apps/pesquisas/templates/forms/includes/built_form.html create mode 100644 sigi/apps/pesquisas/templatetags/__init__.py create mode 100644 sigi/apps/pesquisas/templatetags/forms_builder_tags.py create mode 100644 sigi/apps/pesquisas/tests.py create mode 100644 sigi/apps/pesquisas/urls.py create mode 100644 sigi/apps/pesquisas/views.py diff --git a/sigi/apps/pesquisas/__init__.py b/sigi/apps/pesquisas/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sigi/apps/pesquisas/admin.py b/sigi/apps/pesquisas/admin.py new file mode 100644 index 0000000..65ef533 --- /dev/null +++ b/sigi/apps/pesquisas/admin.py @@ -0,0 +1,15 @@ +# -*- 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 + +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 diff --git a/sigi/apps/pesquisas/forms.py b/sigi/apps/pesquisas/forms.py new file mode 100644 index 0000000..c4ba969 --- /dev/null +++ b/sigi/apps/pesquisas/forms.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- + +from sigi.forms_builder.forms.forms import FormForForm +from sigi.apps.pesquisas.models import Formulario, Resposta + +class PesquisaForm(FormForForm): + field_entry_model = Resposta + + class Meta(FormForForm.Meta): + model = Formulario + fields = ['casa_legislativa',] \ No newline at end of file diff --git a/sigi/apps/pesquisas/models.py b/sigi/apps/pesquisas/models.py new file mode 100644 index 0000000..7854b66 --- /dev/null +++ b/sigi/apps/pesquisas/models.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- + +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 sigi.apps.casas.models import CasaLegislativa +from sigi.apps.servidores.models import Servidor + +class Pesquisa(AbstractForm): + class Meta: + verbose_name = _("Pesquisa") + verbose_name_plural = _("Pesquisas") + +class Pergunta(AbstractField): + """ + Implements automated field ordering. + """ + + form = models.ForeignKey("Pesquisa", related_name="fields") + order = models.IntegerField(_("Order"), null=True, blank=True) + + class Meta(AbstractField.Meta): + ordering = ("order",) + + def save(self, *args, **kwargs): + if self.order is None: + self.order = self.form.fields.count() + super(Pergunta, self).save(*args, **kwargs) + + def delete(self, *args, **kwargs): + fields_after = self.form.fields.filter(order__gte=self.order) + 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") + #operador = models.ForeignKey(Servidor, verbose_name=u"Operador") + + 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/templates/admin/forms/change_form.html b/sigi/apps/pesquisas/templates/admin/forms/change_form.html new file mode 100644 index 0000000..a52c31b --- /dev/null +++ b/sigi/apps/pesquisas/templates/admin/forms/change_form.html @@ -0,0 +1,30 @@ +{% extends "admin/change_form.html" %} + +{% load i18n %} +{% load url from future %} + +{% block object-tools %} +{% if change %}{% if not is_popup %} + + +{% endif %}{% endif %} +{% endblock %} diff --git a/sigi/apps/pesquisas/templates/admin/forms/entries.html b/sigi/apps/pesquisas/templates/admin/forms/entries.html new file mode 100644 index 0000000..2513372 --- /dev/null +++ b/sigi/apps/pesquisas/templates/admin/forms/entries.html @@ -0,0 +1,167 @@ +{% extends "admin/base_site.html" %} + +{% load i18n %} + +{% block extrahead %} +{{ block.super }} + + + +{% endblock %} + +{% block breadcrumbs %} + +{% endblock %} + +{% block content %} +
+
+ {% csrf_token %} + + + + + + + {% for include_field, filter_field, filter_option_fields in entries_form %} + + + + + + + {% endfor %} + + + + + +
{% trans "Field" %}{% trans "Include" %}{% trans "Filter by" %}
{{ include_field.label_tag }}{{ include_field }}{{ filter_field }} +
+ {% for option_field in filter_option_fields %} + {{ option_field.label_tag }} {{ option_field }} + {% endfor %} +
+
+ + + +  
+ + + + {% if xlwt_installed %} + + {% endif %} + {% if submitted %} +
+

{% trans "Entries" %}

+ {% for row in entries_form.rows %} + {% if forloop.first %} + + + {% if can_delete_entries %} + + {% endif %} + {% for column in entries_form.columns %} + {{ column }} + {% endfor %} + + {% endif %} + + {% if can_delete_entries %} + + {% endif %} + {% for field in row %} + {% if not forloop.first %} + {{ field }} + {% endif %} + {% endfor %} + + {% if forloop.last %} +
+ +
+ + + {% if can_delete_entries %} + + + {% endif %} + {% endif %} + {% empty %} +

{% trans "No entries to display" %}

+ {% endfor %} + {% endif %} +
+
+{% endblock %} diff --git a/sigi/apps/pesquisas/templates/email_extras/base.html b/sigi/apps/pesquisas/templates/email_extras/base.html new file mode 100644 index 0000000..6030db4 --- /dev/null +++ b/sigi/apps/pesquisas/templates/email_extras/base.html @@ -0,0 +1,3 @@ +{% block main %}{% endblock %} + +
http://{{ request.get_host }} diff --git a/sigi/apps/pesquisas/templates/email_extras/base.txt b/sigi/apps/pesquisas/templates/email_extras/base.txt new file mode 100644 index 0000000..a8416a3 --- /dev/null +++ b/sigi/apps/pesquisas/templates/email_extras/base.txt @@ -0,0 +1,3 @@ +{% block main %}{% endblock %} + +http://{{ request.get_host }} diff --git a/sigi/apps/pesquisas/templates/email_extras/form_response.html b/sigi/apps/pesquisas/templates/email_extras/form_response.html new file mode 100644 index 0000000..96e1f73 --- /dev/null +++ b/sigi/apps/pesquisas/templates/email_extras/form_response.html @@ -0,0 +1,13 @@ +{% extends "email_extras/base.html" %} + +{% block main %} +{% if message %}

{{ message }}

{% endif %} + +{% for field, value in fields %} + + + + +{% endfor %} +
{{ field }}:{{ value|linebreaks }}
+{% endblock %} diff --git a/sigi/apps/pesquisas/templates/email_extras/form_response.txt b/sigi/apps/pesquisas/templates/email_extras/form_response.txt new file mode 100644 index 0000000..fb93bb5 --- /dev/null +++ b/sigi/apps/pesquisas/templates/email_extras/form_response.txt @@ -0,0 +1,9 @@ +{% extends "email_extras/base.txt" %} + +{% block main %}{% if message %} +{{ message }} + +{% endif %}{% for field, value in fields %} +{{ field }}: {{ value|safe }} +{% endfor %} +{% endblock %} diff --git a/sigi/apps/pesquisas/templates/email_extras/form_response_copies.html b/sigi/apps/pesquisas/templates/email_extras/form_response_copies.html new file mode 100644 index 0000000..c0c6852 --- /dev/null +++ b/sigi/apps/pesquisas/templates/email_extras/form_response_copies.html @@ -0,0 +1,5 @@ +{% extends "email_extras/form_response.html" %} + +{% block main %} +{{ block.super }} +{% endblock %} diff --git a/sigi/apps/pesquisas/templates/email_extras/form_response_copies.txt b/sigi/apps/pesquisas/templates/email_extras/form_response_copies.txt new file mode 100644 index 0000000..9ce9855 --- /dev/null +++ b/sigi/apps/pesquisas/templates/email_extras/form_response_copies.txt @@ -0,0 +1,5 @@ +{% extends "email_extras/form_response.txt" %} + +{% block main %} +{{ block.super }} +{% endblock %} diff --git a/sigi/apps/pesquisas/templates/forms/form_detail.html b/sigi/apps/pesquisas/templates/forms/form_detail.html new file mode 100644 index 0000000..3a160df --- /dev/null +++ b/sigi/apps/pesquisas/templates/forms/form_detail.html @@ -0,0 +1,17 @@ + +{% load forms_builder_tags %} + + + {{ form.title }} + + + + {% render_built_form form %} + diff --git a/sigi/apps/pesquisas/templates/forms/form_sent.html b/sigi/apps/pesquisas/templates/forms/form_sent.html new file mode 100644 index 0000000..847cadf --- /dev/null +++ b/sigi/apps/pesquisas/templates/forms/form_sent.html @@ -0,0 +1,17 @@ + + + + {{ form.title }} + + + +

{{ form.title }}

+ {% if form.response %} +

{{ form.response }}

+ {% endif %} + diff --git a/sigi/apps/pesquisas/templates/forms/includes/built_form.html b/sigi/apps/pesquisas/templates/forms/includes/built_form.html new file mode 100644 index 0000000..0d18fe1 --- /dev/null +++ b/sigi/apps/pesquisas/templates/forms/includes/built_form.html @@ -0,0 +1,11 @@ +

{{ form.title }}

+ {% if form.intro %} +

{{ form.intro }}

+ {% endif %} +
+ {% csrf_token %} + {{ form_for_form.as_p }} +
 
+ +
diff --git a/sigi/apps/pesquisas/templatetags/__init__.py b/sigi/apps/pesquisas/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sigi/apps/pesquisas/templatetags/forms_builder_tags.py b/sigi/apps/pesquisas/templatetags/forms_builder_tags.py new file mode 100644 index 0000000..d26181c --- /dev/null +++ b/sigi/apps/pesquisas/templatetags/forms_builder_tags.py @@ -0,0 +1,33 @@ +from django import template +from sigi.forms_builder.forms.templatetags.forms_builder_tags import BuiltFormNode +from sigi.apps.pesquisas.models import Pesquisa +from sigi.apps.pesquisas.forms import PesquisaForm + +register = template.Library() + +class BuiltPesquisaNode(BuiltFormNode): + form_class = Pesquisa + form_for_form_class = PesquisaForm + +@register.tag +def render_built_form(parser, token): + """ + render_build_form takes one argument in one of the following formats: + + {% render_build_form form_instance %} + {% render_build_form form=form_instance %} + {% render_build_form id=form_instance.id %} + {% render_build_form slug=form_instance.slug %} + + """ + try: + _, arg = token.split_contents() + if "=" not in arg: + arg = "form=" + arg + name, value = arg.split("=", 1) + if name not in ("form", "id", "slug"): + raise ValueError + except ValueError: + e = () + raise template.TemplateSyntaxError(render_built_form.__doc__) + return BuiltPesquisaNode(name, value) diff --git a/sigi/apps/pesquisas/tests.py b/sigi/apps/pesquisas/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/sigi/apps/pesquisas/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/sigi/apps/pesquisas/urls.py b/sigi/apps/pesquisas/urls.py new file mode 100644 index 0000000..136b8a4 --- /dev/null +++ b/sigi/apps/pesquisas/urls.py @@ -0,0 +1,9 @@ +from __future__ import unicode_literals + +from django.conf.urls import patterns, url + + +urlpatterns = patterns("apps.pesquisas.views", + url(r"(?P.*)/sent/$", "form_sent", name="form_sent"), + url(r"(?P.*)/$", "form_detail", name="form_detail"), +) diff --git a/sigi/apps/pesquisas/views.py b/sigi/apps/pesquisas/views.py new file mode 100644 index 0000000..7e8592d --- /dev/null +++ b/sigi/apps/pesquisas/views.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +from sigi.forms_builder.forms.views import FormDetail, FormSent +from sigi.apps.pesquisas.models import Pesquisa +from sigi.apps.pesquisas.forms import PesquisaForm + +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 diff --git a/sigi/settings.py b/sigi/settings.py index 748a6a0..da1b592 100644 --- a/sigi/settings.py +++ b/sigi/settings.py @@ -50,11 +50,13 @@ INSTALLED_APPS = ( 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django.contrib.sites', # Local apps 'sigi.apps.contatos', 'sigi.apps.servidores', 'sigi.apps.parlamentares', + 'sigi.apps.pesquisas', 'sigi.apps.mesas', 'sigi.apps.casas', 'sigi.apps.convenios', diff --git a/sigi/urls.py b/sigi/urls.py index 8789108..86f3713 100644 --- a/sigi/urls.py +++ b/sigi/urls.py @@ -17,6 +17,7 @@ urlpatterns = patterns('', url(r'^servidores/', include('sigi.apps.servidores.urls')), url(r'^servicos/', include('sigi.apps.servicos.urls')), url(r'^dashboard/', include('sigi.apps.metas.urls')), + url(r'^pesquisas/formulario/', include('sigi.apps.pesquisas.urls')), url(r'^', include(admin.site.urls)),