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


Python Comment.get_by_id方法代码示例

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


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

示例1: DoComment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
def DoComment(req, command=None):
    if not IsJSON():
        raise Error("Can only use API to edit comments.")
    local.requser.Require('api', 'write', 'comment')

    if command == 'delete':
        delkey = local.mpParams.get('delkey', '').strip()
        try:
            cid = int(SGetSigned('dk', delkey))
        except:
            raise Error("Invalid comment deletion key: %s" % delkey)
        comment = Comment.get_by_id(int(cid))
        if comment is None:
            raise Error("Comment id=%d does not exists" % cid, 'Fail/NotFound')
        map = comment.map
        comment.Delete()

    if command is None:
        id = local.mpParams.get('id', "").strip()

        map = Map.Lookup(id)
        if map == None:
            RaiseNotFound(id)

        parts = Comment.Parse(local.mpParams.get('username', ''), local.mpParams.get('comment', ''))

        local.requser.SetOpenUsername(parts['username'], fSetEmpty=False, fForce=req.GET.get('force', False))

        map.AddComment(username=local.requser.username, comment=parts['comment'], tags=parts['tags'])

    dateSince = local.mpParams.get('since', None)
    if dateSince:
        dateSince = DateFromISO(dateSince)
    return HttpJSON(req, obj=map.JSON(dateSince=dateSince))
开发者ID:Jeff-Lewis,项目名称:g02me,代码行数:36,代码来源:views.py

示例2: view_post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
def view_post(request, post_id):
    post = Post.get_by_id(int(post_id))
    if not post:
        raise Http404
    if not is_admin() and not post.is_published:
        raise Http404
    if request.method == "POST":
        comment = Comment()
        comment.content = request.POST["comment"]
        comment.author = users.get_current_user()
        comment.post = post
        if request.POST["parent_comment"] != "":
            parent_comment = Comment.get_by_id(int(request.POST["parent_comment"]))
            comment.parent_comment = parent_comment
        comment.put()
        post.comment_count = post.comment_count + 1
        post.put()
        mail.send_mail(
            sender="[email protected]",
            to=post.author.email(),
            subject=(u"牛逼 - 你的文章%s有了新评论" % post.title).encode("utf8"),
            body=(
                u"""%s在你的文章%s上留了评论: 

%s
 
点击这个链接回复: http://www.niubi.de/post/%s/"""
                % (comment.author.nickname(), post.title, comment.content, post.key().id())
            ).encode("utf8"),
        )
        comments = Comment.all().filter("post", post)
        sent_users = []
        for c in comments:
            if not contains_user(sent_users, c.author):
                mail.send_mail(
                    sender="[email protected]",
                    to=c.author.email(),
                    subject=(u"牛逼 - 你参与评论的文章%s有了新评论" % post.title).encode("utf8"),
                    body=(
                        u"""%s在文章%s上留了评论: 

%s
 
点击这个链接回复: http://www.niubi.de/post/%s/"""
                        % (comment.author.nickname(), post.title, comment.content, post.key().id())
                    ).encode("utf8"),
                )
                sent_users.append(c.author)

        return HttpResponseRedirect("/post/%s" % post.key().id())

    post.read_count = post.read_count + 1
    post.put()
    post.getComments()
    return render_to_response(
        "view_post.html",
        {"post": post, "is_post_author": is_post_author(post_id)},
        context_instance=RequestContext(request),
    )
开发者ID:ytrstu,项目名称:niubi,代码行数:61,代码来源:views.py

示例3: post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
 def post(self, post_id, comment_id):
     if not self.user:
         return self.redirect('/login')
     c = Comment.get_by_id(int(comment_id), parent=self.user.key())
     if c.parent().key().id() == self.user.key().id():
         c.comment = self.request.get('comment')
         c.put()
         self.redirect('/blog/%s' % str(post_id))
开发者ID:LeilaniAnn,项目名称:blog,代码行数:10,代码来源:main.py

示例4: update_comment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
 def update_comment(cls, comment_id, user_id, content):
     error_msg = ''
     comment = Comment.get_by_id(comment_id)
     if user_id == comment.created_by and content:
         comment.content = content
         comment.put()
     else:
         error_msg = 'The comment could not be saved, please check your content'
     return comment, error_msg
开发者ID:daliavi,项目名称:udacity-blog,代码行数:11,代码来源:service.py

示例5: post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
 def post(self, comment_id):
     comment = Comment.get_by_id(int(comment_id))
     # check that comment exists and it's author is current user
     if not comment or \
         comment.user.key().id() != self.user.key().id():
         self.response.out.write(json.dumps({'err_msg_critical': True}))
         return
     comment.delete()
     self.response.out.write(json.dumps({}))
开发者ID:mataelle,项目名称:multiuser-blog,代码行数:11,代码来源:main.py

示例6: delete

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
    def delete(self, comment_id):

        if comment_id and comment_id.isdigit():
            comment = Comment.get_by_id(int(comment_id))

        if self.user and comment and comment.user_id() == self.user.get_id():
            comment.key.delete()
            self.response.write('Success! Deleted!')
        else:
            self.response.set_status('403')
            self.response.write('Unsuccessful. Post not found or user not logged in.')
开发者ID:jdiii,项目名称:gae_blog,代码行数:13,代码来源:main.py

示例7: get

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
 def get(self, post_id, comment_id):
     if not self.user:
         return self.redirect('/login')
     error = ""
     post = Post.get_by_id(int(post_id), parent=blog_key())
     comment = Comment.get_by_id(int(comment_id), parent=self.user.key())
     if comment:
         comment.delete()
         self.redirect('/blog/%s' % str(post_id))
     else:
         error = "Please only delete your own comment"
         self.render('permalink.html', error=error, post=post)
