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


Python Comment.query方法代码示例

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


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

示例1: comment_list

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
 def comment_list(self, offset_count):
   index = 0
   viewer = self.user_model
   # Need to see if user has friends, if not - Query using viewer.friends will break #
   if viewer.friends:
     comments = Comment.query(Comment.root==True, ndb.OR(Comment.sender_key.IN(viewer.friends),
       Comment.recipient_key.IN(viewer.friends), Comment.sender_key == viewer.key)).order(-Comment.time).fetch(10, offset=offset_count)
   else:
     comments = Comment.query(Comment.root==True, Comment.sender_key == viewer.key).order(-Comment.time).fetch(10, offset=offset_count)
   more = len(comments)
   while index < len(comments):
     children = Comment.query(Comment.parent == comments[index].key).fetch()
     index += 1
     comments[index:index] = children
   return comments, more
开发者ID:nikko0327,项目名称:Ninja-Tutor,代码行数:17,代码来源:Feed.py

示例2: get_comments_html

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def get_comments_html(theme, owner, result="", level=0, item_template='comment', margin=SUBCOMMENT_LEFT_MARGIN, desc=False):
    comments = Comment.query().filter(owner=owner)
    if desc:
        comments = comments.order_by('-created')
    for comment in comments:
        result += get_comments_html(theme, comment, get_single_comment_html(comment, level, theme, item_template, margin), level+1, item_template, margin, desc) #recursively render subcomments
    return result  
开发者ID:TDispatch,项目名称:london-comments,代码行数:9,代码来源:views.py

示例3: get

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
    def get(self, album_id):
        user = get_user()
        album = Album.get_by_id(
            int(album_id),
            DEFAULT_DOMAIN_KEY
        )

        if album:
            upload_url = blobstore.create_upload_url('/album/%s/upload-photo' % album_id)

            photo_query = Photo.query(
                ancestor=album.key
            )

            comments_query = Comment.query(
                Comment.parent == album.key
            ).order(-Comment.date_created)

            template_values = {
                'user': user,
                'album': album,
                'photos': photo_query.fetch(None),
                'comments': comments_query.fetch(None),
                'upload_url': upload_url,
            }

            self.render_template('view_album.html', template_values)
        else:
            self.raise_error(404)
开发者ID:MichaelAquilina,项目名称:Photo-Nebula,代码行数:31,代码来源:views.py

示例4: get

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
 def get(self, post_urlsafe_key):
     post = self.get_by_urlsafe(post_urlsafe_key, Post)
     comments = Comment.query(ancestor=post.key).fetch()
     if self.format == 'html':
         self.render('post.html', post=post, comments=comments)
     else:
         self.render_json(d=post.serialize)
开发者ID:MatthewBenjamin,项目名称:fsnd-blog,代码行数:9,代码来源:blog.py

示例5: comment_list

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
 def comment_list(self, request):
     """
     Returns:
         An instance of CommentListResponse.
     """
     items = [entity.to_message() for entity in Comment.query()]
     return CommentListResponse(items=items)
开发者ID:kipparker,项目名称:kp-comment,代码行数:9,代码来源:comment_api.py

示例6: getArticleComments

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
    def getArticleComments(self, request):
        """Return all comments for an article"""

        # check that websafeArticleKey is a Article key and it exists
        a_key = self._checkKey(request.websafeArticleKey, 'Article')

        comments = Comment.query(ancestor=a_key)
        return CommentForms(items=[self._copyCommentToForm(comment, article_key=a_key) for comment in comments])
开发者ID:dansalmo,项目名称:new-aca,代码行数:10,代码来源:aca.py

示例7: get

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
  def get(self, forum_id, post_reference):
    user = self.user_model
    post = ForumPost.query(ForumPost.forum_name == forum_id, ForumPost.reference == post_reference).get()
    comments = Comment.query(Comment.parent==post.key).fetch()
    # Get nested Comments
    index = 0
    while index < len(comments):
      children = Comment.query(Comment.parent == comments[index].key).fetch()
      index +=1
      comments[index:index] = children

    if user == None:
      override_base = "visitorBase.html"
    else:
      override_base = "base.html"
    self.response.out.write(template.render('views/forumComments.html',
      {'override_base':override_base, 'viewer': user, 'post':post,
      'forum_name':forum_id, 'comments':comments, 'post_reference':post_reference}))
开发者ID:nikko0327,项目名称:Ninja-Tutor,代码行数:20,代码来源:Forum.py

示例8: getComment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def getComment(article_id, comment_id):
    return serialize(
        Comment.query(
            ndb.AND(
                Comment.article == ndb.Key(Article, article_id),
                Comment.key == ndb.Key(Comment, comment_id)
            )
        ).get()
    )
开发者ID:blogmv,项目名称:backend-python-flask,代码行数:11,代码来源:blogmv.py

示例9: sharepoint_delete

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
 def sharepoint_delete(self, sharepoint):
     """ Delete the sharepoint with the entityKey, plus all the associated comments"""
     if not sharepoint.from_datastore:
         raise endpoints.NotFoundException("No Sharepoint found for the given key")
     children = Comment.query(Comment.sharepoint_key == sharepoint.key)
     for comment in children:
         comment.key.delete()
     sharepoint.key.delete()
     return Sharepoint(title="deleted")
开发者ID:FFyuan,项目名称:yuanx-sharepoint-viewer,代码行数:11,代码来源:api.py

