当前位置: 首页>>代码示例>>Python>>正文


Python Comment.query方法代码示例

本文整理汇总了Python中app.models.Comment.query方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.query方法的具体用法?Python Comment.query怎么用?Python Comment.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app.models.Comment的用法示例。


在下文中一共展示了Comment.query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import query [as 别名]
    def post(self, user):
        # grab the form
        form = PostDeleteForm(self.request.params)

        # validate csrf
        if not self.validate_csrf(form.csrf_token.data):
            form.csrf_token.data = self.generate_csrf()
            self.r(form, flashes=flash('Please submit the form again.'))
            return

        # get the post please
        try:
            post = Key(urlsafe=form.key.data).get()
        except:
            post = None

        # as usual, this really shouldn't
        # be None unless unnatural navigation
        if post is None:
            self.redirect('/')
            return

        # the post exists, is it owned by the user?
        if post.author != user:
            self.redirect('/')
            return

        # check if the user is the owner or not
        if post.author != user:
            self.redirect('/')
            return

        # everything checks out so let's remove the post
        # first though, we need to remove the comments
        # assoc with the post and the likes
        # TODO query these entities to make sure they are removed
        comments = Comment.query(ancestor=post.key).fetch()
        ks = put_multi(comments)
        delete_multi(ks)

        likes = Like.query(Like.post == post.key).fetch()
        ks = put_multi(likes)
        delete_multi(ks)

        # got everything else removed, let's
        # remove the post
        try:
            post.key.delete()
            self.redirect('/')
            return
        except Exception as e:
            # let them try again
            form.csrf_token.data = self.generate_csrf()
            self.r(form, post, flashes=flash())
            return
开发者ID:jwelker110,项目名称:multi-user-blog,代码行数:57,代码来源:delete.py

示例2: get

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import query [as 别名]
    def get(self):
        # get the user
        user = self.validate_user()
        # we have the user and need to access their key to see if they liked the post
        # if they are not signed in then we don't show if they liked or not
        if user is not None:
            user = User.query(User.username == user).get()
            if user is not None:
                user = user.key

        # get the post key
        k = self.request.get('key', None)
        if k is None:
            self.redirect('/')
            return

        # create our form data for likes/comments
        formData = {
            'key': k,
            'csrf_token': self.generate_csrf()
        }

        # create our comment form
        form = CommentForm(data=formData)
        # create our like form
        like_form = LikeForm(data=formData)

        # try to retrieve the post based on the key
        try:
            post = Key(urlsafe=k).get()
        except:
            post = None

        # don't have the comments yet, or likes
        comments = None
        liked = None
        if post is not None:
            # grab the comments please
            comments = Comment.query(ancestor=post.key).order(-Comment.created).fetch()
            # grab likes
            # we also need to see if this user has "liked" the post already
            liked = Like.query(Like.owner == user, Like.post == post.key).get()
        self.r(form, like_form, post, comments, liked)
开发者ID:jwelker110,项目名称:multi-user-blog,代码行数:45,代码来源:view.py


注:本文中的app.models.Comment.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。