diff --git a/base/forms.py b/base/forms.py index 4d13f6adb..9201aa666 100644 --- a/base/forms.py +++ b/base/forms.py @@ -1,20 +1,14 @@ -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 -class CasaLegislativaTabelaAuxForm(ModelForm): +class CasaLegislativaForm(ModelForm): class Meta: @@ -50,67 +44,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..94cd3979a 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,8 @@ 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, { 'template_name': 'base/login.html', 'authentication_form': LoginForm}, diff --git a/base/views.py b/base/views.py index 2e801a3c5..119e81d8b 100644 --- a/base/views.py +++ b/base/views.py @@ -1,67 +1,32 @@ -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 -from .forms import CasaLegislativaTabelaAuxForm +import crud.base +from crud.base import Crud + +from .forms import CasaLegislativaForm from .models import CasaLegislativa -@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 CasaLegislativaTableAuxView(FormView): +class CasaLegislativaCrud(Crud): + model = CasaLegislativa + help_path = '' - template_name = "base/casa_leg_table_aux.html" + class BaseMixin(crud.base.CrudBaseMixin): + list_field_names = ['codigo', 'nome', 'sigla'] - def get(self, request, *args, **kwargs): - try: - casa = CasaLegislativa.objects.first() - except ObjectDoesNotExist: - form = CasaLegislativaTabelaAuxForm() - else: - form = CasaLegislativaTabelaAuxForm(instance=casa) + class CreateView(crud.base.CrudCreateView): + form_class = CasaLegislativaForm - return self.render_to_response({'form': form}) + class UpdateView(crud.base.CrudUpdateView): + form_class = CasaLegislativaForm - 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/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 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 %} 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