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


Python Article.query方法代码示例

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


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

示例1: get

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import query [as 别名]
    def get(self):
        tag = self.request.get('tag')
        if self.request.get('p'):
            curs = Cursor(urlsafe=self.request.get('p'))
            articles = list()
            query_iterator = Article.query().order(
                -Article.when).iter(produce_cursors=True,
                                    start_cursor=curs)

            for article in query_iterator:
                if tag in article.keywords:
                    articles.append(article)
                    if len(articles) == ITEMS_PER_PAGE:
                        break

            curs = query_iterator.cursor_after().urlsafe()
            more = query_iterator.probably_has_next()

            self.response.out.headers['Content-Type'] = 'application/json'
            self.response.out.write(
                json.dumps(
                    {'articles': [a.as_dict() for a in articles],
                     'next': curs,
                     'more': more}
                )
            )
            
        # If nothing is queried, return initial page.
        # TODO: merge those two conditionals.
        else:
            articles = list()
            query_iterator = Article.query().order(
                -Article.when).iter(produce_cursors=True)

            for article in query_iterator:
                if tag in article.keywords:
                    articles.append(article)
                    if len(articles) == ITEMS_PER_PAGE:
                        break

            curs = query_iterator.cursor_after().urlsafe()
            more = query_iterator.probably_has_next()

            self.response.out.headers['Content-Type'] = 'application/json'
            self.response.out.write(
                json.dumps(
                    {'articles': [a.as_dict() for a in articles],
                     'next': curs,
                     'more': more}
                )
            )        
开发者ID:guillemborrell,项目名称:guillemborrell,代码行数:53,代码来源:resources.py

示例2: getArticles

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import query [as 别名]
def getArticles():
    articles = Article.query()
    if articles.count() == 0:
        hello = Article()
        hello.title = "Hello World"
        hello.content = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur, voluptatum. Provident accusamus sit, commodi corrupti illo, veniam possimus minima rerum itaque. Magni, beatae, facere."
        hello.put()
        bye = Article()
        bye.title = "Bye World"
        bye.content = "Iraqi PM Nouri Maliki steps aside, ending political deadlock in Baghdad as the government struggles against insurgents in the north."
        bye.put()
        del hello, bye
        articles = Article.query()
    return serialize(list(articles.order(Article.date).fetch(10)))
开发者ID:blogmv,项目名称:backend-python-flask,代码行数:16,代码来源:blogmv.py

示例3: post

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import query [as 别名]
 def post(self):
     """set memcache entry if author has more than one article"""
     articles = Article.query(parent=self.request.get('profileKey'))
     not_found = not any(s.key.urlsafe() == self.request.get('sessionKey') for s in sessions)
     if sessions.count() + not_found > 1:
         memcache.set(MEMCACHE_FEATURED_ARTICLE_KEY, 
             '%s is our latest Featured Author' % self.request.get(
             'displayName'))
开发者ID:dansalmo,项目名称:new-aca,代码行数:10,代码来源:main.py

示例4: getAllArticles

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import query [as 别名]
    def getAllArticles(self, request):
        """Return all published articles, newest first"""

        articles = Article.query()\
            .filter(Article.view=='PUBLISHED')\
            .order(-Article.dateCreated)

        return ArticleForms(
            items=[self._copyArticleToForm(article) for article in articles]
        )
开发者ID:dansalmo,项目名称:new-aca,代码行数:12,代码来源:aca.py

示例5: zfilterPlayground

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import query [as 别名]
    def zfilterPlayground(self, request):
        """Filter Playground"""
        q = Article.query()
        # field = "city"
        # operator = "="
        # value = "London"
        # f = ndb.query.FilterNode(field, operator, value)
        # q = q.filter(f)
        q = q.filter(Article.tag=="London")
        #q = q.filter(Article.topics=="Medical Innovations")
        #q = q.filter(Article.month==6)

        return ArticleForms(
            items=[self._copyArticleToForm(conf, "") for article in q]
        )
开发者ID:dansalmo,项目名称:new-aca,代码行数:17,代码来源:aca.py

