Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FlexiForm(forms.Form):
- def set_fields(self):
- for (f_name, attributes) in self._thefields.items():
- for (att_name, att_value) in attributes.items():
- setattr(self._theinstance.fields[f_name], att_name, att_value)
- def __init__(self, form, args=None, kwargs=None, fields=None):
- self._theform = form
- self._theargs = args or []
- self._thekwargs = kwargs or {}
- self._thefields = fields or {}
- self.bind()
- # !: make it possible to use kwargs here
- def bind(self, *args):
- self._theinstance = self._theform(*(list(args) + self._theargs), **self._thekwargs)
- self.set_fields()
- return self
- def __getattr__(self, name):
- return getattr(self._theinstance, name)
- def __setattr__(self, name, value):
- inst = self
- if name not in ['_theform', '_theargs', '_thekwargs', '_thefields', '_theinstance']:
- inst = self.__theinstance
- super(FlexiForm, inst).__setattr__(name, value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement