本文整理汇总了Python中ckan.plugins.toolkit.ObjectNotFound方法的典型用法代码示例。如果您正苦于以下问题:Python toolkit.ObjectNotFound方法的具体用法?Python toolkit.ObjectNotFound怎么用?Python toolkit.ObjectNotFound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ckan.plugins.toolkit
的用法示例。
在下文中一共展示了toolkit.ObjectNotFound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_country_codes
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def create_country_codes():
'''Create country_codes vocab and tags, if they don't exist already.
Note that you could also create the vocab and tags using CKAN's API,
and once they are created you can edit them (e.g. to add and remove
possible dataset country code values) using the API.
'''
user = tk.get_action('get_site_user')({'ignore_auth': True}, {})
context = {'user': user['name']}
try:
data = {'id': 'country_codes'}
tk.get_action('vocabulary_show')(context, data)
logging.info("Example genre vocabulary already exists, skipping.")
except tk.ObjectNotFound:
logging.info("Creating vocab 'country_codes'")
data = {'name': 'country_codes'}
vocab = tk.get_action('vocabulary_create')(context, data)
for tag in (u'uk', u'ie', u'de', u'fr', u'es'):
logging.info(
"Adding tag {0} to vocab 'country_codes'".format(tag))
data = {'name': tag, 'vocabulary_id': vocab['id']}
tk.get_action('tag_create')(context, data)
示例2: harvest_source_update
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def harvest_source_update(context, data_dict):
'''
Authorization check for harvest source update
It forwards the checks to package_update, which will check for
organization membership, whether if sysadmin, etc according to the
instance configuration.
'''
model = context.get('model')
user = context.get('user')
source_id = data_dict['id']
pkg = model.Package.get(source_id)
if not pkg:
raise pt.ObjectNotFound(pt._('Harvest source not found'))
context['package'] = pkg
try:
pt.check_access('package_update', context, data_dict)
return {'success': True}
except pt.NotAuthorized:
return {'success': False,
'msg': pt._('User {0} not authorized to update harvest source {1}').format(user, source_id)}
示例3: harvest_source_delete
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def harvest_source_delete(context, data_dict):
'''
Authorization check for harvest source deletion
It forwards the checks to package_delete, which will check for
organization membership, whether if sysadmin, etc according to the
instance configuration.
'''
model = context.get('model')
user = context.get('user')
source_id = data_dict['id']
pkg = model.Package.get(source_id)
if not pkg:
raise pt.ObjectNotFound(pt._('Harvest source not found'))
context['package'] = pkg
try:
pt.check_access('package_delete', context, data_dict)
return {'success': True}
except pt.NotAuthorized:
return {'success': False,
'msg': pt._('User {0} not authorized to delete harvest source {1}').format(user, source_id)}
示例4: harvest_job_create
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def harvest_job_create(context, data_dict):
'''
Authorization check for harvest job creation
It forwards the checks to package_update, ie the user can only create
new jobs if she is allowed to edit the harvest source dataset.
'''
model = context['model']
source_id = data_dict['source_id']
pkg = model.Package.get(source_id)
if not pkg:
raise pt.ObjectNotFound(pt._('Harvest source not found'))
context['package'] = pkg
try:
pt.check_access('package_update', context, data_dict)
return {'success': True}
except pt.NotAuthorized:
return {'success': False,
'msg': pt._('User not authorized to create a job for source {0}').format(source_id)}
示例5: test_remote_groups_only_local
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def test_remote_groups_only_local(self):
# Create an existing group
Group(id='group1-id', name='group1')
config = {'remote_groups': 'only_local'}
results_by_guid = run_harvest(
url='http://localhost:%s' % mock_ckan.PORT,
harvester=CKANHarvester(),
config=json.dumps(config))
assert 'dataset1-id' in results_by_guid
# Check that the dataset was added to the existing local group
dataset = call_action('package_show', {}, id=mock_ckan.DATASETS[0]['id'])
assert_equal(dataset['groups'][0]['id'], mock_ckan.DATASETS[0]['groups'][0]['id'])
# Check that the other remote group was not created locally
assert_raises(toolkit.ObjectNotFound, call_action, 'group_show', {},
id='remote-group')
示例6: _create
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def _create(cls, target_class, *args, **kwargs):
if args:
assert False, "Positional args aren't supported, use keyword args."
context = {'user': _get_action_user_name(kwargs)}
# If there is an existing source for this URL, and we can't create
# another source with that URL, just return the original one.
try:
source_dict = toolkit.get_action('harvest_source_show')(
context, dict(url=kwargs['url']))
except toolkit.ObjectNotFound:
source_dict = toolkit.get_action('harvest_source_create')(
context, kwargs)
if cls._return_type == 'dict':
return source_dict
else:
return cls.FACTORY_FOR.get(source_dict['id'])
示例7: get_vocabulary_items
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def get_vocabulary_items(vocabulary_name, keys=None):
try:
tag_list = toolkit.get_action('tag_list')
items = tag_list(data_dict={'vocabulary_id': vocabulary_name})
tag_list = []
for item in items:
if keys:
for key in keys:
if key == item:
localized_tag_name = interfaces.get_localized_tag_name(item)
tag_list.append(localized_tag_name)
else:
localized_tag_name = interfaces.get_localized_tag_name(item)
tag_list.append({'text': localized_tag_name, 'value': item})
return tag_list
except toolkit.ObjectNotFound:
return []
示例8: showcase_delete
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def showcase_delete(context, data_dict):
'''Delete a showcase. Showcase delete cascades to
ShowcasePackageAssociation objects.
:param id: the id or name of the showcase to delete
:type id: string
'''
model = context['model']
id = toolkit.get_or_bust(data_dict, 'id')
entity = model.Package.get(id)
if entity is None:
raise toolkit.ObjectNotFound
toolkit.check_access('ckanext_showcase_delete', context, data_dict)
entity.purge()
model.repo.commit()
示例9: test_association_delete_attempt_with_non_existent_association
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def test_association_delete_attempt_with_non_existent_association(self):
'''
Attempting to delete a non-existent association (package ids exist,
but aren't associated with each other), will cause a NotFound error.
'''
sysadmin = factories.User(sysadmin=True)
package_id = factories.Dataset()['id']
showcase_id = factories.Dataset(type='showcase')['id']
# No existing associations
nosetools.assert_equal(model.Session.query(ShowcasePackageAssociation).count(), 0)
context = {'user': sysadmin['name']}
nosetools.assert_raises(toolkit.ObjectNotFound, helpers.call_action,
'ckanext_showcase_package_association_delete',
context=context, package_id=package_id,
showcase_id=showcase_id)
示例10: setup_org
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def setup_org(self):
# get the organisation all users will be added to
organization_id = toolkit.config[u'ckanext.ldap.organization.id']
# set up context
user = toolkit.get_action(u'get_site_user')({
u'ignore_auth': True
}, {})
context = {
u'user': user[u'name']
}
try:
toolkit.get_action(u'organization_show')(context, {
u'id': organization_id
})
except toolkit.ObjectNotFound:
# see the following commit to understand why this line is here
# http://github.com/ckan/ckanext-harvest/commit/f315f41c86cbde4a49ef869b6993598f8cb11e2d
context.pop(u'__auth_audit', None)
toolkit.get_action(u'organization_create')(context, {
u'id': organization_id,
u'name': organization_id
})
示例11: group_create
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def group_create(context, data_dict=None):
# Get the user name of the logged-in user.
user_name = context['user']
# Get a list of the members of the 'curators' group.
try:
members = toolkit.get_action('member_list')(
data_dict={'id': 'curators', 'object_type': 'user'})
except toolkit.ObjectNotFound:
# The curators group doesn't exist.
return {'success': False,
'msg': "The curators groups doesn't exist, so only sysadmins "
"are authorized to create groups."}
# 'members' is a list of (user_id, object_type, capacity) tuples, we're
# only interested in the user_ids.
member_ids = [member_tuple[0] for member_tuple in members]
# We have the logged-in user's user name, get their user id.
convert_user_name_or_id_to_id = toolkit.get_converter(
'convert_user_name_or_id_to_id')
try:
user_id = convert_user_name_or_id_to_id(user_name, context)
except toolkit.Invalid:
# The user doesn't exist (e.g. they're not logged-in).
return {'success': False,
'msg': 'You must be logged-in as a member of the curators '
'group to create new groups.'}
# Finally, we can test whether the user is a member of the curators group.
if user_id in member_ids:
return {'success': True}
else:
return {'success': False,
'msg': 'Only curators are allowed to create groups'}
示例12: datapusher_status
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def datapusher_status(resource_id):
try:
return toolkit.get_action('datapusher_status')(
{}, {'resource_id': resource_id})
except toolkit.ObjectNotFound:
return {
'status': 'unknown'
}
示例13: create_country_codes
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def create_country_codes():
user = tk.get_action('get_site_user')({'ignore_auth': True}, {})
context = {'user': user['name']}
try:
data = {'id': 'country_codes'}
tk.get_action('vocabulary_show')(context, data)
except tk.ObjectNotFound:
data = {'name': 'country_codes'}
vocab = tk.get_action('vocabulary_create')(context, data)
for tag in (u'uk', u'ie', u'de', u'fr', u'es'):
data = {'name': tag, 'vocabulary_id': vocab['id']}
tk.get_action('tag_create')(context, data)
示例14: country_codes
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def country_codes():
create_country_codes()
try:
tag_list = tk.get_action('tag_list')
country_codes = tag_list(data_dict={'vocabulary_id': 'country_codes'})
return country_codes
except tk.ObjectNotFound:
return None
示例15: user_is_sysadmin
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import ObjectNotFound [as 别名]
def user_is_sysadmin(context):
'''
Checks if the user defined in the context is a sysadmin
rtype: boolean
'''
model = context['model']
user = context['user']
user_obj = model.User.get(user)
if not user_obj:
raise pt.Objectpt.ObjectNotFound('User {0} not found').format(user)
return user_obj.sysadmin