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 %}