本文整理汇总了Python中ckanext.archiver.model.Archival.get_for_package方法的典型用法代码示例。如果您正苦于以下问题:Python Archival.get_for_package方法的具体用法?Python Archival.get_for_package怎么用?Python Archival.get_for_package使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ckanext.archiver.model.Archival
的用法示例。
在下文中一共展示了Archival.get_for_package方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: archiver_dataset_show
# 需要导入模块: from ckanext.archiver.model import Archival [as 别名]
# 或者: from ckanext.archiver.model.Archival import get_for_package [as 别名]
def archiver_dataset_show(context, data_dict=None):
'''Return a details of the archival of a dataset, aggregated across its
resources.
:param id: the name or id of the dataset
:type id: string
:rtype: dictionary
'''
id_ = _get_or_bust(data_dict, 'id')
dataset = model.Package.get(id_)
if not dataset:
raise ObjectNotFound
archivals = Archival.get_for_package(dataset.id)
archival_dict = aggregate_archivals_for_a_dataset(archivals)
p.toolkit.check_access('archiver_dataset_show', context, data_dict)
return archival_dict
示例2: qa_package_broken_show
# 需要导入模块: from ckanext.archiver.model import Archival [as 别名]
# 或者: from ckanext.archiver.model.Archival import get_for_package [as 别名]
def qa_package_broken_show(context, data_dict):
'''
Returns the Archival is_broken information for a package, aggregating
across its resources.
is_broken - True (all), 'some', False or None (not sure)
'''
model = context['model']
session = context['session']
#user = context.get('user')
#p.toolkit.check_access('qa_package_broken_show', context, data_dict)
pkg_id = p.toolkit.get_or_bust(data_dict, 'id')
pkg = session.query(model.Package).get(pkg_id)
if not pkg:
raise p.toolkit.ObjectNotFound
if pkg.resources:
# Are any broken?
any_resources_broken = False
any_resources_ok = False
for archival in Archival.get_for_package(pkg_id):
if archival.is_broken is True:
any_resources_broken = True
elif archival.is_broken is False:
any_resources_ok = True
if any_resources_broken and any_resources_ok:
is_broken = 'some' # i.e. some broken
elif any_resources_broken:
is_broken = True # all broken
elif any_resources_ok:
is_broken = False # all ok
else:
is_broken = None # not sure / not recorded
else:
is_broken = False
return {'name': pkg.name,
'title': pkg.title,
'id': pkg.id,
'archival_is_broken': is_broken,
}
示例3: after_show
# 需要导入模块: from ckanext.archiver.model import Archival [as 别名]
# 或者: from ckanext.archiver.model.Archival import get_for_package [as 别名]
def after_show(self, context, pkg_dict):
# Insert the archival info into the package_dict so that it is
# available on the API.
# When you edit the dataset, these values will not show in the form,
# it they will be saved in the resources (not the dataset). I can't see
# and easy way to stop this, but I think it is harmless. It will get
# overwritten here when output again.
archivals = Archival.get_for_package(pkg_dict['id'])
if not archivals:
return
# dataset
dataset_archival = aggregate_archivals_for_a_dataset(archivals)
pkg_dict['archiver'] = dataset_archival
# resources
archivals_by_res_id = dict((a.resource_id, a) for a in archivals)
for res in pkg_dict['resources']:
archival = archivals_by_res_id.get(res['id'])
if archival:
archival_dict = archival.as_dict()
del archival_dict['id']
del archival_dict['package_id']
del archival_dict['resource_id']
res['archiver'] = archival_dict