本文整理汇总了Python中apps.packages.TakesPackageService.get方法的典型用法代码示例。如果您正苦于以下问题:Python TakesPackageService.get方法的具体用法?Python TakesPackageService.get怎么用?Python TakesPackageService.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apps.packages.TakesPackageService
的用法示例。
在下文中一共展示了TakesPackageService.get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_update
# 需要导入模块: from apps.packages import TakesPackageService [as 别名]
# 或者: from apps.packages.TakesPackageService import get [as 别名]
def on_update(self, updates, original):
"""
Overridden to validate the updates to the article and take necessary actions depending on the updates. In brief,
it does the following:
1. Sets state, item operation, version created, version creator, sign off and word count.
2. Resets Item Expiry
3. If the request is to de-schedule then checks and de-schedules the associated Takes Package also.
4. Creates Crops if article is a picture
"""
user = get_user()
self._validate_updates(original, updates, user)
if 'publish_schedule' in updates and original[ITEM_STATE] == CONTENT_STATE.SCHEDULED:
self.deschedule_item(updates, original) # this is an deschedule action
# check if there is a takes package and deschedule the takes package.
package = TakesPackageService().get_take_package(original)
if package and package.get('state') == 'scheduled':
package_updates = {'publish_schedule': None, 'groups': package.get('groups')}
self.patch(package.get(config.ID_FIELD), package_updates)
return
if self.__is_req_for_save(updates):
update_state(original, updates)
remove_unwanted(updates)
self._add_system_updates(original, updates, user)
if original[ITEM_TYPE] == CONTENT_TYPE.PICTURE: # create crops
CropService().create_multiple_crops(updates, original)
示例2: validate_embargo
# 需要导入模块: from apps.packages import TakesPackageService [as 别名]
# 或者: from apps.packages.TakesPackageService import get [as 别名]
def validate_embargo(self, item):
"""
Validates the embargo of the item. Following are checked:
1. Item can't be a package or a take or a re-write of another story
2. Publish Schedule and Embargo are mutually exclusive
3. Always a future date except in case of Corrected and Killed.
:raises: SuperdeskApiError.badRequestError() if the validation fails
"""
if item[ITEM_TYPE] != CONTENT_TYPE.COMPOSITE:
if EMBARGO in item:
embargo = item.get(SCHEDULE_SETTINGS, {}).get('utc_{}'.format(EMBARGO))
if embargo:
if item.get(PUBLISH_SCHEDULE) or item[ITEM_STATE] == CONTENT_STATE.SCHEDULED:
raise SuperdeskApiError.badRequestError("An item can't have both Publish Schedule and Embargo")
if (item[ITEM_STATE] not in {CONTENT_STATE.KILLED, CONTENT_STATE.SCHEDULED}) \
and embargo <= utcnow():
raise SuperdeskApiError.badRequestError("Embargo cannot be earlier than now")
package = TakesPackageService().get_take_package(item)
if package and package.get(SEQUENCE, 1) > 1:
raise SuperdeskApiError.badRequestError("Takes doesn't support Embargo")
if item.get('rewrite_of'):
raise SuperdeskApiError.badRequestError("Rewrites doesn't support Embargo")
if not isinstance(embargo, datetime.date) or not embargo.time():
raise SuperdeskApiError.badRequestError("Invalid Embargo")
elif is_normal_package(item):
if item.get(EMBARGO):
raise SuperdeskApiError.badRequestError("A Package doesn't support Embargo")
self.packageService.check_if_any_item_in_package_has_embargo(item)
示例3: _validate_updates
# 需要导入模块: from apps.packages import TakesPackageService [as 别名]
# 或者: from apps.packages.TakesPackageService import get [as 别名]
def _validate_updates(self, original, updates, user):
"""
Validates updates to the article for the below conditions, if any of them then exception is raised:
1. Is article locked by another user other than the user requesting for update
2. Is state of the article is Killed?
3. Is user trying to update the package with Public Service Announcements?
4. Is user authorized to update unique name of the article?
5. Is user trying to update the genre of a broadcast article?
6. Is article being scheduled and is in a package?
7. Is article being scheduled and schedule timestamp is invalid?
8. Does article has valid crops if the article type is a picture?
9. Is article a valid package if the article type is a package?
10. Does article has a valid Embargo?
11. Make sure that there are no duplicate anpa_category codes in the article.
12. Make sure there are no duplicate subjects in the upadte
:raises:
SuperdeskApiError.forbiddenError()
- if state of the article is killed or user is not authorized to update unique name or if article is
locked by another user
SuperdeskApiError.badRequestError()
- if Public Service Announcements are being added to a package or genre is being updated for a
broadcast, is invalid for scheduling, the updates contain duplicate anpa_category or subject codes
"""
lock_user = original.get('lock_user', None)
force_unlock = updates.get('force_unlock', False)
str_user_id = str(user.get(config.ID_FIELD)) if user else None
if lock_user and str(lock_user) != str_user_id and not force_unlock:
raise SuperdeskApiError.forbiddenError('The item was locked by another user')
if original.get(ITEM_STATE) == CONTENT_STATE.KILLED:
raise SuperdeskApiError.forbiddenError("Item isn't in a valid state to be updated.")
if updates.get('body_footer') and is_normal_package(original):
raise SuperdeskApiError.badRequestError("Package doesn't support Public Service Announcements")
if 'unique_name' in updates and not is_admin(user) \
and (user['active_privileges'].get('metadata_uniquename', 0) == 0):
raise SuperdeskApiError.forbiddenError("Unauthorized to modify Unique Name")
# if broadcast then update to genre is not allowed.
if original.get('broadcast') and updates.get('genre') and \
any(genre.get('value', '').lower() != BROADCAST_GENRE.lower() for genre in updates.get('genre')):
raise SuperdeskApiError.badRequestError('Cannot change the genre for broadcast content.')
if updates.get('publish_schedule') and original[ITEM_STATE] != CONTENT_STATE.SCHEDULED \
and datetime.datetime.fromtimestamp(0).date() != updates['publish_schedule'].date():
if is_item_in_package(original):
raise SuperdeskApiError.badRequestError(
'This item is in a package and it needs to be removed before the item can be scheduled!')
package = TakesPackageService().get_take_package(original) or {}
validate_schedule(updates['publish_schedule'], package.get(SEQUENCE, 1))
if original[ITEM_TYPE] == CONTENT_TYPE.PICTURE:
CropService().validate_multiple_crops(updates, original)
elif original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE:
self.packageService.on_update(updates, original)
# Do the validation after Circular Reference check passes in Package Service
updated = original.copy()
updated.update(updates)
self.validate_embargo(updated)
# Ensure that there are no duplicate categories in the update
category_qcodes = [q['qcode'] for q in updates.get('anpa_category', []) or []]
if category_qcodes and len(category_qcodes) != len(set(category_qcodes)):
raise SuperdeskApiError.badRequestError("Duplicate category codes are not allowed")
# Ensure that there are no duplicate subjects in the update
subject_qcodes = [q['qcode'] for q in updates.get('subject', []) or []]
if subject_qcodes and len(subject_qcodes) != len(set(subject_qcodes)):
raise SuperdeskApiError.badRequestError("Duplicate subjects are not allowed")
示例4: on_update
# 需要导入模块: from apps.packages import TakesPackageService [as 别名]
# 或者: from apps.packages.TakesPackageService import get [as 别名]
def on_update(self, updates, original):
updates[ITEM_OPERATION] = ITEM_UPDATE
is_update_allowed(original)
user = get_user()
if 'publish_schedule' in updates and original['state'] == 'scheduled':
# this is an deschedule action
self.deschedule_item(updates, original)
# check if there is a takes package and deschedule the takes package.
package = TakesPackageService().get_take_package(original)
if package and package.get('state') == 'scheduled':
package_updates = {'publish_schedule': None, 'groups': package.get('groups')}
self.patch(package.get(config.ID_FIELD), package_updates)
return
if updates.get('publish_schedule'):
if datetime.datetime.fromtimestamp(0).date() == updates.get('publish_schedule').date():
# publish_schedule field will be cleared
updates['publish_schedule'] = None
else:
# validate the schedule
if is_item_in_package(original):
raise SuperdeskApiError.badRequestError(message='This item is in a package' +
' it needs to be removed before the item can be scheduled!')
package = TakesPackageService().get_take_package(original) or {}
validate_schedule(updates.get('publish_schedule'), package.get(SEQUENCE, 1))
if 'unique_name' in updates and not is_admin(user) \
and (user['active_privileges'].get('metadata_uniquename', 0) == 0):
raise SuperdeskApiError.forbiddenError("Unauthorized to modify Unique Name")
remove_unwanted(updates)
if self.__is_req_for_save(updates):
update_state(original, updates)
lock_user = original.get('lock_user', None)
force_unlock = updates.get('force_unlock', False)
updates.setdefault('original_creator', original.get('original_creator'))
str_user_id = str(user.get('_id')) if user else None
if lock_user and str(lock_user) != str_user_id and not force_unlock:
raise SuperdeskApiError.forbiddenError('The item was locked by another user')
updates['versioncreated'] = utcnow()
set_item_expiry(updates, original)
updates['version_creator'] = str_user_id
set_sign_off(updates, original=original)
update_word_count(updates)
if force_unlock:
del updates['force_unlock']
# create crops
crop_service = ArchiveCropService()
crop_service.validate_multiple_crops(updates, original)
crop_service.create_multiple_crops(updates, original)
if original[ITEM_TYPE] == CONTENT_TYPE.COMPOSITE:
self.packageService.on_update(updates, original)
update_version(updates, original)
# Do the validation after Circular Reference check passes in Package Service
updated = original.copy()
updated.update(updates)
self.validate_embargo(updated)