コード例 #1
0
ファイル: test_comment.py プロジェクト: tmarwen/abilian-core
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())
コード例 #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())
コード例 #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
コード例 #4
0
ファイル: views.py プロジェクト: debon/abilian-core
  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
コード例 #5
0
ファイル: views.py プロジェクト: abilian/abilian-core
    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
コード例 #6
0
 def is_commentable(self, obj):
     return comments.is_commentable(obj)
コード例 #7
0
ファイル: extension.py プロジェクト: debon/abilian-core
 def is_commentable(self, obj):
   return comments.is_commentable(obj)