本文整理汇总了Python中apps.packages.TakesPackageService.enhance_with_package_info方法的典型用法代码示例。如果您正苦于以下问题:Python TakesPackageService.enhance_with_package_info方法的具体用法?Python TakesPackageService.enhance_with_package_info怎么用?Python TakesPackageService.enhance_with_package_info使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apps.packages.TakesPackageService
的用法示例。
在下文中一共展示了TakesPackageService.enhance_with_package_info方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: enhance_with_archive_items
# 需要导入模块: from apps.packages import TakesPackageService [as 别名]
# 或者: from apps.packages.TakesPackageService import enhance_with_package_info [as 别名]
def enhance_with_archive_items(self, items):
if items:
ids = list(set([item.get('item_id') for item in items if item.get('item_id')]))
archive_items = []
if ids:
query = {'$and': [{config.ID_FIELD: {'$in': ids}}]}
archive_req = ParsedRequest()
archive_req.max_results = len(ids)
# can't access published from elastic due filter on the archive resource hence going to mongo
archive_items = list(superdesk.get_resource_service(ARCHIVE)
.get_from_mongo(req=archive_req, lookup=query))
takes_service = TakesPackageService()
for item in archive_items:
handle_existing_data(item)
takes_service.enhance_with_package_info(item)
for item in items:
archive_item = [i for i in archive_items if i.get(config.ID_FIELD) == item.get('item_id')]
archive_item = archive_item[0] if len(archive_item) > 0 else \
{config.VERSION: item.get(config.VERSION, 1)}
updates = {
config.ID_FIELD: item.get('item_id'),
'item_id': item.get(config.ID_FIELD),
'lock_user': archive_item.get('lock_user', None),
'lock_time': archive_item.get('lock_time', None),
'lock_session': archive_item.get('lock_session', None),
'archive_item': archive_item if archive_item else None
}
item.update(updates)
handle_existing_data(item)
示例2: enhance_with_archive_items
# 需要导入模块: from apps.packages import TakesPackageService [as 别名]
# 或者: from apps.packages.TakesPackageService import enhance_with_package_info [as 别名]
def enhance_with_archive_items(self, items):
if items:
ids = list(set([item.get("item_id") for item in items if item.get("item_id")]))
archive_items = []
if ids:
query = {"$and": [{config.ID_FIELD: {"$in": ids}}]}
archive_req = ParsedRequest()
archive_req.max_results = len(ids)
# can't access published from elastic due filter on the archive resource hence going to mongo
archive_items = list(
superdesk.get_resource_service(ARCHIVE).get_from_mongo(req=archive_req, lookup=query)
)
takes_service = TakesPackageService()
for item in archive_items:
handle_existing_data(item)
takes_service.enhance_with_package_info(item)
for item in items:
try:
archive_item = [i for i in archive_items if i.get(config.ID_FIELD) == item.get("item_id")][0]
except IndexError:
logger.exception(
(
"Data inconsistency found for the published item {}. "
"Cannot find item {} in the archive collection."
).format(item.get(config.ID_FIELD), item.get("item_id"))
)
archive_item = {}
updates = {
config.ID_FIELD: item.get("item_id"),
"item_id": item.get(config.ID_FIELD),
"lock_user": archive_item.get("lock_user", None),
"lock_time": archive_item.get("lock_time", None),
"lock_session": archive_item.get("lock_session", None),
"archive_item": archive_item if archive_item else None,
}
item.update(updates)
handle_existing_data(item)
示例3: enhance_with_archive_items
# 需要导入模块: from apps.packages import TakesPackageService [as 别名]
# 或者: from apps.packages.TakesPackageService import enhance_with_package_info [as 别名]
def enhance_with_archive_items(self, items):
if items:
ids = list(set([item.get('item_id') for item in items if item.get('item_id')]))
archive_items = []
if ids:
query = {'$and': [{'_id': {'$in': ids}}]}
archive_req = ParsedRequest()
archive_req.max_results = len(ids)
# can't access published from elastic due filter on the archive resource hence going to mongo
archive_items = list(superdesk.get_resource_service(ARCHIVE)
.get_from_mongo(req=archive_req, lookup=query))
takes_service = TakesPackageService()
for item in archive_items:
handle_existing_data(item)
takes_service.enhance_with_package_info(item)
for item in items:
try:
archive_item = [i for i in archive_items if i.get('_id') == item.get('item_id')][0]
except IndexError:
logger.exception(('Data inconsistency found for the published item {}. '
'Cannot find item {} in the archive collection.')
.format(item.get('_id'), item.get('item_id')))
archive_item = {}
updates = {
'_id': item.get('item_id'),
'item_id': item.get('_id'),
'lock_user': archive_item.get('lock_user', None),
'lock_time': archive_item.get('lock_time', None),
'lock_session': archive_item.get('lock_session', None),
'archive_item': archive_item if archive_item else None
}
item.update(updates)
handle_existing_data(item)