本文整理汇总了Python中superdesk.errors.PublishQueueError.previous_take_not_published_error方法的典型用法代码示例。如果您正苦于以下问题:Python PublishQueueError.previous_take_not_published_error方法的具体用法?Python PublishQueueError.previous_take_not_published_error怎么用?Python PublishQueueError.previous_take_not_published_error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类superdesk.errors.PublishQueueError
的用法示例。
在下文中一共展示了PublishQueueError.previous_take_not_published_error方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_takes
# 需要导入模块: from superdesk.errors import PublishQueueError [as 别名]
# 或者: from superdesk.errors.PublishQueueError import previous_take_not_published_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
示例2: _validate
# 需要导入模块: from superdesk.errors import PublishQueueError [as 别名]
# 或者: from superdesk.errors.PublishQueueError import previous_take_not_published_error [as 别名]
def _validate(self, original, updates):
self.raise_if_not_marked_for_publication(original)
self.raise_if_invalid_state_transition(original)
updated = original.copy()
updated.update(updates)
takes_package = self.takes_package_service.get_take_package(original)
if self.publish_type == 'publish':
# validate if take can be published
if takes_package and not self.takes_package_service.can_publish_take(
takes_package, updates.get(SEQUENCE, original.get(SEQUENCE, 1))):
raise PublishQueueError.previous_take_not_published_error(
Exception("Previous takes are not published."))
update_schedule_settings(updated, PUBLISH_SCHEDULE, updated.get(PUBLISH_SCHEDULE))
validate_schedule(updated.get(SCHEDULE_SETTINGS, {}).get('utc_{}'.format(PUBLISH_SCHEDULE)),
takes_package.get(SEQUENCE, 1) if takes_package else 1)
if original[ITEM_TYPE] != CONTENT_TYPE.COMPOSITE and updates.get(EMBARGO):
update_schedule_settings(updated, EMBARGO, updated.get(EMBARGO))
get_resource_service(ARCHIVE).validate_embargo(updated)
if self.publish_type in [ITEM_CORRECT, ITEM_KILL]:
if updates.get(EMBARGO) and not original.get(EMBARGO):
raise SuperdeskApiError.badRequestError("Embargo can't be set after publishing")
if self.publish_type in [ITEM_CORRECT, ITEM_KILL]:
if updates.get('dateline'):
raise SuperdeskApiError.badRequestError("Dateline can't be modified after publishing")
if self.publish_type == ITEM_PUBLISH and updated.get('rewritten_by'):
# if update is published then user cannot publish the takes
rewritten_by = get_resource_service(ARCHIVE).find_one(req=None, _id=updated.get('rewritten_by'))
if rewritten_by and rewritten_by.get(ITEM_STATE) in PUBLISH_STATES:
raise SuperdeskApiError.badRequestError("Cannot publish the story after Update is published.!")
publish_type = 'auto_publish' if updates.get('auto_publish') else self.publish_type
validate_item = {'act': publish_type, 'type': original['type'], 'validate': updated}
validation_errors = get_resource_service('validate').post([validate_item])
if validation_errors[0]:
raise ValidationError(validation_errors)
validation_errors = []
self._validate_associated_items(original, takes_package, validation_errors)
if original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE:
self._validate_package(original, updates, validation_errors)
if len(validation_errors) > 0:
raise ValidationError(validation_errors)
示例3: on_update
# 需要导入模块: from superdesk.errors import PublishQueueError [as 别名]
# 或者: from superdesk.errors.PublishQueueError import previous_take_not_published_error [as 别名]
def on_update(self, updates, original):
self.raise_if_not_marked_for_publication(original)
self.raise_if_invalid_state_transition(original)
updated = original.copy()
updated.update(updates)
takes_package = self.takes_package_service.get_take_package(original)
if self.publish_type == "publish":
# validate if take can be published
if takes_package and not self.takes_package_service.can_publish_take(
takes_package, updates.get(SEQUENCE, original.get(SEQUENCE, 1))
):
raise PublishQueueError.previous_take_not_published_error(
Exception("Previous takes are not published.")
)
validate_schedule(updated.get("publish_schedule"), takes_package.get(SEQUENCE, 1) if takes_package else 1)
if original[ITEM_TYPE] != CONTENT_TYPE.COMPOSITE and updates.get(EMBARGO):
get_resource_service(ARCHIVE).validate_embargo(updated)
if self.publish_type in ["correct", "kill"]:
if updates.get(EMBARGO):
raise SuperdeskApiError.badRequestError("Embargo can't be set after publishing")
if updates.get("dateline"):
raise SuperdeskApiError.badRequestError("Dateline can't be modified after publishing")
validate_item = {"act": self.publish_type, "type": original["type"], "validate": updated}
validation_errors = get_resource_service("validate").post([validate_item])
if validation_errors[0]:
raise ValidationError(validation_errors)
# validate the package if it is one
package_validation_errors = []
self._validate_package_contents(original, takes_package, package_validation_errors)
if len(package_validation_errors) > 0:
raise ValidationError(package_validation_errors)
self._set_updates(original, updates, updates.get(config.LAST_UPDATED, utcnow()))
updates[ITEM_OPERATION] = ITEM_PUBLISH
convert_task_attributes_to_objectId(updates)
示例4: on_update
# 需要导入模块: from superdesk.errors import PublishQueueError [as 别名]
# 或者: from superdesk.errors.PublishQueueError import previous_take_not_published_error [as 别名]
def on_update(self, updates, original):
self.raise_if_not_marked_for_publication(original)
self.raise_if_invalid_state_transition(original)
updated = original.copy()
updated.update(updates)
takes_package = self.takes_package_service.get_take_package(original)
if self.publish_type == 'publish':
# validate if take can be published
if takes_package and not self.takes_package_service.can_publish_take(
takes_package, updates.get(SEQUENCE, original.get(SEQUENCE, 1))):
raise PublishQueueError.previous_take_not_published_error(
Exception("Previous takes are not published."))
validate_schedule(updated.get('publish_schedule'), takes_package.get(SEQUENCE, 1) if takes_package else 1)
if original[ITEM_TYPE] != CONTENT_TYPE.COMPOSITE and updates.get(EMBARGO):
get_resource_service(ARCHIVE).validate_embargo(updated)
if self.publish_type in ['correct', 'kill']:
if updates.get(EMBARGO):
raise SuperdeskApiError.badRequestError("Embargo can't be set after publishing")
if updates.get('dateline'):
raise SuperdeskApiError.badRequestError("Dateline can't be modified after publishing")
validate_item = {'act': self.publish_type, 'type': original['type'], 'validate': updated}
validation_errors = get_resource_service('validate').post([validate_item])
if validation_errors[0]:
raise ValidationError(validation_errors)
# validate the package if it is one
package_validation_errors = []
self._validate_package_contents(original, takes_package, package_validation_errors)
if len(package_validation_errors) > 0:
raise ValidationError(package_validation_errors)
self._set_updates(original, updates, updates.get(config.LAST_UPDATED, utcnow()))