mirror of https://github.com/interlegis/sapl.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
38 lines
1.1 KiB
9 years ago
|
from crispy_forms.bootstrap import FormActions
|
||
9 years ago
|
from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit
|
||
10 years ago
|
from django.utils.translation import ugettext as _
|
||
|
|
||
|
|
||
|
def to_column(name_span):
|
||
10 years ago
|
fieldname, span = name_span
|
||
9 years ago
|
return Div(fieldname, css_class='col-md-%d' % span)
|
||
10 years ago
|
|
||
|
|
||
|
def to_row(names_spans):
|
||
9 years ago
|
return Div(*map(to_column, names_spans), css_class='row-fluid')
|
||
10 years ago
|
|
||
|
|
||
|
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
|
||
|
|
||
|
|
||
9 years ago
|
def form_actions(more=[], save_label=_('Salvar')):
|
||
9 years ago
|
return FormActions(
|
||
|
Submit('salvar', save_label, css_class='pull-right'), *more)
|
||
9 years ago
|
|
||
|
|
||
10 years ago
|
class SaplFormLayout(Layout):
|
||
|
|
||
|
def __init__(self, *fields):
|
||
9 years ago
|
buttons = form_actions(more=[
|
||
10 years ago
|
HTML('<a href="{{ view.cancel_url }}"'
|
||
9 years ago
|
' class="btn btn-inverse">%s</a>' % _('Cancelar'))])
|
||
9 years ago
|
_fields = list(to_fieldsets(fields)) + [to_row([(buttons, 12)])]
|
||
10 years ago
|
super(SaplFormLayout, self).__init__(*_fields)
|