def init_object(self, args, kwargs): args, kwargs = super(BaseAttachmentView, self).init_object(args, kwargs) entity_id = kwargs.pop('entity_id', None) if entity_id is not None: self.entity = Entity.query.get(entity_id) if self.entity is None: raise BadRequest('No entity provided') if not is_support_attachments(self.entity): raise BadRequest('This entity is doesn\'t support attachments') extension = current_app.extensions['attachments'] self.Form = extension.manager(self.entity).Form actions.context['object'] = self.entity return args, kwargs
def is_support_attachments(self, obj): return attachments.is_support_attachments(obj)