本文整理汇总了Python中apps.packages.TakesPackageService.enhance_items_with_takes_packages方法的典型用法代码示例。如果您正苦于以下问题:Python TakesPackageService.enhance_items_with_takes_packages方法的具体用法?Python TakesPackageService.enhance_items_with_takes_packages怎么用?Python TakesPackageService.enhance_items_with_takes_packages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apps.packages.TakesPackageService
的用法示例。
在下文中一共展示了TakesPackageService.enhance_items_with_takes_packages方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: enhance_with_archive_items
# 需要导入模块: from apps.packages import TakesPackageService [as 别名]
# 或者: from apps.packages.TakesPackageService import enhance_items_with_takes_packages [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 = []
archive_lookup = {}
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()
takes_service.enhance_items_with_takes_packages(archive_items)
for item in archive_items:
handle_existing_data(item)
archive_lookup[item[config.ID_FIELD]] = item
for item in items:
archive_item = archive_lookup.get(item.get("item_id"), {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_items_with_takes_packages [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()
takes_service.enhance_items_with_takes_packages(archive_items)
for item in archive_items:
handle_existing_data(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)