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


Python Comment.post_id方法代码示例

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


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

示例1: addToDatabase

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import post_id [as 别名]
def addToDatabase(parent, subtree, i):

    subComments = subtree["data"]["children"]
    if len(subComments) == 0:
        pass
        # print "List EMPTY"
    w = 0
    for j in subComments:
        comment = Comment()
        comment.reddit_id = j["data"]["id"]
        comment.text = j["data"]["body"]
        comment.user_name = j["data"]["author"]
        comment.upvotes = int(j["data"]["ups"])
        comment.downvotes = j["data"]["downs"]
        comment.date_of_last_sweep = datetime.now()
        comment.parent = parent
        comment.post_id = parent.post_id
        session.add(comment)
        if j["data"]["replies"] == "":
            comment.weight = comment.upvotes
            # print "Dict Empty"
            # print type(j["data"]["replies"])

        else:
            addToDatabase(comment, j["data"]["replies"], i + 1)
            comment.weight = comment.weight + comment.upvotes
        w = comment.weight + w
    parent.weight = w

    """
开发者ID:NSkelsey,项目名称:reddit_sweep,代码行数:32,代码来源:comments.py

示例2: add_comment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import post_id [as 别名]
def add_comment(post_id):
    comment = Comment(request.form['text'])
    comment.author_id = current_user().id
    comment.post_id = post_id
    db.session.add(comment)
    db.session.commit()
    return redirect('/post/' + str(post_id))
开发者ID:adicu,项目名称:intro-webapps,代码行数:9,代码来源:routes.py

示例3: post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import post_id [as 别名]
def post(id):
    post = Post.query.get_or_404(id)
    form = forms.CommentForm()

    if request.method=='POST':
        comment = Comment()
        comment.content = form.content.html
        comment.user_id = current_user.id
        comment.post_id = id
        comment.time_stamp = datetime.now()
        db.session.add(comment)
        db.session.commit()
        return redirect(url_for('.post',id=id,page=-1))

    page = request.args.get('page',1,type=int)
    if page==-1:
        page = (post.comments.count() - 1) / COMMENTS_PER_PAGE + 1
    comments = post.comments.order_by(Comment.time_stamp.asc()).paginate(page,COMMENTS_PER_PAGE,False)

    Post.query.filter(Post.id==id).update({Post.view_times:Post.view_times+1})
    return render_template('post.html',post=post,comments=comments,form=form)
开发者ID:qinms,项目名称:BlogApp,代码行数:23,代码来源:views.py

示例4: save_comment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import post_id [as 别名]
def save_comment():
	msg = "Comment not saved."
	try:
		nome = request.form['name']
		email = request.form['email']
		texto = request.form['content']
		post_id = request.form['post_id']
		comentario = Comment()
		comentario.name = nome
		comentario.email = email
		comentario.content = texto
		comentario.display = False
		comentario.date_created = datetime.today()
		comentario.post_id = post_id
		db.session.add(comentario)
		db.session.commit()
		msg = "Comentário enviado! Obrigado!"
	except:
		db.session.rollback()
		traceback.print_exc()
		#raise
	data = {}
	data['message'] = msg
	return jsonify(data)
开发者ID:berlotto,项目名称:asciiblog,代码行数:26,代码来源:__init__.py

示例5: import_blog

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import post_id [as 别名]
def import_blog():
    f = request.files["file"]

    try:
        data = f.stream.read().decode("utf-8")
        data = json.loads(data)
        links = data.pop("links", [])
        medias = data.pop("medias", [])
        posts = data.pop("posts", [])

        for link in links:
            new_link = Link.get_by_href(link["href"])
            if new_link:
                continue
            else:
                new_link = Link()

            for item in link:
                new_link.__dict__[item] = link[item]
            new_link.link_id = None
            new_link.create_time = \
                datetime.fromtimestamp(new_link.create_time)
            new_link.save()

        for media in medias:
            new_media = Media.get_by_fileid(media["fileid"])
            if new_media:
                continue
            else:
                new_media = Media()

            for item in media:
                new_media.__dict__[item] = media[item]

            # Notice, media id should not be set to None
            new_media.media_id = None
            new_media.create_time = \
                datetime.fromtimestamp(new_media.create_time)
            new_media.save()

        for post in posts:
            # If posts exist, continue
            new_post = Post.get_by_url(post["url"], public_only=False)
            if new_post:
                continue
            else:
                new_post = Post()

            for item in post:
                new_post.__dict__[item] = post[item]
            new_post.post_id = None
            new_post.create_time = \
                datetime.fromtimestamp(new_post.create_time)
            new_post.update_time = \
                datetime.fromtimestamp(new_post.update_time)

            new_post.raw_content = re.sub('<[^<]+?>', "", new_post.content)
            newtags = new_post.tags
            new_post.tags = ""
            new_post.update_tags(newtags)
            new_post.save()

            # Restore all posts
            comments = post["commentlist"]
            for comment in comments:
                new_comment = Comment()
                for item in comment:
                    new_comment.__dict__[item] = comment[item]
                new_comment.post_id = new_post.post_id
                new_comment.comment_id = None
                new_comment.create_time = \
                    datetime.fromtimestamp(new_comment.create_time)
                new_comment.save()
    except Exception as e:
        return str(e)

    return "Done"
开发者ID:minyoad,项目名称:Tyou,代码行数:79,代码来源:admin.py


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