Exemple #1
0
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())
Exemple #2
0
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())
Exemple #3
0
    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
Exemple #4
0
  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
Exemple #5
0
    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
Exemple #6
0
 def is_commentable(self, obj):
     return comments.is_commentable(obj)
Exemple #7
0
 def is_commentable(self, obj):
   return comments.is_commentable(obj)