def create(self, docs, **kwargs): doc = docs[0] if len(docs) > 0 else {} article_id = request.view_args["original_id"] article_version = doc.get("version") article = self._validate_article(article_id, article_version) subscribers = self._validate_subscribers(doc.get("subscribers"), article) remove_is_queued(article) get_enqueue_service(article.get(ITEM_OPERATION)).resend(article, subscribers) app.on_archive_item_updated({"subscribers": doc.get("subscribers")}, article, ITEM_RESEND) return [article_id]
def on_update(self, updates, original): CropService().validate_multiple_crops(updates, original) super().on_update(updates, original) remove_is_queued(updates) 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) flush_renditions(updates, original) self.change_being_corrected_to_published(updates, original)
def create(self, docs, **kwargs): guid_of_item_to_be_duplicated = request.view_args["guid"] guid_of_duplicated_items = [] for doc in docs: archive_service = get_resource_service(ARCHIVE) archived_doc = {} if doc.get("type") == "archived": archived_service = get_resource_service("archived") req = ParsedRequest() query = { "query": { "filtered": { "filter": { "bool": { "must": [{ "term": { "item_id": doc.get("item_id") } }] } } } }, "sort": [{ "_current_version": "desc" }], "size": 1, } req.args = {"source": json.dumps(query)} archived_docs = archived_service.get(req=req, lookup=None) if archived_docs.count() > 0: archived_doc = archived_docs[0] else: archived_doc = archive_service.find_one( req=None, _id=guid_of_item_to_be_duplicated) self._validate(archived_doc, doc, guid_of_item_to_be_duplicated) # reset timestamps archived_doc["versioncreated"] = archived_doc[ "firstcreated"] = utcnow() archived_doc["firstpublished"] = None remove_is_queued(archived_doc) send_to( doc=archived_doc, desk_id=doc.get("desk"), stage_id=doc.get("stage"), default_stage="working_stage", user_id=get_user_id(), ) if not doc.get("desk"): # item copied to personal space archived_doc["state"] = CONTENT_STATE.PROGRESS new_guid = archive_service.duplicate_content(archived_doc) guid_of_duplicated_items.append(new_guid) if kwargs.get("notify", True): push_content_notification([archived_doc]) return guid_of_duplicated_items
def _translate_item(self, guid, language, task=None, service=None, state=None, **kwargs): if not service: service = ARCHIVE archive_service = get_resource_service(service) macros_service = get_resource_service("macros") published_service = get_resource_service("published") item = archive_service.find_one(req=None, _id=guid) if not item: raise SuperdeskApiError.notFoundError( _("Failed to find item with guid: {guid}").format(guid=guid)) if not is_workflow_state_transition_valid("translate", item[ITEM_STATE]): raise InvalidStateTransitionError() if item.get("language") == language: return guid if package_service.is_package(item): refs = package_service.get_item_refs(item) for ref in refs: ref[RESIDREF] = self._translate_item( ref[RESIDREF], language, service=ref.get("location"), task=task) if not item.get("translation_id"): item["translation_id"] = item["guid"] macros_service.execute_translation_macro(item, item.get("language", None), language) item["language"] = language item["translated_from"] = guid item["versioncreated"] = utcnow() item["firstcreated"] = utcnow() if task: item["task"] = task remove_is_queued(item) extra_fields = ["translation_id", "translated_from"] UPDATE_TRANSLATION_METADATA_MACRO = app.config.get( "UPDATE_TRANSLATION_METADATA_MACRO") if UPDATE_TRANSLATION_METADATA_MACRO and macros_service.get_macro_by_name( UPDATE_TRANSLATION_METADATA_MACRO): macros_service.execute_macro(item, UPDATE_TRANSLATION_METADATA_MACRO) translation_guid = archive_service.duplicate_item( item, extra_fields=extra_fields, state=state, operation="translate") item.setdefault("translations", []).append(translation_guid) updates = { "translation_id": item["translation_id"], "translations": item["translations"], } archive_service.system_update(item["_id"], updates, item) published_service.update_published_items(item["_id"], "translation_id", item["_id"]) published_service.update_published_items(item["_id"], "translations", item["translations"]) if kwargs.get("notify", True): push_content_notification([item]) return translation_guid