开发者ID:LeilaniAnn,项目名称:blog,代码行数:14,代码来源:main.py

示例8: post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
 def post(self, deleteID):
   """
   Post method to delete comment by id
   :param deleteID:
   :type deleteID:
   """
   if self.user:
     comment_key = Comment.get_by_id(int(deleteID))
     comment_key.key.delete()
     self.redirect("/")
   else:
     self.redirect('/login')
开发者ID:manpreet07,项目名称:multi-user-blog,代码行数:14,代码来源:blog.py

示例9: get

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
 def get(self, _postID):
   """
   Get method to get post by id and render editcomment.html
   :param _postID:
   :type _postID:
   """
   if self.user:
     comment_key = Comment.get_by_id(int(_postID))
     post = comment_key
     self.render('editcomment.html', comment=post)
   else:
     self.redirect('/login')
开发者ID:manpreet07,项目名称:multi-user-blog,代码行数:14,代码来源:blog.py

示例10: delete_comment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
    def delete_comment(cls, post_id, comment_id, user_id):
        error_msg = ''
        comments = Comment.all().filter('post_id =', post_id).order('-created').fetch(limit=10)
        comment = Comment.get_by_id(comment_id)

        if user_id == comment.created_by:
            updated_comments = cls.update_list_on_delete(
                object_list=comments,
                object_id=comment_id
            )
            Comment.delete(comment)
        else:
            error_msg = 'You can delete only your own comments'
            updated_comments = comments
        return updated_comments, error_msg
开发者ID:daliavi,项目名称:udacity-blog,代码行数:17,代码来源:service.py

示例11: view_post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
def view_post(request, post_id):
    post = Post.get_by_id(int(post_id))
    if not post:
        raise Http404    
    if not is_admin() and not post.is_published:
        raise Http404  
    if request.method == 'POST':
        comment = Comment()
        comment.content = request.POST['comment']
        comment.author = users.get_current_user()
        comment.post = post
        if request.POST['parent_comment'] != "":
            parent_comment = Comment.get_by_id(int(request.POST['parent_comment']))
            comment.parent_comment = parent_comment
        comment.put()      
        post.comment_count = post.comment_count + 1
        post.put()        
        mail.send_mail(sender="[email protected]",
                       to=post.author.email(),
                       subject=(u'牛逼 - 你的文章%s有了新评论'%post.title).encode('utf8'),
                       body=(u'''%s在你的文章%s上留了评论: 

%s
 
点击这个链接回复: http://www.niubi.de/post/%s/''' %(comment.author.nickname(), post.title, comment.content, post.key().id())).encode('utf8')
                       )     
        comments = Comment.all().filter('post', post)
        sent_users = []
        for c in comments:
            if not contains_user(sent_users, c.author):
                mail.send_mail(sender="[email protected]",
                               to=c.author.email(),
                               subject=(u'牛逼 - 你参与评论的文章%s有了新评论'%post.title).encode('utf8'),
                               body=(u'''%s在文章%s上留了评论: 

%s
 
点击这个链接回复: http://www.niubi.de/post/%s/''' %(comment.author.nickname(), post.title, comment.content, post.key().id())).encode('utf8')
                       )
                sent_users.append(c.author)
        
        return HttpResponseRedirect('/post/%s' % post.key().id())
    
    post.read_count = post.read_count + 1
    post.put()
    post.getComments()       
    return render_to_response('view_post.html', 
                              {'post':post,'is_post_author':is_post_author(post_id)}, context_instance=RequestContext(request))
开发者ID:lvbeck,项目名称:niubi,代码行数:50,代码来源:views.py

示例12: put

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
    def put(self, comment_id):

        if comment_id and comment_id.isdigit():
            comment = Comment.get_by_id(int(comment_id))

        if self.user and comment and comment.user_id() == self.user.get_id():
            if self.request.body:
                new_comment = self.request.body
                comment.comment = new_comment
                comment.put()
                self.response.write(comment.render())
            else:
                self.response.set_status('403')
                self.response.write('Unsuccessful. No comment included in request.')
        else:
            self.response.set_status('403')
            self.response.write('Unsuccessful. Post not found or user not logged in.')
开发者ID:jdiii,项目名称:gae_blog,代码行数:19,代码来源:main.py

示例13: post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
    def post(self, comment_id):
        if not self.user:
            self.redirect('/blog/login')
            return

        if self.request.POST.get('save_comment'):
            new_comment, error_msg = PostService.update_comment(
                comment_id=int(comment_id),
                user_id=int(self.user.key().id()),
                content=self.request.get('content')
            )

            if error_msg:
                self.render('editcomment.html',
                            error=error_msg,
                            comment_id=comment_id
                            )
            else:
                time.sleep(0.5)
                self.redirect('/blog/' + str(new_comment.post_id))
        else:
            comment = Comment.get_by_id(int(comment_id))
            self.redirect('/blog/' + str(comment.post_id))
开发者ID:daliavi,项目名称:udacity-blog,代码行数:25,代码来源:handlers.py

示例14: get

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
 def get(self, comment_id, error=''):
     comment = Comment.get_by_id(int(comment_id))
     self.render('editcomment.html',
                 content=comment.content
                 )
开发者ID:daliavi,项目名称:udacity-blog,代码行数:7,代码来源:handlers.py

示例15: _grab_comment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import get_by_id [as 别名]
 def _grab_comment(self, comment_id):
     comment = Comment.get_by_id(int(comment_id))
     if not comment:
         self.abort(404, explanation = "No such Comment.")
     return comment
开发者ID:sergey-inform,项目名称:Udacity-FSWDN-MultiuserBlog,代码行数:7,代码来源:handlers.py


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