Browse Source

Configura helper via get_form em CrispyLayoutFormMixin

pull/237/head
Marcio Mazza 9 years ago
parent
commit
58e7345466
  1. 29
      crispy_layout_mixin.py

29
crispy_layout_mixin.py

@ -1,7 +1,6 @@
from crispy_forms.bootstrap import FormActions from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit
from django import forms
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
@ -59,22 +58,18 @@ def get_field_display(obj, fieldname):
class CrispyLayoutFormMixin(object): class CrispyLayoutFormMixin(object):
def get_form_class(self): @property
def fields(self):
layout = self.layout '''Returns all fields in the layout'''
return [fieldname for legend_rows in self.layout
class CrispyForm(forms.ModelForm): for row in legend_rows[1:]
for fieldname, span in row]
class Meta:
model = self.model def get_form(self, form_class=None):
exclude = [] form = super(CrispyLayoutFormMixin, self).get_form(form_class)
form.helper = FormHelper()
def __init__(self, *args, **kwargs): form.helper.layout = SaplFormLayout(*self.layout)
super(CrispyForm, self).__init__(*args, **kwargs) return form
self.helper = FormHelper()
self.helper.layout = SaplFormLayout(*layout)
return CrispyForm
@property @property
def list_field_names(self): def list_field_names(self):

Loading…
Cancel
Save