本文整理汇总了Python中superdesk.errors.ProviderError.externalProviderError方法的典型用法代码示例。如果您正苦于以下问题:Python ProviderError.externalProviderError方法的具体用法?Python ProviderError.externalProviderError怎么用?Python ProviderError.externalProviderError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类superdesk.errors.ProviderError
的用法示例。
在下文中一共展示了ProviderError.externalProviderError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from superdesk.errors import ProviderError [as 别名]
# 或者: from superdesk.errors.ProviderError import externalProviderError [as 别名]
def create(self, docs, **kwargs):
new_guids = []
provider = self.get_provider()
for doc in docs:
if not doc.get('desk'):
# if no desk is selected then it is bad request
raise SuperdeskApiError.badRequestError("Destination desk cannot be empty.")
try:
archived_doc = self.fetch(doc['guid'])
except FileNotFoundError as ex:
raise ProviderError.externalProviderError(ex, provider)
dest_doc = dict(archived_doc)
new_id = generate_guid(type=GUID_TAG)
new_guids.append(new_id)
dest_doc['_id'] = new_id
generate_unique_id_and_name(dest_doc)
if provider:
dest_doc['ingest_provider'] = str(provider[superdesk.config.ID_FIELD])
dest_doc[config.VERSION] = 1
send_to(doc=dest_doc, update=None, desk_id=doc.get('desk'), stage_id=doc.get('stage'))
dest_doc[ITEM_STATE] = doc.get(ITEM_STATE, CONTENT_STATE.FETCHED)
dest_doc[INGEST_ID] = archived_doc['_id']
dest_doc[FAMILY_ID] = archived_doc['_id']
remove_unwanted(dest_doc)
set_original_creator(dest_doc)
superdesk.get_resource_service(ARCHIVE).post([dest_doc])
insert_into_versions(dest_doc.get('_id'))
return new_guids
示例2: create
# 需要导入模块: from superdesk.errors import ProviderError [as 别名]
# 或者: from superdesk.errors.ProviderError import externalProviderError [as 别名]
def create(self, docs, **kwargs):
new_guids = []
provider = get_resource_service("ingest_providers").find_one(source="aapmm", req=None)
if provider and "config" in provider and "username" in provider["config"]:
self.backend.set_credentials(provider["config"]["username"], provider["config"]["password"])
for doc in docs:
if not doc.get("desk"):
# if no desk is selected then it is bad request
raise SuperdeskApiError.badRequestError("Destination desk cannot be empty.")
try:
archived_doc = self.backend.find_one_raw(doc["guid"], doc["guid"])
except FileNotFoundError as ex:
raise ProviderError.externalProviderError(ex, provider)
dest_doc = dict(archived_doc)
new_id = generate_guid(type=GUID_TAG)
new_guids.append(new_id)
dest_doc["_id"] = new_id
generate_unique_id_and_name(dest_doc)
if provider:
dest_doc["ingest_provider"] = str(provider[superdesk.config.ID_FIELD])
dest_doc[config.VERSION] = 1
send_to(doc=dest_doc, update=None, desk_id=doc.get("desk"), stage_id=doc.get("stage"))
dest_doc[ITEM_STATE] = doc.get(ITEM_STATE, CONTENT_STATE.FETCHED)
dest_doc[INGEST_ID] = archived_doc["_id"]
dest_doc[FAMILY_ID] = archived_doc["_id"]
remove_unwanted(dest_doc)
set_original_creator(dest_doc)
superdesk.get_resource_service(ARCHIVE).post([dest_doc])
insert_into_versions(dest_doc.get("_id"))
return new_guids
示例3: create
# 需要导入模块: from superdesk.errors import ProviderError [as 别名]
# 或者: from superdesk.errors.ProviderError import externalProviderError [as 别名]
def create(self, docs, **kwargs):
search_provider = get_resource_service('search_providers').find_one(search_provider=PROVIDER_NAME, req=None)
if not search_provider or search_provider.get('is_closed', False):
raise SuperdeskApiError.badRequestError('No search provider found or the search provider is closed.')
if 'config' in search_provider:
self.backend.set_credentials(search_provider['config'])
new_guids = []
for doc in docs:
if not doc.get('desk'): # if no desk is selected then it is bad request
raise SuperdeskApiError.badRequestError("Destination desk cannot be empty.")
try:
archived_doc = self.backend.find_one_raw(doc['guid'], doc['guid'])
except FileNotFoundError as ex:
raise ProviderError.externalProviderError(ex, search_provider)
dest_doc = dict(archived_doc)
new_id = generate_guid(type=GUID_TAG)
new_guids.append(new_id)
dest_doc[config.ID_FIELD] = new_id
generate_unique_id_and_name(dest_doc)
if search_provider:
dest_doc['ingest_provider'] = str(search_provider[config.ID_FIELD])
dest_doc[config.VERSION] = 1
send_to(doc=dest_doc, update=None, desk_id=doc.get('desk'), stage_id=doc.get('stage'))
dest_doc[ITEM_STATE] = doc.get(ITEM_STATE, CONTENT_STATE.FETCHED)
dest_doc[INGEST_ID] = archived_doc[config.ID_FIELD]
dest_doc[FAMILY_ID] = archived_doc[config.ID_FIELD]
dest_doc[ITEM_OPERATION] = ITEM_FETCH
remove_unwanted(dest_doc)
set_original_creator(dest_doc)
superdesk.get_resource_service(ARCHIVE).post([dest_doc])
insert_into_versions(dest_doc[config.ID_FIELD])
get_resource_service('search_providers').system_update(search_provider[config.ID_FIELD],
{'last_item_update': utcnow()}, search_provider)
return new_guids