def test_commentable_interface() -> None: assert is_commentable(CommentableContent) instance = CommentableContent(name="test instance") assert not is_commentable(instance) # not in DB: no id instance.id = 42 assert is_commentable(instance) assert not is_commentable(object) assert not is_commentable(object())
def test_commentable_interface() -> None: assert is_commentable(CommentableContent) instance = CommentableContent(name="test instance") assert not is_commentable(instance) # not in DB: no id # pyre-fixme[8]: Attribute has type `Column`; used as `int`. instance.id = 42 assert is_commentable(instance) assert not is_commentable(object) assert not is_commentable(object())
def init_object(self, args, kwargs): args, kwargs = super(BaseCommentView, 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 to comment") if not is_commentable(self.entity): raise BadRequest("This entity is not commentable") actions.context["object"] = self.entity return args, kwargs
def init_object(self, args, kwargs): args, kwargs = super(BaseCommentView, 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 to comment') if not is_commentable(self.entity): raise BadRequest('This entity is not commentable') actions.context['object'] = self.entity return args, kwargs
def init_object(self, args, kwargs): args, kwargs = super().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 to comment") if not is_commentable(self.entity): raise BadRequest("This entity is not commentable") actions.context["object"] = self.entity return args, kwargs
def is_commentable(self, obj): return comments.is_commentable(obj)