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


Python Comment.author方法代码示例

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


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

示例1: post

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import author [as 别名]
    def post(self, blog_id=1, page=1):
        data = request.json
        blog = Blog.query.get(blog_id)
        comment = Comment()
        comment.detail = data['detail']
        user_id = data['user_id']
        user = User.query.get(user_id)
        if user:
            comment.author = user
        else:
            guest = User('guest','unused')
            guest.id = 0
            comment.author = guest
        comment.article = blog
        comment.createAt = datetime.now()
        db.session.add(comment)
        db.session.commit()

        comments = Comment.query.filter_by(article=blog).paginate(page, PAGE_SIZE, False)
        return comments
开发者ID:51azxc,项目名称:blogbyflask,代码行数:22,代码来源:views.py

示例2: post

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import author [as 别名]
    def post(self, slug):
        context = self.get_context(slug)
        form = context.get('form')

        if form.validate():
            comment = Comment()
            form.populate_obj(comment)
            comment.author = context.get('author')
            post = context.get('post')
            post.comments.append(comment)
            post.save()

            return redirect(url_for('posts.detail', slug=slug))

        return render_template('posts/detail.html', **context)
开发者ID:davbrama,项目名称:GoldNGlass,代码行数:17,代码来源:docviews.py

示例3: staticUnity

# 需要导入模块: from app.models import Comment [as 别名]
# 或者: from app.models.Comment import author [as 别名]
def staticUnity(slug):
    if request.method == 'POST':
        unity = Unity.get_or_404(slug=slug)
        form = CommentForm()
        if not form.validate():
            return render_template('unity/staticUnity.html',
                                   pageTitle=unity.title,
                                   unity=unity,
                                   form=form)
        else:
            newComment = Comment(body=form.comment.data)
            newComment.author = User.get(email=current_user.email)
            unity.comments.append(newComment)
            unity.save()
            form.comment.data = None  # resets field on refresh
            flash('Comment Posted')
        return render_template('unity/staticUnity.html',
                               pageTitle=unity.title,
                               unity=unity,
                               form=form)
    elif request.method == 'GET':
        try:
            return render_template('unity/%s.html' % slug,
                                   pageTitle=slug)
        except TemplateNotFound:
            unity = Unity.get_or_404(slug=slug)
            currentUser = User.get(email=current_user.email)
            if (unity.postType == 'draft' and
                    unity.author != currentUser and
                    currentUser.is_admin() is False):
                flash('You must be draft author or admin to view.')
                return redirect(url_for('.listUnity'))
            else:
                form = CommentForm()
                return render_template('unity/staticUnity.html',
                                       pageTitle=unity.title,
                                       unity=unity,
                                       form=form)
开发者ID:cldershem,项目名称:homelessgaffer,代码行数:40,代码来源:views.py


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