示例6: getMyArticles

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

        author = self._getAuthorFromUser() 

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

        articles = Article.query(ancestor=author.key)\
            .order(-Article.dateCreated)

        # return set of ArticleForm objects per Article
        return ArticleForms(
            items=[self._copyArticleToForm(article, author) for article in articles]
        )
开发者ID:dansalmo,项目名称:new-aca,代码行数:17,代码来源:aca.py

示例7: getArticlesByAuthor

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import query [as 别名]
    def getArticlesByAuthor(self, request):
        """Return published articles created by author (key or authorID), newest first"""

        #try by authorID first
        author = Author.query()\
            .filter(Author.authorID==request.websafeAuthorKey)\
            .get()\
            or self._checkKey(request.websafeAuthorKey, 'Author').get()

        articles = Article.query(ancestor=author.key)\
            .filter(Article.view=='PUBLISHED')\
            .order(-Article.dateCreated)

        # return set of ArticleForm objects per Article
        return ArticleForms(
            items=[self._copyArticleToForm(article, author=author) for article in articles]
        )
开发者ID:dansalmo,项目名称:new-aca,代码行数:19,代码来源:aca.py

示例8: _getQuery

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import query [as 别名]
    def _getQuery(self, request):
        """Return formatted query from the submitted filters."""
        q = Article.query()
        inequality_filter, filters = self._formatFilters(request.filters)

        # If exists, sort on inequality filter first
        if not inequality_filter:
            q = q.order(Article.name)
        else:
            q = q.order(ndb.GenericProperty(inequality_filter))
            q = q.order(Article.name)

        for filtr in filters:
            if filtr["field"] in ["month", "maxAttendees"]:
                filtr["value"] = int(filtr["value"])
            formatted_query = ndb.query.FilterNode(filtr["field"], filtr["operator"], filtr["value"])
            q = q.filter(formatted_query)
        return q
开发者ID:dansalmo,项目名称:new-aca,代码行数:20,代码来源:aca.py

示例9: setFeaturedArticles

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import query [as 别名]
    def setFeaturedArticles(self, request):
        '''setFeaturedArticlefrom list of legacy ID's'''
        user = endpoints.get_current_user()
        if not user:
            raise endpoints.UnauthorizedException('Authorization required')

        favoritesAuthor = Author.query(Author.authorID=='0').get()

        featured_ids = [11006, 97006, 98006, 91006, 91004, 95001, 46003, 87006, 85006, 59001,
           49001, 9001, 10001, 23008, 31006, 4001, 13001, 21012, 35008, 21005,
           27001, 18002, 5001, 7001, 25001, 12002, 28011, 8002, 22002]

        for legacyID in featured_ids:
            article = Article.query(Article.legacyID==str(legacyID)).get()
            if article:
                websafeArticleKey = article.key.urlsafe()

                if websafeArticleKey not in favoritesAuthor.favoriteArticles:
                    favoritesAuthor.favoriteArticles.append(websafeArticleKey)
                    favoritesAuthor.put()

        return BooleanMessage(data=True)
开发者ID:dansalmo,项目名称:new-aca,代码行数:24,代码来源:aca.py

示例10: get

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import query [as 别名]
  def get(self): 
    """Generate the main index page"""
    # Check memcache for the list of front page articles
    articles_list = memcache.get("articles_list")

    # If it wasn't in memcache, generate the list and place it into memcache
    if not articles_list:
      articles = Article.query().order(-Article.rating, -Article.submitted).fetch(20)
      article_list = []
      for article in articles:
        article_properties = { 'title': article.title,
                               'rating': article.rating,
                               # This model unpacking is necessary to get the key/id
                               'id': article.key.id() }
        article_list.append(article_properties)
      memcache.add("articles_list", articles_list, time=60)

    # display the list of front page articles in the front page template
    template_values = {
      'articles': article_list,
    }

    template = jinja_environment.get_template('index.html')
    self.response.out.write(template.render(template_values))
开发者ID:aeakett,项目名称:AppEngine-Example,代码行数:26,代码来源:index.py


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