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


Python Comment.allocate_ids方法代码示例

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


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

示例1: createComment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import allocate_ids [as 别名]
    def createComment(self, request):
        """Create new Comment object, returning CommentForm/request."""
        
        author = self._getAuthorFromUser()
        data['authorName'] = author.displayName
        data['authorID'] = author.authorID

        self._checkComment(request)

        data = {'comment': request.comment}

        # get the article key for where the comment will be added
        article_key = self._checkKey(request.websafeArticleKey, 'Article')

        comment_id = Comment.allocate_ids(size=1, parent=article_key)[0]
        comment_key = ndb.Key(Comment, comment_id, parent=article_key)
        data['key'] = comment_key

        # create Comment
        comment_key = Comment(**data).put()

        # send alerts to all authors of Article and all other comments
        #taskqueue.add(params={'email': author.mainEmail,
        #    'CommentInfo': repr(request)},
        #    url='/tasks/send_comment_alert'
        #)

        return self._copyCommentToForm(comment_key.get(), article_key=article_key, author=author)
开发者ID:dansalmo,项目名称:new-aca,代码行数:30,代码来源:aca.py

示例2: copyArticlesKind

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import allocate_ids [as 别名]
    def copyArticlesKind(self, article, author):
        """Create new Article and Comment objects from old Articles object, returning True if success."""
        
        article_id = Article.allocate_ids(size=1, parent=author.key)[0]
        article_key = ndb.Key(Article, article_id, parent=author.key)
        a = article_key.get()
        if a:
            return

        # copy ArticleForm/ProtoRPC Message into dict
        data = db.to_dict(article)
        data['key'] = article_key

        if 'comments' in data:
            for comment in data['comments']:
                #Create new Comment object
                comment_author_email = str(loads(str(comment))[1])
                a_key = ndb.Key(Author, comment_author_email or 'unknown')
                comment_author = a_key.get()
                # create new Author if not there
                if not comment_author:
                    comment_author = Author(
                        key = a_key,
                        authorID = str(Author.allocate_ids(size=1)[0]),
                        displayName = comment_author_email.split('@')[0],
                        mainEmail = comment_author_email,
                    )
                    comment_author.put()

                comment_data = {
                    'comment': loads(str(comment))[0],
                    'authorName': comment_author.displayName if comment_author else 'unknown',
                    'authorID': comment_author.authorID if comment_author else 'unknown',
                    'dateCreated': loads(str(comment))[2]
                }

                comment_id = Comment.allocate_ids(size=1, parent=article_key)[0]
                comment_key = ndb.Key(Comment, comment_id, parent=article_key)
                comment_data['key'] = comment_key

                # create Comment
                Comment(**comment_data).put()

            del data['comments']

        if 'tags' in data:
            #del data['tags']
            try:
                data['tags'] = str(data['tags']).split(', ')
            except UnicodeEncodeError:
                del data['tags']
        if 'tags' in data and data['tags'] == [""]:
            del data['tags']

        if 'id' in data:
            del data['id']

        if data['view'] == None:
            del data['view']
        else:
            data['view'] = {'Publish': 'PUBLISHED', 'Preview': 'NOT_PUBLISHED', 'Retract': 'RETRACTED'}[str(data['view'])]

        data['legacyID'] = str(article.key().id())

        data['authorName'] = author.displayName
        del data['author']
        data['dateCreated'] = data['date']
        del data['date']

        # create Article
        Article(**data).put()
开发者ID:dansalmo,项目名称:new-aca,代码行数:73,代码来源:aca.py


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