示例10: get

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
    def get(self):
        archive = memcache.get('archive')
        if archive is not None:
            self.response.out.headers['Content-Type'] = 'application/json'
            self.response.out.write(json.dumps({'articles':archive}))

        else:
            more = True
            archive = OrderedDict()
            curs = None
            
            while more:
                articles, curs, more = Article.query().order(
                    -Article.when).fetch_page(
                        50,
                        start_cursor=curs,
                        projection=[Article.title, 
                                    Article.when,
                                    Article.keywords])
                for article in articles:
                    article_key = article.key.urlsafe()
                    
                    if article_key in archive:
                        archive[article_key]['keywords'].extend(
                            article.keywords)
                    else:
                        archive[article_key] = {
                            'title': article.title,
                            'when': article.when.strftime("%d/%m/%Y %H:%M:%S"),
                            'keywords': article.keywords,
                            'key': article_key,
                            'ncomments': 0}
                        

            more = True
            curs = None

            while more:
                page, curs, more = Comment.query().fetch_page(
                    100,
                    start_cursor = curs)

                for comment in page:
                    parent_key = comment.key.parent().urlsafe()
                    if parent_key in archive:
                        archive[parent_key]['ncomments'] += 1
                     

            memcache.add('archive',
                         [a for a in archive.itervalues()],
                         time=86400)
            self.response.out.headers['Content-Type'] = 'application/json'
            self.response.out.write(json.dumps(
                {'articles':[a for a in archive.itervalues()]}
            ))
开发者ID:guillemborrell,项目名称:guillemborrell,代码行数:57,代码来源:resources.py

示例11: get

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
    def get(self):       
        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write("[")
        # pull the id parameter from the query string
        # this holds the urlsafe key for a specific parking lot
        lot_id = self.request.get('lot_id')
        lot_key = ndb.Key(urlsafe=lot_id)
        # get account
        acc = self.get_account()
        # check if lot is in favorites
        if lot_key not in acc.parking_lots:
                acc.parking_lots.append(lot_key)
                acc.put()
        # get comments on lot
        comments = Comment.query(
            Comment.lot_key == lot_key,
            # filter out any comments older than a day
            Comment.date > datetime.utcnow() - timedelta(days=1)
            ).order(-Comment.date)

        for c in comments:
            seconds_passed = (datetime.now() - c.date).total_seconds()
            passed = ""
            end = ""
            # recent is no older than 15 minutes (ie < 16 minutes)
            if seconds_passed < 60 * 16:
                c.recent = True
            # compute seconds when under a minute has passed
            if seconds_passed < 60:
                passed = str(int(seconds_passed))
                end = " seconds ago"
            # compute minutes when under an hour has passed
            elif seconds_passed < 3600:
                passed = str(int(seconds_passed / 60))
                end = " minutes ago"
                if seconds_passed < 120:
                    end = " minute ago"
            # compute hours when under a day has passed
            elif seconds_passed < 3600 * 24:
                passed = str(int(seconds_passed) / 3600)
                end = " hours ago"
                if seconds_passed < 7200:
                    end = " hour ago"
            else:
                passed = str(int(seconds_passed) / (3600*24))
                end = " days ago"
                if seconds_passed < 3600 * 48:
                    end = " day ago"
            c.time = passed + end
            self.response.out.write(serialize(c) + ",")
        self.response.out.write("{}")
        self.response.out.write("]")
开发者ID:lf237,项目名称:project5,代码行数:54,代码来源:comment_forms.py

示例12: get

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
 def get(self):
     post_id = int(self.request.get('id'))
     post = Post.get_by_id(post_id)
     comment_query = Comment.query().filter(Comment.post==post.key).order(-Comment.time).fetch()
     output = ''
     for comment in comment_query:
         output += '<div class="ui-bar ui-bar-a"><h3>'
         output += comment.author
         output += ' said...</h3></div>'
         output += '<div class="ui-body ui-body-a"><p>'
         output += comment.content
         output += '</p></div><br>'
     self.response.out.write(output)
开发者ID:crumpledpaper,项目名称:singgest,代码行数:15,代码来源:main.py

示例13: comment_search

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
    def comment_search(self, request):
        """
        Arguments:
            CommentRequestMessage, with content used for search

        Returns:
            An instance of CommentListResponse.
        """
        term = request.content or ""
        comment_search = search.Index(SEARCH_INDEX).search(term)
        comment_keys = [ndb.Key(Comment, int(x.doc_id)) for x in comment_search.results]
        q = Comment.query().filter(Comment._key.IN(comment_keys))
        items = [entity.to_message() for entity in q.iter()]
        return CommentListResponse(items=items)
开发者ID:kipparker,项目名称:kp-comment,代码行数:16,代码来源:comment_api.py

示例14: getMyComments

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
    def getMyComments(self, request):
        """Return comments created by current user"""

        author = self._getAuthorFromUser()

        if not author:
            raise endpoints.UnauthorizedException('%s is not an author of any articles or comments' % user.nickname())

        comments = Comment.query().filter(Comment.authorID==author.authorID)

        # return set of CommentForm objects per Comment
        return CommentForms(
            items=[self._copyCommentToForm(comment, author=author) for comment in comments]
        )
开发者ID:dansalmo,项目名称:new-aca,代码行数:16,代码来源:aca.py

示例15: postComment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import query [as 别名]
def postComment(article_id):
    article = Article.get_by_id(article_id)
    if not article:
        return "", 404, {"Content-Type": "application/json"}
    data = request.get_json()
    if not data:
        return "Missing data", 400
    comment = Comment()
    comment.article = article.key
    comment.author_name = escape(data.get("author_name"))
    comment.author_email = escape(data.get("author_email"))
    comment.content = escape(data.get("content"))
    comment.put()
    comments = Comment.query().order(Comment.date).fetch(keys_only=True)
    if len(comments) >= 10:
        comments[0].delete()
    return serialize(comment)
开发者ID:blogmv,项目名称:backend-python-flask,代码行数:19,代码来源:blogmv.py


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