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


Python PublishQueueError.article_not_found_error方法代码示例

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


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

示例1: process_takes

# 需要导入模块: from superdesk.errors import PublishQueueError [as 别名]
# 或者: from superdesk.errors.PublishQueueError import article_not_found_error [as 别名]
    def process_takes(self, updates_of_take_to_be_published, package_id, original_of_take_to_be_published=None):
        """
        Primary rule for publishing a Take in Takes Package is: all previous takes must be published before a take
        can be published.

        This method validates if the take(s) previous to this article are published. If not published then raises error.
        Also, generates body_html of the takes package and make sure the metadata for the package is the same as the
        metadata of the take to be published.

        :param updates_of_take_to_be_published: The take to be published
        :return: Takes Package document and body_html of the Takes Package
        :raises:
            1. Article Not Found Error: If take identified by GUID in the Takes Package is not found in archive.
            2. Previous Take Not Published Error
        """

        package = super().find_one(req=None, _id=package_id)
        body_html = updates_of_take_to_be_published.get('body_html', original_of_take_to_be_published['body_html'])
        package_updates = {'body_html': body_html + '<br>'}

        groups = package.get('groups', [])
        if groups:
            take_refs = [ref for group in groups if group['id'] == 'main' for ref in group.get('refs')]
            sequence_num_of_take_to_be_published = 0

            take_article_id = updates_of_take_to_be_published.get(
                config.ID_FIELD, original_of_take_to_be_published[config.ID_FIELD])

            for r in take_refs:
                if r[GUID_FIELD] == take_article_id:
                    sequence_num_of_take_to_be_published = r[SEQUENCE]
                    break

            if sequence_num_of_take_to_be_published:
                if self.published_state != "killed":
                    for sequence in range(sequence_num_of_take_to_be_published, 0, -1):
                        previous_take_ref = next(ref for ref in take_refs if ref.get(SEQUENCE) == sequence)
                        if previous_take_ref[GUID_FIELD] != take_article_id:
                            previous_take = super().find_one(req=None, _id=previous_take_ref[GUID_FIELD])

                            if not previous_take:
                                raise PublishQueueError.article_not_found_error(
                                    Exception("Take with id %s not found" % previous_take_ref[GUID_FIELD]))

                            if previous_take and previous_take[config.CONTENT_STATE] not in ['published', 'corrected']:
                                raise PublishQueueError.previous_take_not_published_error(
                                    Exception("Take with id {} is not published in Takes Package with id {}"
                                              .format(previous_take_ref[GUID_FIELD], package[config.ID_FIELD])))

                            package_updates['body_html'] = \
                                previous_take['body_html'] + '<br>' + package_updates['body_html']

                metadata_tobe_copied = ['headline', 'abstract', 'anpa_category', 'pubstatus', 'slugline', 'urgency',
                                        'subject', 'byline', 'dateline']

                for metadata in metadata_tobe_copied:
                    package_updates[metadata] = \
                        updates_of_take_to_be_published.get(metadata, original_of_take_to_be_published.get(metadata))

        return package, package_updates
开发者ID:oxcarh,项目名称:superdesk,代码行数:62,代码来源:archive_publish.py


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