def on_update(self, updates, original): CropService().validate_multiple_crops(updates, original) super().on_update(updates, original) updates[ITEM_OPERATION] = ITEM_CORRECT updates['versioncreated'] = utcnow() updates['correction_sequence'] = original.get('correction_sequence', 1) + 1 set_sign_off(updates, original) update_associations(updates)
def on_update(self, updates, original): update_associations(updates) CropService().validate_multiple_crops(updates, original) super().on_update(updates, original) updates[ITEM_OPERATION] = self.item_operation updates['versioncreated'] = utcnow() updates['correction_sequence'] = original.get('correction_sequence', 1) + 1 set_sign_off(updates, original) update_word_count(updates, original)
def test_update_associations(self): doc = { 'fields_meta': { 'body_html': { 'draftjsState': [{ 'entityMap': { '1': { 'mutability': 'MUTABLE', 'type': 'MEDIA', 'data': { 'media': { 'guid': 'guid1', 'type': 'picture', 'alt_text': 'media 1' } } }, '0': { 'mutability': 'MUTABLE', 'type': 'MEDIA', 'data': { 'media': { 'guid': 'guid0', 'type': 'picture', 'alt_text': 'media 0' } } }, '2': { 'mutability': 'MUTABLE', 'type': 'MEDIA', 'data': { 'media': { 'guid': 'guid2', 'type': 'picture', 'alt_text': 'media 2' } } } } }]}}, 'associations': { 'editor_1': {'guid': 'guid10', 'type': 'picture10', 'alt_text': 'media 10'}, 'editor_7': {'guid': 'guid7', 'type': 'picture7', 'alt_text': 'media 7'}, 'featuremedia': {'guid': 'guid11', 'type': 'picture11'}} } update_associations(doc) self.assertEqual(len(doc['associations']), 5) self.assertEqual(doc['associations']['editor_0'], {'guid': 'guid0', 'type': 'picture', 'alt_text': 'media 0'}) self.assertEqual(doc['associations']['editor_1'], {'guid': 'guid1', 'type': 'picture', 'alt_text': 'media 1'}) self.assertEqual(doc['associations']['editor_2'], {'guid': 'guid2', 'type': 'picture', 'alt_text': 'media 2'}) self.assertEqual(doc['associations']['editor_7'], None) self.assertEqual(doc['associations']['featuremedia'], {'guid': 'guid11', 'type': 'picture11'})
def create(self, docs, **kwargs): doc = docs[0] if len(docs) > 0 else {} original_id = request.view_args["original_id"] update_document = doc.get("update") archive_service = get_resource_service(ARCHIVE) original = archive_service.find_one(req=None, _id=original_id) self._validate_rewrite(original, update_document) rewrite = self._create_rewrite_article(original, existing_item=update_document, desk_id=doc.get("desk_id")) # sync editor state copy_fields(original, rewrite, ignore_empty=True) if update_document: # copy editor state from existing item to preserve those copy_fields(update_document, rewrite, ignore_empty=True) if rewrite.get("fields_meta"): generate_fields(rewrite, force=True) update_associations(rewrite) # signal item_rewrite.send(self, item=rewrite, original=original) if update_document: # process the existing story archive_service.patch(update_document[config.ID_FIELD], rewrite) app.on_archive_item_updated(rewrite, update_document, ITEM_LINK) rewrite[config.ID_FIELD] = update_document[config.ID_FIELD] ids = [update_document[config.ID_FIELD]] else: # Set the version. resolve_document_version(rewrite, ARCHIVE, "POST") ids = archive_service.post([rewrite]) insert_into_versions(doc=rewrite) build_custom_hateoas(CUSTOM_HATEOAS, rewrite) app.on_archive_item_updated( {"rewrite_of": rewrite.get("rewrite_of")}, rewrite, ITEM_LINK) self._add_rewritten_flag(original, rewrite) get_resource_service("archive_broadcast").on_broadcast_master_updated( ITEM_CREATE, item=original, rewrite_id=ids[0]) doc.clear() doc.update(rewrite) return ids
def create(self, docs, **kwargs): doc = docs[0] if len(docs) > 0 else {} original_id = request.view_args['original_id'] update_document = doc.get('update') archive_service = get_resource_service(ARCHIVE) original = archive_service.find_one(req=None, _id=original_id) self._validate_rewrite(original, update_document) rewrite = self._create_rewrite_article(original, existing_item=update_document, desk_id=doc.get('desk_id')) if 'body_html' in rewrite: if 'fields_meta' in original: rewrite['fields_meta'] = original['fields_meta'] update_associations(rewrite) # signal item_rewrite.send(self, item=rewrite, original=original) if update_document: # process the existing story archive_service.patch(update_document[config.ID_FIELD], rewrite) app.on_archive_item_updated(rewrite, update_document, ITEM_LINK) rewrite[config.ID_FIELD] = update_document[config.ID_FIELD] ids = [update_document[config.ID_FIELD]] else: # Set the version. resolve_document_version(rewrite, ARCHIVE, "POST") ids = archive_service.post([rewrite]) insert_into_versions(doc=rewrite) build_custom_hateoas(CUSTOM_HATEOAS, rewrite) app.on_archive_item_updated( {'rewrite_of': rewrite.get('rewrite_of')}, rewrite, ITEM_LINK) self._add_rewritten_flag(original, rewrite) get_resource_service('archive_broadcast').on_broadcast_master_updated( ITEM_CREATE, item=original, rewrite_id=ids[0]) doc.clear() doc.update(rewrite) return ids
def create(self, docs, **kwargs): doc = docs[0] if len(docs) > 0 else {} original_id = request.view_args['original_id'] update_document = doc.get('update') archive_service = get_resource_service(ARCHIVE) original = archive_service.find_one(req=None, _id=original_id) self._validate_rewrite(original, update_document) rewrite = self._create_rewrite_article(original, existing_item=update_document, desk_id=doc.get('desk_id')) if 'body_html' in rewrite: if 'fields_meta' in original: rewrite['fields_meta'] = original['fields_meta'] update_associations(rewrite) if update_document: # process the existing story archive_service.patch(update_document[config.ID_FIELD], rewrite) app.on_archive_item_updated(rewrite, update_document, ITEM_LINK) rewrite[config.ID_FIELD] = update_document[config.ID_FIELD] ids = [update_document[config.ID_FIELD]] else: # Set the version. resolve_document_version(rewrite, ARCHIVE, "POST") ids = archive_service.post([rewrite]) insert_into_versions(doc=rewrite) build_custom_hateoas(CUSTOM_HATEOAS, rewrite) app.on_archive_item_updated({'rewrite_of': rewrite.get('rewrite_of')}, rewrite, ITEM_LINK) self._add_rewritten_flag(original, rewrite) get_resource_service('archive_broadcast').on_broadcast_master_updated(ITEM_CREATE, item=original, rewrite_id=ids[0]) doc.clear() doc.update(rewrite) return ids
def test_update_associations(self): doc = { "fields_meta": { "body_html": { "draftjsState": [{ "entityMap": { "1": { "mutability": "MUTABLE", "type": "MEDIA", "data": { "media": { "guid": "guid1", "type": "picture", "alt_text": "media 1" } }, }, "0": { "mutability": "MUTABLE", "type": "MEDIA", "data": { "media": { "guid": "guid0", "type": "picture", "alt_text": "media 0" } }, }, "2": { "mutability": "MUTABLE", "type": "MEDIA", "data": { "media": { "guid": "guid2", "type": "picture", "alt_text": "media 2" } }, }, } }] } }, "associations": { "editor_1": { "guid": "guid10", "type": "picture10", "alt_text": "media 10" }, "editor_7": { "guid": "guid7", "type": "picture7", "alt_text": "media 7" }, "featuremedia": { "guid": "guid11", "type": "picture11" }, }, } update_associations(doc) self.assertEqual(len(doc["associations"]), 5) self.assertEqual(doc["associations"]["editor_0"], { "guid": "guid0", "type": "picture", "alt_text": "media 0" }) self.assertEqual(doc["associations"]["editor_1"], { "guid": "guid1", "type": "picture", "alt_text": "media 1" }) self.assertEqual(doc["associations"]["editor_2"], { "guid": "guid2", "type": "picture", "alt_text": "media 2" }) self.assertEqual(doc["associations"]["editor_7"], None) self.assertEqual(doc["associations"]["featuremedia"], { "guid": "guid11", "type": "picture11" })