From ccc85785f772e2d736d6eaa99204030c36c67ba4 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 23 May 2016 15:06:54 -0300 Subject: [PATCH 1/3] Crud Casa Legislativa --- base/forms.py | 63 +---------------------- base/layouts.yaml | 10 ++++ base/urls.py | 9 ++-- base/views.py | 64 +++++++----------------- materia/urls.py | 2 +- templates/base/casa_leg_table_aux.html | 8 --- templates/base/casalegislativa_list.html | 38 ++++++++++++++ 7 files changed, 73 insertions(+), 121 deletions(-) delete mode 100644 templates/base/casa_leg_table_aux.html create mode 100644 templates/base/casalegislativa_list.html diff --git a/base/forms.py b/base/forms.py index 4d13f6adb..d8747b6af 100644 --- a/base/forms.py +++ b/base/forms.py @@ -14,7 +14,7 @@ from sapl.settings import MAX_IMAGE_UPLOAD_SIZE from .models import CasaLegislativa -class CasaLegislativaTabelaAuxForm(ModelForm): +class CasaLegislativaForm(ModelForm): class Meta: @@ -50,67 +50,6 @@ class CasaLegislativaTabelaAuxForm(ModelForm): raise ValidationError("Imagem muito grande. ( > 2mb )") return logotipo - def __init__(self, *args, **kwargs): - - row1 = crispy_layout_mixin.to_row( - [('codigo', 2), - ('nome', 5), - ('sigla', 5)]) - - row2 = crispy_layout_mixin.to_row( - [('endereco', 8), - ('cep', 4)]) - - row3 = crispy_layout_mixin.to_row( - [('municipio', 10), - ('uf', 2)]) - - row4 = crispy_layout_mixin.to_row( - [('telefone', 6), - ('fax', 6)]) - - row5 = crispy_layout_mixin.to_row( - [('logotipo', 12)]) - - row6 = crispy_layout_mixin.to_row( - [('endereco_web', 12)]) - - row7 = crispy_layout_mixin.to_row( - [('email', 12)]) - - row8 = crispy_layout_mixin.to_row( - [('informacao_geral', 12)]) - - self.helper = FormHelper() - self.helper.layout = Layout( - Fieldset( - _('Dados Básicos'), - row1, - row2, - row3, - row4, - row5, - HTML(""" -
- {% if not form.fotografia.errors and form.fotografia.value %} - -
- - {% endif %} -
"""), - row6, - row7, - row8, - form_actions() - ) - ) - super(CasaLegislativaTabelaAuxForm, self).__init__(*args, **kwargs) - class LoginForm(AuthenticationForm): username = forms.CharField(label="Username", max_length=30, diff --git a/base/layouts.yaml b/base/layouts.yaml index e69de29bb..0a377da6f 100644 --- a/base/layouts.yaml +++ b/base/layouts.yaml @@ -0,0 +1,10 @@ +CasaLegislativa: + Casa Legislativa: + - codigo:2 nome sigla + - endereco:8 cep + - municipio:10 uf + - telefone fax + - logotipo + - endereco_web + - email + - informacao_geral diff --git a/base/urls.py b/base/urls.py index 0a4caad73..a8692e18e 100644 --- a/base/urls.py +++ b/base/urls.py @@ -1,11 +1,11 @@ -from django.conf.urls import url +from django.conf.urls import include, url from django.contrib.auth import views from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.views.generic.base import TemplateView from .apps import AppConfig from .forms import LoginForm -from .views import CasaLegislativaTableAuxView, HelpView +from .views import CasaLegislativaCrud, HelpView app_name = AppConfig.name @@ -15,8 +15,9 @@ urlpatterns = [ url(r'^ajuda/(?P\w+)$', HelpView.as_view(), name='help_topic'), url(r'^ajuda/', TemplateView.as_view(template_name='ajuda/index.html'), name='help_base'), - url(r'^casa-legislativa$', - CasaLegislativaTableAuxView.as_view(), name='casa_legislativa'), + # url(r'^casa-legislativa$', + # CasaLegislativaTableAuxView.as_view(), name='casa_legislativa'), + url(r'^casa_legislativa/', include(CasaLegislativaCrud.get_urls())), url(r'^login/$', views.login, { 'template_name': 'base/login.html', 'authentication_form': LoginForm}, diff --git a/base/views.py b/base/views.py index 2e801a3c5..f7e68ea87 100644 --- a/base/views.py +++ b/base/views.py @@ -6,62 +6,34 @@ from django.core.urlresolvers import reverse from django.views.generic import FormView from django.views.generic.base import TemplateView -from .forms import CasaLegislativaTabelaAuxForm +import crud.base +from crud.base import Crud + +from .forms import CasaLegislativaForm from .models import CasaLegislativa -@lru_cache(maxsize=1) +# @lru_cache(maxsize=1) def get_casalegislativa(): return CasaLegislativa.objects.first() -class HelpView(TemplateView): - # XXX treat non existing template as a 404!!!! - - def get_template_names(self): - return ['ajuda/%s.html' % self.kwargs['topic']] - +class CasaLegislativaCrud(Crud): + model = CasaLegislativa + help_path = '' -class CasaLegislativaTableAuxView(FormView): + class BaseMixin(crud.base.CrudBaseMixin): + list_field_names = ['codigo', 'nome', 'sigla'] - template_name = "base/casa_leg_table_aux.html" + class CreateView(crud.base.CrudCreateView): + form_class = CasaLegislativaForm - def get(self, request, *args, **kwargs): - try: - casa = CasaLegislativa.objects.first() - except ObjectDoesNotExist: - form = CasaLegislativaTabelaAuxForm() - else: - form = CasaLegislativaTabelaAuxForm(instance=casa) + class UpdateView(crud.base.CrudUpdateView): + form_class = CasaLegislativaForm - return self.render_to_response({'form': form}) - def post(self, request, *args, **kwargs): - form = CasaLegislativaTabelaAuxForm(request.POST, request.FILES) - if form.is_valid(): - casa = CasaLegislativa.objects.first() - if casa: - if ("remover" in request.POST or - (form.cleaned_data['logotipo'] and casa.logotipo)): - try: - os.unlink(casa.logotipo.path) - except OSError: - pass # Should log this error!!!!! - casa.logotipo = None - CasaLegislativaTabelaAuxForm( - request.POST, - request.FILES, - instance=casa - ).save() - else: - form.save() - - # Invalida cache de consulta - get_casalegislativa.cache_clear() - - return self.form_valid(form) - else: - return self.render_to_response({'form': form}) +class HelpView(TemplateView): + # XXX treat non existing template as a 404!!!! - def get_success_url(self): - return reverse('base:casa_legislativa') + def get_template_names(self): + return ['ajuda/%s.html' % self.kwargs['topic']] diff --git a/materia/urls.py b/materia/urls.py index e53f6940c..1283164ce 100644 --- a/materia/urls.py +++ b/materia/urls.py @@ -30,7 +30,7 @@ urlpatterns = [ RelatoriaCrud.get_urls() + DocumentoAcessorioCrud.get_urls())), - url(r'proposicao/', include(ProposicaoCrud.get_urls())), + url(r'^proposicao/', include(ProposicaoCrud.get_urls())), # Integração com Compilação url(r'^materia/(?P[0-9]+)/ta$', diff --git a/templates/base/casa_leg_table_aux.html b/templates/base/casa_leg_table_aux.html deleted file mode 100644 index 3b59fbe57..000000000 --- a/templates/base/casa_leg_table_aux.html +++ /dev/null @@ -1,8 +0,0 @@ -{% extends "crud/detail.html" %} -{% load i18n %} -{% load crispy_forms_tags %} -{% block actions %} {% endblock %} - -{% block detail_content %} - {% crispy form %} -{% endblock detail_content %} diff --git a/templates/base/casalegislativa_list.html b/templates/base/casalegislativa_list.html new file mode 100644 index 000000000..223d33b1b --- /dev/null +++ b/templates/base/casalegislativa_list.html @@ -0,0 +1,38 @@ +{% extends "crud/list.html" %} +{% load i18n %} + +{% block base_content %} + {% if not rows %} +

{{ NO_ENTRIES_MSG }}

+ + {% else %} + + + + {% for name in headers %} + + {% endfor %} + + + + {% for value_list in rows %} + + {% for value, href in value_list %} + + {% endfor %} + + {% endfor %} + +
{{ name }}
+ {% if href %} + {{ value }} + {% else %} + {{ value|safe }} + {% endif %} +
+ {% endif %} +{% endblock %} From 4db60cc78e69561dd955e118aa7106b24cbafae3 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 23 May 2016 15:10:31 -0300 Subject: [PATCH 2/3] Fix qa --- base/forms.py | 6 ------ base/views.py | 7 ------- comissoes/tests/test_comissoes.py | 3 +-- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/base/forms.py b/base/forms.py index d8747b6af..9201aa666 100644 --- a/base/forms.py +++ b/base/forms.py @@ -1,14 +1,8 @@ -from crispy_forms.helper import FormHelper -from crispy_forms.layout import HTML, Fieldset, Layout from django import forms from django.contrib.auth.forms import AuthenticationForm from django.core.exceptions import ValidationError from django.forms import ModelForm -from django.utils.translation import ugettext_lazy as _ - -import crispy_layout_mixin import sapl -from crispy_layout_mixin import form_actions from sapl.settings import MAX_IMAGE_UPLOAD_SIZE from .models import CasaLegislativa diff --git a/base/views.py b/base/views.py index f7e68ea87..119e81d8b 100644 --- a/base/views.py +++ b/base/views.py @@ -1,9 +1,3 @@ -import os -from functools import lru_cache - -from django.core.exceptions import ObjectDoesNotExist -from django.core.urlresolvers import reverse -from django.views.generic import FormView from django.views.generic.base import TemplateView import crud.base @@ -13,7 +7,6 @@ from .forms import CasaLegislativaForm from .models import CasaLegislativa -# @lru_cache(maxsize=1) def get_casalegislativa(): return CasaLegislativa.objects.first() diff --git a/comissoes/tests/test_comissoes.py b/comissoes/tests/test_comissoes.py index bad7b45a1..8d05c0a80 100644 --- a/comissoes/tests/test_comissoes.py +++ b/comissoes/tests/test_comissoes.py @@ -2,8 +2,7 @@ import pytest from django.core.urlresolvers import reverse from model_mommy import mommy -from comissoes.models import (CargoComissao, Comissao, Composicao, - Participacao, Periodo, TipoComissao) +from comissoes.models import Comissao, Composicao, Periodo, TipoComissao from parlamentares.models import Filiacao, Parlamentar, Partido From 05026cfd33172261e3aa385b9ca4ffabfb24b030 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 23 May 2016 15:23:48 -0300 Subject: [PATCH 3/3] Muda url da casa na tabela auxiliar" --- base/urls.py | 3 +-- templates/sistema.html | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/base/urls.py b/base/urls.py index a8692e18e..94cd3979a 100644 --- a/base/urls.py +++ b/base/urls.py @@ -15,8 +15,7 @@ urlpatterns = [ url(r'^ajuda/(?P\w+)$', HelpView.as_view(), name='help_topic'), url(r'^ajuda/', TemplateView.as_view(template_name='ajuda/index.html'), name='help_base'), - # url(r'^casa-legislativa$', - # CasaLegislativaTableAuxView.as_view(), name='casa_legislativa'), + url(r'^casa_legislativa/', include(CasaLegislativaCrud.get_urls())), url(r'^login/$', views.login, { diff --git a/templates/sistema.html b/templates/sistema.html index a859ff5e9..06e6ac264 100644 --- a/templates/sistema.html +++ b/templates/sistema.html @@ -5,7 +5,7 @@

Configuração Inicial

Módulo Parlamentares