def __call__(self): use_ajax = getattr(self, 'use_ajax', False) ajax_options = getattr(self, 'ajax_options', '{}') action = getattr(self, 'action', '') method = getattr(self, 'method', 'POST') formid = getattr(self, 'formid', 'deform') autocomplete = getattr(self, 'autocomplete', None) self.schema = self.schema.bind( request=self.request, context=self.context) form = self.form_class(self.schema, action=action, method=method, buttons=self.buttons, formid=formid, use_ajax=use_ajax, ajax_options=ajax_options, autocomplete=autocomplete) # XXX override autocomplete; should be part of deform_bootstrap form.widget.template = 'substanced:widget/templates/form.pt' self.before(form) reqts = form.get_widget_resources() result = None for button in form.buttons: if button.name in self.request.POST: success_method = getattr(self, '%s_success' % button.name) try: controls = self.request.POST.items() validated = form.validate(controls) result = success_method(validated) except deform.exception.ValidationFailure, e: fail = getattr(self, '%s_failure' % button.name, None) if fail is None: fail = self.failure result = fail(e) break
def __call__(self): use_ajax = getattr(self, 'use_ajax', False) ajax_options = getattr(self, 'ajax_options', '{}') self.schema = self.schema.bind(**self.get_bind_data()) form = self.form_class(self.schema, buttons=self.buttons, use_ajax=use_ajax, ajax_options=ajax_options) self.before(form) reqts = form.get_widget_resources() result = None for button in form.buttons: if button.name in self.request.POST: success_method = getattr(self, '%s_success' % button.name) try: controls = self.request.POST.items() validated = form.validate(controls) result = success_method(validated) except deform.exception.ValidationFailure as e: fail = getattr(self, '%s_failure' % button.name, None) if fail is None: fail = self.failure result = fail(e) break if result is None: result = self.show(form) if isinstance(result, dict): result['js_links'] = reqts['js'] result['css_links'] = reqts['css'] return result
def _build_form(self): use_ajax = getattr(self, 'use_ajax', False) ajax_options = getattr(self, 'ajax_options', '{}') action = getattr(self, 'action', '') method = getattr(self, 'method', 'POST') formid = getattr(self, 'formid', 'deform') autocomplete = getattr(self, 'autocomplete', None) request = self.request self.schema = self.schema.bind( request=request, context=self.context, # see substanced.schema.CSRFToken _csrf_token_=request.session.get_csrf_token(), ) form = self.form_class(self.schema, action=action, method=method, buttons=self.buttons, formid=formid, use_ajax=use_ajax, ajax_options=ajax_options, autocomplete=autocomplete) # XXX override autocomplete; should be part of deform #form.widget.template = 'substanced:widget/templates/form.pt' self.before(form) reqts = form.get_widget_resources() return form, reqts
def __call__(self): """ Prepares and render the form according to provided options. """ use_ajax = getattr(self, "use_ajax", False) ajax_options = getattr(self, "ajax_options", "{}") self.schema = self.schema.bind(**self.get_bind_data()) form = self.form_class(self.schema, buttons=self.buttons, use_ajax=use_ajax, ajax_options=ajax_options) self.before(form) reqts = form.get_widget_resources() result = None for button in form.buttons: if button.name in self.request.POST: success_method = getattr(self, "%s_success" % button.name) try: controls = self.request.POST.items() validated = form.validate(controls) result = success_method(validated) except deform.exception.ValidationFailure as e: fail = getattr(self, "%s_failure" % button.name, None) if fail is None: fail = self.failure result = fail(e) break if result is None: result = self.show(form) if isinstance(result, dict): result["js_links"] = reqts["js"] result["css_links"] = reqts["css"] return result
def __call__(self, ignore_buttons=False): """ Prepares and renders the form according to provided options. Upon receiving a ``POST`` request, this method will validate the request against the form instance. After validation, this calls a method based upon the name of the button used for form submission and whether the validation succeeded or failed. If the button was named ``save``, then :meth:`save_success` will be called on successful validation or :meth:`save_failure` will be called upon failure. An exception to this is when no such ``save_failure`` method is present; in this case, the fallback is :meth:`failure``. This button method call behaviour can be avoided by setting the ``ignore_buttons`` argument to this method to be ``True``. This is particularly useful when needing to return a response (eg a rendered form) from a button ``success`` or ``failure`` method. Without this option, attempting to re-render the form view from one of these methods will result in infinite recursion as the method calls itself. Returns a ``dict`` structure suitable for provision tog the given view. By default, this is the page template specified. """ form = self.prepare_form() reqts = form.get_widget_resources() result = None if not ignore_buttons: for button in form.buttons: if self.request.POST.get(button.name): success_method = getattr(self, '%s_success' % button.name) try: controls = self.request.POST.items() validated = form.validate(controls) result = success_method(validated) except deform.exception.ValidationFailure as e: fail = getattr(self, '%s_failure' % button.name, None) if fail is None: fail = self.failure result = fail(e) break if result is None: result = self.show(form) if isinstance(result, dict): result['js_links'] = reqts['js'] result['css_links'] = reqts['css'] return result
def __call__(self): """ Prepares and render the form according to provided options. Upon receiving a ``POST`` request, this method will validate the request against the form instance. After validation, this calls a method based upon the name of the button used for form submission and whether the validation succeeded or failed. If the button was named ``save``, then :meth:`save_success` will be called on successful validation or :meth:`save_failure` will be called upon failure. An exception to this is when no such ``save_failure`` method is present; in this case, the fallback is :meth:`failure``. Returns a ``dict`` structure suitable for provision tog the given view. By default, this is the page template specified """ use_ajax = getattr(self, 'use_ajax', False) ajax_options = getattr(self, 'ajax_options', '{}') self.schema = self.schema.bind(**self.get_bind_data()) form = self.form_class(self.schema, buttons=self.buttons, use_ajax=use_ajax, ajax_options=ajax_options, **dict(self.form_options)) self.before(form) reqts = form.get_widget_resources() result = None for button in form.buttons: if button.name in self.request.POST: success_method = getattr(self, '%s_success' % button.name) try: controls = self.request.POST.items() validated = form.validate(controls) result = success_method(validated) except deform.exception.ValidationFailure as e: fail = getattr(self, '%s_failure' % button.name, None) if fail is None: fail = self.failure result = fail(e) break if result is None: result = self.show(form) if isinstance(result, dict): result['js_links'] = reqts['js'] result['css_links'] = reqts['css'] return result
def _build_form(self): use_ajax = getattr(self, 'use_ajax', False) ajax_options = getattr(self, 'ajax_options', '{}') action = getattr(self, 'action', '') method = getattr(self, 'method', 'POST') formid = getattr(self, 'formid', 'deform') autocomplete = getattr(self, 'autocomplete', None) self.schema = self.schema.bind( request=self.request, context=self.context) form = self.form_class(self.schema, action=action, method=method, buttons=self.buttons, formid=formid, use_ajax=use_ajax, ajax_options=ajax_options, autocomplete=autocomplete) # XXX override autocomplete; should be part of deform #form.widget.template = 'substanced:widget/templates/form.pt' self.before(form) reqts = form.get_widget_resources() return form, reqts
def __call__(self): use_ajax = getattr(self, "use_ajax", False) ajax_options = getattr(self, "ajax_options", "{}") schema = self.schema.bind(request=self.request) form = self.form_class(schema, buttons=self.buttons, use_ajax=use_ajax, ajax_options=ajax_options) self.before(form) reqts = form.get_widget_resources() result = None for button in form.buttons: if button.name in self.request.POST: success_method = getattr(self, "%s_success" % button.name) try: controls = self.request.POST.items() validated = form.validate(controls) result = success_method(validated) except deform.exception.ValidationFailure, e: fail = getattr(self, "%s_failure" % button.name, None) if fail is None: fail = self.failure result = fail(e) break