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


Python Comment.parent方法代码示例

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


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

示例1: post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import parent [as 别名]
  def post(self, forum_id, post_reference):
    user = self.user_model
    post = ForumPost.query(ForumPost.forum_name == forum_id, ForumPost.reference == post_reference).get()
    text = cgi.escape(self.request.get('text'))
    sender = cgi.escape(self.request.get('sender'))
    recipient = cgi.escape(self.request.get('recipient'))
    replied_to_urlsafe = cgi.escape(self.request.get('parent'))
    comment = Comment(parent = post.key)
    if len(replied_to_urlsafe) != 0:
      replied_to_key = ndb.Key(urlsafe=replied_to_urlsafe)
      parent_comment = replied_to_key.get()
      comment.parent = replied_to_key
      comment.offset = parent_comment.offset + 20
      recipient_comment = ndb.Key(urlsafe=replied_to_urlsafe).get()
      comment.recipient = recipient_comment.sender
      comment.sender = user.username
      comment.root = False
    else:
      comment.sender = sender
      comment.recipient = recipient

    comment.text = text
    comment.time = datetime.datetime.now() - datetime.timedelta(hours=7) #For PST
    comment.put()

    if comment.root == False:
      parent_comment.children.append(comment.key)
      parent_comment.put()
      
    post.comment_count += 1
    post.put()
    self.redirect('/tech/{}/{}'.format(forum_id, post_reference))
开发者ID:nikko0327,项目名称:Ninja-Tutor,代码行数:34,代码来源:Forum.py

示例2: addToDatabase

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import parent [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

示例3: view_ad

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import parent [as 别名]
def view_ad(url):
    room = Room.query.filter_by(urlname=url).first()
    if not room:
        abort(404)
    if room.dead or get_days_ago(room.created_at) > OLD_DAYS.days:
        abort(404)
    occupied = Occupied.query.filter_by(space=room.occupieds).order_by("created_at").first()
    if occupied and get_days_ago(occupied.created_at) > OCCUPIED_DAYS.days:
        abort(404)
    # URL is okay. Show the ad.
    comments = Comment.query.filter_by(commentspace=room.comments, parent=None).order_by("created_at").all()
    commentform = CommentForm()
    delcommentform = DeleteCommentForm()
    if request.method == "POST":
        if request.form.get("form.id") == "newcomment" and commentform.validate():
            if commentform.edit_id.data:
                comment = Comment.query.get(int(commentform.edit_id.data))
                if comment:
                    if comment.user == g.user:
                        comment.message = commentform.message.data
                        flash("Your comment has been edited", category="info")
                    else:
                        flash("You can only edit your own comments", category="info")
                else:
                    flash("No such comment", category="error")
            else:
                comment = Comment(user=g.user, commentspace=room.comments, message=commentform.message.data)
                if commentform.parent_id.data:
                    parent = Comment.query.get(int(commentform.parent_id.data))
                    if parent and parent.commentspace == room.comments:
                        comment.parent = parent
                room.comments.count += 1
                db.session.add(comment)
                flash("Your comment has been posted", category="success")
            db.session.commit()
            # Redirect despite this being the same page because HTTP 303 is required to not break
            # the browser Back button
            return redirect(url_for("view_ad", url=room.urlname) + "#c" + str(comment.id), code=303)
        elif request.form.get("form.id") == "delcomment" and delcommentform.validate():
            comment = Comment.query.get(int(delcommentform.comment_id.data))
            if comment:
                if comment.user == g.user:
                    comment.delete()
                    room.comments.count -= 1
                    db.session.commit()
                    flash("Your comment was deleted.", category="success")
                else:
                    flash("You did not post that comment.", category="error")
            else:
                flash("No such comment.", category="error")
            return redirect(url_for("view_ad", url=room.urlname), code=303)
    return render_template(
        "room.html", room=room, comments=comments, commentform=commentform, delcommentform=delcommentform
    )
开发者ID:punchagan,项目名称:tree-house,代码行数:56,代码来源:views.py

示例4: addcomment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import parent [as 别名]
def addcomment(request):
    if request.method == "POST":
        news = News.objects.get(id=request.POST['news'])
        text = request.POST['text']
        user = User.objects.get(username=request.user)
        c = Comment()
        c.news = news
        c.owner = user
        c.text = text
        if request.POST['pid'] != 'false':
            pid = request.POST['pid']
            c.parent = Comment.objects.get(id=pid)
        c.save()
        return HttpResponse(c.id)
开发者ID:TorinAsakura,项目名称:gk,代码行数:16,代码来源:views.py

示例5: post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import parent [as 别名]
    def post(self, album_id):
        user = get_user()

        if user:
            album = Album.get_by_id(
                int(album_id),
                parent=DEFAULT_DOMAIN_KEY
            )

            comment = Comment(parent=album.key)
            comment.text = self.request.get('comment_text')
            comment.author = user.key
            comment.parent = album.key

            comment.put()

            self.redirect('/album/%s/view' % album.key.integer_id())
        else:
            self.redirect_to_login()
开发者ID:MichaelAquilina,项目名称:Photo-Nebula,代码行数:21,代码来源:views.py

示例6: post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import parent [as 别名]
  def post(self):
    origin = cgi.escape(self.request.get('origin'))
    text = cgi.escape(self.request.get('text'))
    sender = cgi.escape(self.request.get('sender'))
    recipient = cgi.escape(self.request.get('recipient'))
    replied_to_urlsafe = cgi.escape(self.request.get('parent'))
    viewer = self.user_model
    comment = Comment()
    if len(replied_to_urlsafe) != 0:
      replied_to_key = ndb.Key(urlsafe=replied_to_urlsafe)
      parent_comment = replied_to_key.get() #parent comment
      comment.parent = replied_to_key
      comment.offset = parent_comment.offset + 20
      recipient_comment = ndb.Key(urlsafe=replied_to_urlsafe).get()
      comment.recipient = recipient_comment.sender
      comment.sender = viewer.username
      comment.root = False
    else:
      comment.sender = sender
      comment.recipient = recipient

    # Not double adding User Keys
    if sender != recipient:
      comment.sender_key = User.query(User.username == sender).get().key
      comment.recipient_key = User.query(User.username== recipient).get().key
    else:
      comment.sender_key = User.query(User.username == sender).get().key
      comment.recipient_key = None
    comment.text = text
    comment.time = datetime.datetime.now() - datetime.timedelta(hours=8) #For PST
    comment.put()
    
    if comment.root == False:
      parent_comment.children.append(comment.key)
      parent_comment.put()

    self.redirect('/profile/{}'.format(recipient))
开发者ID:nikko0327,项目名称:Ninja-Tutor,代码行数:39,代码来源:Feed.py


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