diff --git a/comissoes/forms.py b/comissoes/forms.py index 3a55ea14d..14a300a15 100644 --- a/comissoes/forms.py +++ b/comissoes/forms.py @@ -2,7 +2,7 @@ from crispy_forms.helper import FormHelper from django import forms from django.utils.translation import ugettext as _ -from comissoes.models import Comissao, TipoComissao +from comissoes.models import TipoComissao from sapl.layout import SaplFormLayout @@ -13,7 +13,7 @@ class TipoComissaoForm(forms.ModelForm): exclude = [] def __init__(self, *args, **kwargs): - super(ComissaoForm, self).__init__(*args, **kwargs) + super(TipoComissaoForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = SaplFormLayout( @@ -26,39 +26,3 @@ class TipoComissaoForm(forms.ModelForm): [('nome', 6), ('sigla', 6)], [('dispositivo_regimental', 6), ('natureza', 6)]], ) - - -class ComissaoForm(forms.ModelForm): - - class Meta: - model = Comissao - exclude = [] - - def __init__(self, *args, **kwargs): - super(ComissaoForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - self.helper.layout = SaplFormLayout( - - [_('Dados Básicos'), - [('nome', 9), ('sigla', 3)], - [('tipo', 3), - ('data_criacao', 3), - ('unidade_deliberativa', 3), - ('data_extincao', 3)]], - - [_('Dados Complementares'), - [('local_reuniao', 4), - ('agenda_reuniao', 4), - ('telefone_reuniao', 4)], - [('endereco_secretaria', 4), - ('telefone_secretaria', 4), - ('fax_secretaria', 4)], - [('secretario', 4), ('email', 8)], - [('finalidade', 12)]], - - [_('Temporária'), - [('apelido_temp', 8), ('data_instalacao_temp', 4)], - [('data_final_prevista_temp', 4), - ('data_prorrogada_temp', 4), - ('data_fim_comissao', 4)]], - ) diff --git a/comissoes/views.py b/comissoes/views.py index dc1072842..8551b1b6f 100644 --- a/comissoes/views.py +++ b/comissoes/views.py @@ -1,5 +1,32 @@ -from .forms import ComissaoForm +from django.utils.translation import ugettext_lazy as _ + +from comissoes.models import Comissao from sapl.crud import build_crud -comissao_crud = build_crud(ComissaoForm) +comissao_crud = build_crud(Comissao, + + [_('Dados Básicos'), + [('nome', 9), ('sigla', 3)], + [('tipo', 3), + ('data_criacao', 3), + ('unidade_deliberativa', 3), + ('data_extincao', 3)]], + + [_('Dados Complementares'), + [('local_reuniao', 4), + ('agenda_reuniao', 4), + ('telefone_reuniao', 4)], + [('endereco_secretaria', 4), + ('telefone_secretaria', 4), + ('fax_secretaria', 4)], + [('secretario', 4), ('email', 8)], + [('finalidade', 12)]], + + [_('Temporária'), + [('apelido_temp', 8), + ('data_instalacao_temp', 4)], + [('data_final_prevista_temp', 4), + ('data_prorrogada_temp', 4), + ('data_fim_comissao', 4)]], + ) diff --git a/sapl/crud.py b/sapl/crud.py index 5a264defa..1c41dd597 100644 --- a/sapl/crud.py +++ b/sapl/crud.py @@ -1,19 +1,36 @@ from braces.views import FormMessagesMixin +from crispy_forms.helper import FormHelper +from django import forms from django.conf.urls import url from django.core.urlresolvers import reverse, reverse_lazy -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext as _ from django.views.generic import ( CreateView, DeleteView, ListView, UpdateView, DetailView) +from sapl.layout import SaplFormLayout + class Crud(object): pass -def build_crud(model_form): +def build_crud(model, *layout): crud = Crud() - crud.model = model_form._meta.model - crud.namespace = crud.model._meta.model_name + crud.model = model + crud.namespace = model._meta.model_name + + class CrispyForm(forms.ModelForm): + + class Meta: + model = crud.model + exclude = [] + + def __init__(self, *args, **kwargs): + super(CrispyForm, self).__init__(*args, **kwargs) + self.helper = FormHelper() + self.helper.layout = SaplFormLayout(*layout) + + crud.model_form = CrispyForm def in_namespace(url_name): return '%s:%s' % (crud.namespace, url_name) @@ -50,7 +67,7 @@ def build_crud(model_form): title = BaseMixin.verbose_name_plural class CrudCreateView(BaseMixin, FormMessagesMixin, CreateView): - form_class = model_form + form_class = crud.model_form title = _('Adicionar %(verbose_name)s') % { 'verbose_name': BaseMixin.verbose_name} form_valid_message = _('Registro criado com sucesso!') @@ -67,7 +84,7 @@ def build_crud(model_form): return self.get_object() class CrudUpdateView(BaseMixin, FormMessagesMixin, UpdateView): - form_class = model_form + form_class = crud.model_form form_valid_message = _('Registro alterado com sucesso!') form_invalid_message = make_form_invalid_message( _('Suas alterações não foram salvas.')) @@ -93,6 +110,7 @@ def build_crud(model_form): crud.CrudUpdateView = CrudUpdateView crud.CrudDeleteView = CrudDeleteView + # XXX transform into a property of Crud to enable override crud.urls = [ url(r'^$', CrudListView.as_view(), name='list'), url(r'^create$', CrudCreateView.as_view(), name='create'),