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


Python Author.query方法代码示例

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


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

示例1: _copyCommentToForm

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import query [as 别名]
    def _copyCommentToForm(self, comment, article_key=None, author=None):
        """Copy relevant fields from Comment to CommentForm."""
        cf = CommentForm()

        if not author:
            author = Author.query()\
                .filter(Author.authorID==comment.authorID)\
                .get()

        if not article_key:
            article_key = comment.key.parent()

        for field in cf.all_fields():
            if hasattr(comment, field.name):
                # convert Date to date string
                if field.name.startswith('date'):
                    setattr(cf, field.name, str(getattr(comment, field.name)))
                else:
                    setattr(cf, field.name, getattr(comment, field.name))
            # add the fields that are not part of the Comment model
            elif field.name == "websafeCommentKey":
                setattr(cf, field.name, comment.key.urlsafe())
            elif field.name == "websafeArticleKey":
                setattr(cf, field.name, article_key.urlsafe())
            elif field.name == "websafeAuthorKey":
                setattr(cf, field.name, author.key.urlsafe())
        cf.check_initialized()
        return cf
开发者ID:dansalmo,项目名称:new-aca,代码行数:30,代码来源:aca.py

示例2: removeFeaturedArticle

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import query [as 别名]
    def removeFeaturedArticle(self, request):
        """Remove an article from featured articles (Favorites of authorID 0)"""

        user_author = self._getAuthorFromUser() 

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

        userRights = getattr(UserRights, user_author.userRights)

        if userRights < UserRights.FELLOW:
            raise endpoints.ForbiddenException(
                "Only an administrator or fellow can remove a featured article."
                )
        self._checkKey(request.websafeArticleKey, 'Article')

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

        if not request.websafeArticleKey in favoritesAuthor.favoriteArticles:
            raise endpoints.NotFoundException("Article is not a featured article")

        # find and delete the article key
        idx = favoritesAuthor.favoriteArticles.index(request.websafeArticleKey)
        del favoritesAuthor.favoriteArticles[idx]
        favoritesAuthor.put()

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

示例3: addFeaturedArticle

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import query [as 别名]
    def addFeaturedArticle(self, request):
        """Add an article to featured articles (Favorites of authorID 0)"""

        user_author = self._getAuthorFromUser() 

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

        userRights = getattr(UserRights, user_author.userRights)

        if userRights < UserRights.FELLOW:
            raise endpoints.ForbiddenException(
                "Only an administrator or fellow can add a featured article."
                )
        self._checkKey(request.websafeArticleKey, 'Article')

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

        if request.websafeArticleKey in favoritesAuthor.favoriteArticles:
            raise endpoints.BadRequestException("Article is already a featured article")

        favoritesAuthor.favoriteArticles.append(request.websafeArticleKey)
        favoritesAuthor.put()

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

示例4: get

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import query [as 别名]
    def get(self):

        self.templateVars["institutions"] = Institution.query().fetch()
        self.templateVars["authors"] = Author.query().fetch()
        self.templateVars["conferences"] = Conference.query().fetch()
        self.templateVars["publications"] = Publication.query().fetch()
        self.templateVars["contents"] = Content.query().fetch()
        return self.render("admin.html")
开发者ID:dcastro9,项目名称:personal_site,代码行数:10,代码来源:admin.py

示例5: getFeaturedArticleKeys

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import query [as 别名]
    def getFeaturedArticleKeys(self, request):
        """Return websafe keys for all featured articles (Favorites of authorID 0)"""

        author = Author.query()\
            .filter(Author.authorID=='0')\
            .get()

        # return set of ArticleForm objects per favorite article
        return KeyForms(
            items=[KeyForm(websafeKey=key) for key in author.favoriteArticles]
        )
开发者ID:dansalmo,项目名称:new-aca,代码行数:13,代码来源:aca.py

