def __call__(cls, sender, app, *args, **kw): """Decorate post handlers with a validator that references the appropriate webhook sender for this controller. """ if hasattr(cls, 'create'): cls.create = validate( cls.create_form(), error_handler=getattr(cls.index, '__func__', cls.index), )(cls.create) if hasattr(cls, 'edit'): cls.edit = validate( cls.edit_form(sender, app), error_handler=getattr(cls._default, '__func__', cls._default), )(cls.edit) return type.__call__(cls, sender, app, *args, **kw)
def __call__(cls, sender, app, *args, **kw): """Decorate post handlers with a validator that references the appropriate webhook sender for this controller. """ if hasattr(cls, 'create'): cls.create = validate( cls.create_form(), error_handler=cls.index.__func__, )(cls.create) if hasattr(cls, 'edit'): cls.edit = validate( cls.edit_form(sender, app), error_handler=cls._default.__func__, )(cls.edit) return type.__call__(cls, sender, app, *args, **kw)
def __call__(cls, importer, *args, **kw): """ Decorate the `create` post handler with a validator that references the appropriate App for this controller's importer. """ if hasattr(cls, 'create') and getattr(cls.create.decoration, 'validation', None) is None: cls.create = validate(cls.import_form(aslist(importer.target_app)[0]), error_handler=cls.index.__func__)(cls.create) return type.__call__(cls, importer, *args, **kw)
def __new__(cls, name, form): ''' Set up validation dynamically ''' instance = SettingsBaseController.__new__(cls) instance.form = form update = instance.update.im_func index = instance.index.im_func update = validate(form=form, error_handler=index)(update) update = types.MethodType(update, instance, cls) instance.update = update return instance