def on_update(self, updates, original): """Runs on archive update. 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: # check if there is a takes package and deschedule the takes package. takes_service = TakesPackageService() package = takes_service.get_take_package(original) if package and package.get(ITEM_STATE) == CONTENT_STATE.SCHEDULED: get_resource_service('published').delete_by_article_id(package.get(config.ID_FIELD)) self.delete_by_article_ids([package.get(config.ID_FIELD)]) updates[LINKED_IN_PACKAGES] = [package for package in original.get(LINKED_IN_PACKAGES, []) if package.get(PACKAGE_TYPE) != TAKES_PACKAGE] return if self.__is_req_for_save(updates): update_state(original, updates) remove_unwanted(updates) self._add_system_updates(original, updates, user) self._add_desk_metadata(updates, original) self._handle_media_updates(updates, original, user)
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. takes_service = TakesPackageService() package = takes_service.get_take_package(original) if package and package.get(ITEM_STATE) == CONTENT_STATE.SCHEDULED: get_resource_service('published').delete_by_article_id( package.get(config.ID_FIELD)) self.delete_by_article_ids([package.get(config.ID_FIELD)]) updates[LINKED_IN_PACKAGES] = [ package for package in original.get(LINKED_IN_PACKAGES, []) if package.get(PACKAGE_TYPE) != TAKES_PACKAGE ] return if self.__is_req_for_save(updates): update_state(original, updates) remove_unwanted(updates) self._add_system_updates(original, updates, user) self._add_desk_metadata(updates, original) if original[ITEM_TYPE] == CONTENT_TYPE.PICTURE: # create crops CropService().create_multiple_crops(updates, original) updates_feature_image = updates.get('associations', {}).get('featureimage') if updates_feature_image and 'poi' in updates_feature_image: original_feature_image = original.get('associations', {}).get('featureimage', {}) if original_feature_image and original_feature_image.get( 'poi', {}) == updates_feature_image['poi']: return _id = updates_feature_image[config.ID_FIELD] if config.ID_FIELD in updates_feature_image \ else original_feature_image[config.ID_FIELD] image_item = self.find_one(req=None, _id=_id) if image_item: image_item['poi'] = updates_feature_image['poi'] image_item = self.patch(_id, image_item) updates['associations']['featureimage'][ 'renditions'] = image_item['renditions']
def _update_rewrite(self, original): """ Removes the reference from the rewritten story in published collection """ rewrite_service = ArchiveRewriteService() if original.get('rewrite_of') and original.get('event_id'): rewrite_service._clear_rewritten_flag(original.get('event_id'), original[config.ID_FIELD], 'rewritten_by') # write the rewritten_by to the take before spiked archive_service = get_resource_service(ARCHIVE) published_service = get_resource_service('published') takes_service = TakesPackageService() takes_package = takes_service.get_take_package(original) if takes_package and takes_package.get( SEQUENCE, 0) > 1 and original.get('rewritten_by'): # get the rewritten by rewritten_by = archive_service.find_one( req=None, _id=original.get('rewritten_by')) # get the take take_id = takes_service.get_take_by_take_no( original, take_no=takes_package.get(SEQUENCE) - 1, package=takes_package) take = archive_service.find_one(req=None, _id=take_id) # update the take and takes package with rewritten_by if take.get('rewritten_by') != rewritten_by[config.ID_FIELD]: if take.get(ITEM_STATE) in PUBLISH_STATES: published_service.update_published_items( take_id, 'rewritten_by', rewritten_by[config.ID_FIELD]) archive_service.system_update( take[config.ID_FIELD], {'rewritten_by': rewritten_by[config.ID_FIELD]}, take) if takes_package.get('rewritten_by') != rewritten_by[ config.ID_FIELD]: if takes_package.get(ITEM_STATE) in PUBLISH_STATES: published_service.update_published_items( takes_package.get(config.ID_FIELD), 'rewritten_by', rewritten_by[config.ID_FIELD]) archive_service.system_update( takes_package[config.ID_FIELD], {'rewritten_by': rewritten_by[config.ID_FIELD]}, takes_package) if rewritten_by.get('rewrite_of') != takes_package.get( config.ID_FIELD): archive_service.system_update( rewritten_by[config.ID_FIELD], {'rewrite_of': takes_package.get(config.ID_FIELD)}, rewritten_by)
def on_update(self, updates, original): """Runs on archive update. 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: # check if there is a takes package and deschedule the takes package. takes_service = TakesPackageService() package = takes_service.get_take_package(original) if package and package.get(ITEM_STATE) == CONTENT_STATE.SCHEDULED: get_resource_service('published').delete_by_article_id( package.get(config.ID_FIELD)) self.delete_by_article_ids([package.get(config.ID_FIELD)]) updates[LINKED_IN_PACKAGES] = [ package for package in original.get(LINKED_IN_PACKAGES, []) if package.get(PACKAGE_TYPE) != TAKES_PACKAGE ] return if self.__is_req_for_save(updates): update_state(original, updates) remove_unwanted(updates) self._add_system_updates(original, updates, user) self._add_desk_metadata(updates, original) if original[ITEM_TYPE] == CONTENT_TYPE.PICTURE: # create crops CropService().create_multiple_crops(updates, original) # iterate over associations. Validate and process them if they are stored in database if 'associations' in updates: for item_name, item_obj in updates.get('associations').items(): if item_obj and config.ID_FIELD in item_obj: _id = item_obj[config.ID_FIELD] stored_item = self.find_one(req=None, _id=_id) if stored_item: self._validate_updates(stored_item, item_obj, user) if stored_item[ ITEM_TYPE] == CONTENT_TYPE.PICTURE: # create crops CropService().create_multiple_crops( item_obj, stored_item) stored_item.update(item_obj) updates['associations'][item_name] = stored_item
def set_usn(self, odbc_item, article): """ Set the usn (unique story number) in the odbc item :param odbc_item: :param article: :return: """ takes_package_service = TakesPackageService() pkg = takes_package_service.get_take_package(article) if pkg is not None: odbc_item['usn'] = pkg.get('unique_id', None) # @usn else: odbc_item['usn'] = article.get('unique_id', None) # @usn
def set_usn(self, odbc_item, article): """ Set the usn (unique story number) in the odbc item :param odbc_item: :param article: :return: """ takes_package_service = TakesPackageService() pkg = takes_package_service.get_take_package(article) if pkg is not None: odbc_item['usn'] = pkg.get('unique_id', None) # @usn else: odbc_item['usn'] = article.get('unique_id', None) # @usn
def _update_rewrite(self, original): """Removes the reference from the rewritten story in published collection.""" rewrite_service = ArchiveRewriteService() if original.get('rewrite_of') and original.get('event_id'): rewrite_service._clear_rewritten_flag(original.get('event_id'), original[config.ID_FIELD], 'rewritten_by') # write the rewritten_by to the take before spiked archive_service = get_resource_service(ARCHIVE) published_service = get_resource_service('published') takes_service = TakesPackageService() takes_package = takes_service.get_take_package(original) if takes_package and takes_package.get(SEQUENCE, 0) > 1 and original.get('rewritten_by'): # get the rewritten by rewritten_by = archive_service.find_one(req=None, _id=original.get('rewritten_by')) # get the take take_id = takes_service.get_take_by_take_no(original, take_no=takes_package.get(SEQUENCE) - 1, package=takes_package) take = archive_service.find_one(req=None, _id=take_id) # update the take and takes package with rewritten_by if take.get('rewritten_by') != rewritten_by[config.ID_FIELD]: if take.get(ITEM_STATE) in PUBLISH_STATES: published_service.update_published_items(take_id, 'rewritten_by', rewritten_by[config.ID_FIELD]) archive_service.system_update(take[config.ID_FIELD], {'rewritten_by': rewritten_by[config.ID_FIELD]}, take) if takes_package.get('rewritten_by') != rewritten_by[config.ID_FIELD]: if takes_package.get(ITEM_STATE) in PUBLISH_STATES: published_service.update_published_items(takes_package.get(config.ID_FIELD), 'rewritten_by', rewritten_by[config.ID_FIELD]) archive_service.system_update(takes_package[config.ID_FIELD], {'rewritten_by': rewritten_by[config.ID_FIELD]}, takes_package) if rewritten_by.get('rewrite_of') != takes_package.get(config.ID_FIELD): archive_service.system_update(rewritten_by[config.ID_FIELD], {'rewrite_of': takes_package.get(config.ID_FIELD)}, rewritten_by) elif original.get('rewritten_by') or (takes_package and takes_package.get('rewritten_by')): # you are spike the story from which the rewrite was triggered. # in this case both rewrite_of and rewritten_by are published. rewrite_id = original.get('rewritten_by') or takes_package.get('rewritten_by') rewritten_by = archive_service.find_one(req=None, _id=rewrite_id) archive_service.system_update(rewrite_id, {'rewrite_of': None, 'rewrite_sequence': 0}, rewritten_by)
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. takes_service = TakesPackageService() package = takes_service.get_take_package(original) if package and package.get(ITEM_STATE) == CONTENT_STATE.SCHEDULED: get_resource_service('published').delete_by_article_id(package.get(config.ID_FIELD)) self.delete_by_article_ids([package.get(config.ID_FIELD)]) updates[LINKED_IN_PACKAGES] = [package for package in original.get(LINKED_IN_PACKAGES, []) if package.get(PACKAGE_TYPE) != TAKES_PACKAGE] return if self.__is_req_for_save(updates): update_state(original, updates) remove_unwanted(updates) self._add_system_updates(original, updates, user) self._add_desk_metadata(updates, original) if original[ITEM_TYPE] == CONTENT_TYPE.PICTURE: # create crops CropService().create_multiple_crops(updates, original) updates_feature_image = updates.get('associations', {}).get('featureimage') if updates_feature_image and 'poi' in updates_feature_image: original_feature_image = original.get('associations', {}).get('featureimage', {}) if original_feature_image and original_feature_image.get('poi', {}) == updates_feature_image['poi']: return _id = updates_feature_image[config.ID_FIELD] if config.ID_FIELD in updates_feature_image \ else original_feature_image[config.ID_FIELD] image_item = self.find_one(req=None, _id=_id) if image_item: image_item['poi'] = updates_feature_image['poi'] image_item = self.patch(_id, image_item) updates['associations']['featureimage']['renditions'] = image_item['renditions']
def on_update(self, updates, original): """Runs on archive update. 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: # check if there is a takes package and deschedule the takes package. takes_service = TakesPackageService() package = takes_service.get_take_package(original) if package and package.get(ITEM_STATE) == CONTENT_STATE.SCHEDULED: get_resource_service('published').delete_by_article_id(package.get(config.ID_FIELD)) self.delete_by_article_ids([package.get(config.ID_FIELD)]) updates[LINKED_IN_PACKAGES] = [package for package in original.get(LINKED_IN_PACKAGES, []) if package.get(PACKAGE_TYPE) != TAKES_PACKAGE] return if self.__is_req_for_save(updates): update_state(original, updates) remove_unwanted(updates) self._add_system_updates(original, updates, user) self._add_desk_metadata(updates, original) if original[ITEM_TYPE] == CONTENT_TYPE.PICTURE: # create crops CropService().create_multiple_crops(updates, original) # iterate over associations. Validate and process them if they are stored in database if 'associations' in updates: for item_name, item_obj in updates.get('associations').items(): if item_obj and config.ID_FIELD in item_obj: _id = item_obj[config.ID_FIELD] stored_item = self.find_one(req=None, _id=_id) if stored_item: self._validate_updates(stored_item, item_obj, user) if stored_item[ITEM_TYPE] == CONTENT_TYPE.PICTURE: # create crops CropService().create_multiple_crops(item_obj, stored_item) stored_item.update(item_obj) updates['associations'][item_name] = stored_item
def update_rewrite(self, original): """Removes the reference from the rewritten story in published collection.""" rewrite_service = ArchiveRewriteService() if original.get('rewrite_of') and original.get(ITEM_EVENT_ID): rewrite_service._clear_rewritten_flag(original.get(ITEM_EVENT_ID), original[config.ID_FIELD], 'rewritten_by') # write the rewritten_by to the take before spiked archive_service = get_resource_service(ARCHIVE) published_service = get_resource_service('published') takes_service = TakesPackageService() takes_package = takes_service.get_take_package(original) if takes_package and takes_package.get( SEQUENCE, 0) > 1 and original.get('rewritten_by'): # get the rewritten by rewritten_by = archive_service.find_one( req=None, _id=original.get('rewritten_by')) # get the take take_id = takes_service.get_take_by_take_no( original, take_no=takes_package.get(SEQUENCE) - 1, package=takes_package) take = archive_service.find_one(req=None, _id=take_id) # update the take and takes package with rewritten_by if take.get('rewritten_by') != rewritten_by[config.ID_FIELD]: if take.get(ITEM_STATE) in PUBLISH_STATES: published_service.update_published_items( take_id, 'rewritten_by', rewritten_by[config.ID_FIELD]) archive_service.system_update( take[config.ID_FIELD], {'rewritten_by': rewritten_by[config.ID_FIELD]}, take) if takes_package.get('rewritten_by') != rewritten_by[ config.ID_FIELD]: if takes_package.get(ITEM_STATE) in PUBLISH_STATES: published_service.update_published_items( takes_package.get(config.ID_FIELD), 'rewritten_by', rewritten_by[config.ID_FIELD]) archive_service.system_update( takes_package[config.ID_FIELD], {'rewritten_by': rewritten_by[config.ID_FIELD]}, takes_package) if rewritten_by.get('rewrite_of') != takes_package.get( config.ID_FIELD): archive_service.system_update( rewritten_by[config.ID_FIELD], {'rewrite_of': takes_package.get(config.ID_FIELD)}, rewritten_by) elif original.get('rewritten_by') or ( takes_package and takes_package.get('rewritten_by')): # you are spike the story from which the rewrite was triggered. # in this case both rewrite_of and rewritten_by are published. rewrite_id = original.get('rewritten_by') or takes_package.get( 'rewritten_by') rewritten_by = archive_service.find_one(req=None, _id=rewrite_id) archive_service.system_update(rewrite_id, { 'rewrite_of': None, 'rewrite_sequence': 0 }, rewritten_by) app.on_archive_item_updated( { 'rewrite_of': None, 'rewrite_sequence': 0 }, original, ITEM_UNLINK)