示例6: getFeaturedArticles

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import query [as 别名]
    def getFeaturedArticles(self, request):
        """Return featured articles (Favorites of authorID 0)"""

        author = Author.query()\
            .filter(Author.authorID=='0')\
            .get()

        # return set of ArticleForm objects per favorite article
        return ArticleForms(
            items=[self._copyArticleToForm(ndb.Key(urlsafe=key).get()) for key in author.favoriteArticles]
        )
开发者ID:dansalmo,项目名称:new-aca,代码行数:13,代码来源:aca.py

示例7: create

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import query [as 别名]
def create(request):
    name = request.POST["name"]
    phone = request.POST["phone"]
    email = request.POST["email"]
    author_email = request.POST["author_email"]

    author = Author.query(Author.email == author_email).get()
    if (author is None): 
        return HttpResponseServerError("Author %s not found" % author_email)
    
    supporter = Supporter(name=name, email=email, phone=phone, of=[author.key])
    supporter.put()
    return HttpResponse(json_fixed.dumps(supporter))
开发者ID:gdbelvin,项目名称:mailsafe,代码行数:15,代码来源:supporter.py

示例8: create

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import query [as 别名]
def create(request):
    author_email = request.POST["author_email"]
    text = request.POST["text"]
    subject = request.POST.get("subject")
    status = request.POST.get('status')

    author = Author.query(Author.email == author_email).get()
    if (author is None):
        return HttpResponseServerError("Author %s not found" % author_id)

    content = Content(author=author.key, text=text, subject=subject,
            status="draft")
    content.put()
    return HttpResponse(json_fixed.dumps(content))
开发者ID:gdbelvin,项目名称:mailsafe,代码行数:16,代码来源:doc.py

示例9: getFavoritesByAuthor

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import query [as 别名]
    def getFavoritesByAuthor(self, request):
        """Return favorite articles of author (key or authorID)"""

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

        # return set of ArticleForm objects per favorite article
        return ArticleForms(
            items=[self._copyArticleToForm(ndb.Key(urlsafe=key).get()) for key in author.favoriteArticles]
        )
开发者ID:dansalmo,项目名称:new-aca,代码行数:16,代码来源:aca.py

示例10: getArticle

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import query [as 别名]
    def getArticle(self, request):
        """ Return requested article by Author/Article ID.  
            A shorter URL form for published links"""
        author = Author.query()\
            .filter(Author.authorID==request.authorID)\
            .get()

        if not author:
            raise endpoints.UnauthorizedException('Invalid Author ID (%s)' % request.authorID)

        article = ndb.Key(Article, int(request.articleID), parent=author.key).get()
        if not article:
            raise endpoints.UnauthorizedException('Invalid Article ID (%s) for %s' % (request.articleID, author.displayName))

        return self._copyArticleToForm(article, author=author)
开发者ID:dansalmo,项目名称:new-aca,代码行数:17,代码来源:aca.py

示例11: create

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import query [as 别名]
def create(request):
    """
    Create an author.
    """
    name = request.POST["author_name"]
    author_email = request.POST["author_email"]

    author = Author.query(Author.email == author_email).get()
    if (author is None):
        author = Author(name=name, email=author_email)
    else:
        author.name = name
        
    author.put()
    return HttpResponse(json_fixed.dumps(author))
开发者ID:gdbelvin,项目名称:mailsafe,代码行数:17,代码来源:author.py

示例12: getArticlesByAuthor

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

示例13: setFeaturedArticles

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

示例14: get

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import query [as 别名]
def get(request, author_email):
    author = Author.query(Author.email == author_email).get()
    if (author is None):
        return HttpResponseNotFound()
    return HttpResponse(json_fixed.dumps(author))
开发者ID:gdbelvin,项目名称:mailsafe,代码行数:7,代码来源:author.py

示例15: get_supporters

# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import query [as 别名]
def get_supporters(request, author_email):
    author = Author.query(Author.email == author_email).get()
    if (author is None):
        return HttpResponseNotFound()
    supporters = Supporter.query(Supporter.of == author.key).fetch()
    return HttpResponse(json_fixed.dumps(supporters))
开发者ID:gdbelvin,项目名称:mailsafe,代码行数:8,代码来源:author.py


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