mirror of https://github.com/interlegis/sapl.git
Marcio Mazza
10 years ago
4 changed files with 82 additions and 16 deletions
@ -0,0 +1,41 @@ |
|||
from crispy_forms.helper import FormHelper |
|||
from django import forms |
|||
from django.utils.translation import ugettext as _ |
|||
|
|||
from comissoes.models import Comissao |
|||
from sapl.layout import SaplFormLayout |
|||
|
|||
|
|||
class ComissaoForm(forms.ModelForm): |
|||
|
|||
class Meta: |
|||
model = Comissao |
|||
fields = [f.name for f in Comissao._meta.fields] |
|||
|
|||
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)]], |
|||
) |
@ -0,0 +1,37 @@ |
|||
from crispy_forms.bootstrap import FormActions |
|||
from crispy_forms.layout import Submit, Reset, Layout, Div, Fieldset |
|||
from django.utils.translation import ugettext as _ |
|||
|
|||
|
|||
def to_column(name_span): |
|||
try: |
|||
fieldname, span = name_span |
|||
except: |
|||
return name_span |
|||
else: |
|||
return Div(fieldname, css_class='col-xs-%d' % span) |
|||
|
|||
|
|||
def to_row(names_spans): |
|||
return Div(*list(map(to_column, names_spans)), css_class='row-fluid') |
|||
|
|||
|
|||
def to_fieldsets(fields): |
|||
for field in fields: |
|||
if isinstance(field, list): |
|||
legend, *row_specs = field |
|||
rows = [to_row(name_span_list) for name_span_list in row_specs] |
|||
yield Fieldset(legend, *rows) |
|||
else: |
|||
yield field |
|||
|
|||
|
|||
class SaplFormLayout(Layout): |
|||
|
|||
def __init__(self, *fields): |
|||
_fields = list(to_fieldsets(fields)) + [ |
|||
FormActions( |
|||
Submit('save', _('Save'), css_class='btn btn-primary '), |
|||
Reset('reset', _('Cancel'), css_class='btn')) |
|||
] |
|||
super(SaplFormLayout, self).__init__(*_fields) |
@ -1,22 +1,11 @@ |
|||
{% extends "base.html" %} |
|||
{% load i18n bootstrap3 %} |
|||
{% load i18n bootstrap3 crispy_forms_tags %} |
|||
|
|||
{% block title %}SAPL{% endblock %} |
|||
|
|||
{% block content %} |
|||
<div id="content-main"> |
|||
{# Display a form #} |
|||
<form method="post" class="form"> |
|||
{% csrf_token %} |
|||
|
|||
{% bootstrap_form form %} |
|||
|
|||
{% buttons %} |
|||
<button type="submit" class="btn btn-primary"> |
|||
{% bootstrap_icon "star" %} Submit |
|||
</button> |
|||
{% endbuttons %} |
|||
</form> |
|||
{% crispy form %} |
|||
</div> |
|||
{% endblock %} |
|||
|
|||
|
Loading…
Reference in new issue