本文整理汇总了Python中ckan.logic.get_action方法的典型用法代码示例。如果您正苦于以下问题:Python logic.get_action方法的具体用法?Python logic.get_action怎么用?Python logic.get_action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ckan.logic
的用法示例。
在下文中一共展示了logic.get_action方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: email_requestors
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def email_requestors(dataset_id):
requests = Session.query(DoiRequest).filter_by(package_id=dataset_id)
subject = 'DataPortal DOI Request approved'
data = {
'dataset_url': toolkit.url_for(
controller='package',
action='read',
id=dataset_id,
qualified=True)
}
body = base.render(
'package/doi_request_completed.text',
extra_vars=data)
for request in requests:
user = toolkit.get_action('user_show')(None, {'id': request.user_id})
if user['email']:
mail_recipient(user['display_name'], user['email'], subject, body)
示例2: dataset_doi_admin
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def dataset_doi_admin(self, id):
dataset_url = toolkit.url_for(
controller='package',
action='read',
id=id,
qualified=True
)
if not c.userobj.sysadmin:
return toolkit.redirect_to(dataset_url)
dataset = toolkit.get_action('package_show')(None, {'id': id})
self.fail_if_private(dataset, dataset_url)
if request.method == 'POST':
return self.dataset_doi_admin_process(dataset_url, dataset)
else:
return self.dataset_doi_admin_form(dataset_url, dataset)
示例3: vocabulary_autocomplete
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def vocabulary_autocomplete(self):
q = request.str_params.get('incomplete', '')
q = unicode(urllib.unquote(q), 'utf-8')
vocab = request.params.get('vocabulary_id', None)
vocab = str(vocab)
log.debug('Looking for Vocab %r', vocab)
limit = request.params.get('limit', 10)
tag_names = []
if q:
context = {'model': model, 'session': model.Session, 'user': c.user, 'auth_user_obj': c.userobj}
data_dict = {'q': q, 'limit': limit, 'vocabulary_id': vocab}
tag_names = get_action('tag_autocomplete')(context, data_dict)
resultSet = {
'ResultSet': {
'Result': [{'Name': tag} for tag in tag_names]
}
}
return super(DCATAPITApiController, self)._finish_ok(resultSet)
示例4: _create_source_and_job
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def _create_source_and_job(self, source_fixture):
context ={'model':model,
'session':Session,
'user':u'harvest'}
if config.get('ckan.harvest.auth.profile') == u'publisher' \
and not 'publisher_id' in source_fixture:
source_fixture['publisher_id'] = self.publisher.id
source_dict=get_action('harvest_source_create')(context,source_fixture)
source = HarvestSource.get(source_dict['id'])
assert source
job = self._create_job(source.id)
return source, job
示例5: clear_views
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def clear_views(self, view_plugin_types=[]):
log = logging.getLogger(__name__)
if not self.options.assume_yes:
if view_plugin_types:
msg = 'Are you sure you want to delete all resource views ' + \
'of type {0}?'.format(', '.join(view_plugin_types))
else:
msg = 'Are you sure you want to delete all resource views?'
result = query_yes_no(msg, default='no')
if result == 'no':
log.info('Command aborted by user')
sys.exit(1)
context = {'user': self.site_user['name']}
logic.get_action('resource_view_clear')(
context, {'view_types': view_plugin_types})
log.info('Done')
示例6: follow_count
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def follow_count(obj_type, obj_id):
'''Return the number of followers of an object.
:param obj_type: the type of the object, e.g. 'user' or 'dataset'
:type obj_type: string
:param obj_id: the id of the object
:type obj_id: string
:returns: the number of followers of the object
:rtype: int
'''
obj_type = obj_type.lower()
assert obj_type in _follow_objects
action = '%s_follower_count' % obj_type
context = {'model': model, 'session': model.Session, 'user': c.user}
return logic.get_action(action)(context, {'id': obj_id})
示例7: notify
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def notify(self, entity, operation):
if not isinstance(entity, model.Package):
return
if operation != model.domain_object.DomainObjectOperation.deleted:
dispatch_by_operation(
entity.__class__.__name__,
logic.get_action('package_show')(
{'model': model, 'ignore_auth': True, 'validate': False,
'use_cache': False},
{'id': entity.id}),
operation
)
elif operation == model.domain_object.DomainObjectOperation.deleted:
dispatch_by_operation(entity.__class__.__name__,
{'id': entity.id}, operation)
else:
log.warn("Discarded Sync. indexing for: %s" % entity)
示例8: dashboard_new_activities_count
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def dashboard_new_activities_count(context, data_dict):
'''Return the number of new activities in the user's dashboard.
Return the number of new activities in the authorized user's dashboard
activity stream.
Activities from the user herself are not counted by this function even
though they appear in the dashboard (users don't want to be notified about
things they did themselves).
:rtype: int
'''
_check_access('dashboard_new_activities_count', context, data_dict)
activities = logic.get_action('dashboard_activity_list')(
context, data_dict)
return len([activity for activity in activities if activity['is_new']])
示例9: help_show
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def help_show(context, data_dict):
'''Return the help string for a particular API action.
:param name: Action function name (eg `user_create`, `package_search`)
:type name: string
:returns: The help string for the action function, or None if the function
does not have a docstring.
:rtype: string
:raises: :class:`ckan.logic.NotFound`: if the action function doesn't exist
'''
function_name = logic.get_or_bust(data_dict, 'name')
_check_access('help_show', context, data_dict)
try:
function = logic.get_action(function_name)
except KeyError:
raise NotFound('Action function not found')
return function.__doc__
示例10: test_mapper_plugin_fired_on_delete
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def test_mapper_plugin_fired_on_delete(self):
with plugins.use_plugin('mapper_plugin') as mapper_plugin:
CreateTestData.create_arbitrary([{'name': u'testpkg'}])
mapper_plugin.calls = []
# remove this data
user = factories.User()
context = {'user': user['name']}
logic.get_action('package_delete')(context, {'id': 'testpkg'})
# state=deleted doesn't trigger before_delete()
assert_equal(mapper_plugin.calls, [])
from ckan import model
# purging the package does trigger before_delete()
model.Package.get('testpkg').purge()
model.Session.commit()
model.Session.remove()
assert_equal(mapper_plugin.calls,
[('before_delete', 'testpkg'),
('after_delete', 'testpkg')])
示例11: test_get_pkg_dict_extra
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def test_get_pkg_dict_extra(self):
from ckan.lib.create_test_data import CreateTestData
from ckan import model
from ckan.logic import get_action
CreateTestData.create()
pkg_dict = get_action('package_show')({'model': model, 'user': u'tester'}, {'id': 'annakarenina'})
assert_equal(h.get_pkg_dict_extra(pkg_dict, 'genre'), 'romantic novel')
assert_equal(h.get_pkg_dict_extra(pkg_dict, 'extra_not_found'), None)
assert_equal(h.get_pkg_dict_extra(pkg_dict, 'extra_not_found', 'default_value'), 'default_value')
model.repo.rebuild_db()
示例12: setup_class
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def setup_class(cls):
admin_api = get_action('get_site_user')(
{'model': model, 'ignore_auth': True}, {})['apikey']
## This is a mutable dict on the class level so tests can
## add apikeys as they go along
cls.apikeys = {'sysadmin': str(admin_api), 'random_key': 'moo'}
cls._original_config = config.copy()
config['ckan.auth.anon_create_dataset'] = False
config['ckan.auth.create_dataset_if_not_in_organization'] = False
config['ckan.auth.user_create_groups'] = False
config['ckan.auth.user_create_organizations'] = False
config['ckan.auth.user_delete_groups'] = False
config['ckan.auth.user_delete_organizations'] = False
config['ckan.auth.create_unowned_dataset'] = False
config['ckan.auth.create_user_via_api'] = False
config['ckan.auth.create_user_via_web'] = True
config['ckan.auth.roles_that_cascade_to_sub_groups'] = 'admin'
wsgiapp = ckan.config.middleware.make_app(
config['global_conf'], **config)
cls.app = paste.fixture.TestApp(wsgiapp)
示例13: test_27_get_site_user_not_authorized
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def test_27_get_site_user_not_authorized(self):
assert_raises(NotAuthorized,
get_action('get_site_user'),
{'model': model}, {})
user = model.User.get('test.ckan.net')
assert not user
site_id = config.get('ckan.site_id')
user = get_action('get_site_user')({'model': model, 'ignore_auth': True}, {})
assert user['name'] == site_id
user = model.User.get(site_id)
assert user
user=get_action('get_site_user')({'model': model, 'ignore_auth': True}, {})
assert user['name'] == site_id
user = model.Session.query(model.User).filter_by(name=site_id).one()
assert user
示例14: test_user_create_simple
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def test_user_create_simple(self):
'''Simple creation of a new user by a non-sysadmin user.'''
context = {
'model': model,
'session': model.Session,
'user': 'tester'
}
data_dict = {
'name': 'a-new-user',
'email': '[email protected]',
'password': 'supersecret',
}
user_dict = logic.get_action('user_create')(context, data_dict)
assert_equal(user_dict['name'], 'a-new-user')
assert 'email' in user_dict
assert 'apikey' in user_dict
assert 'password' not in user_dict
示例15: _package_search
# 需要导入模块: from ckan import logic [as 别名]
# 或者: from ckan.logic import get_action [as 别名]
def _package_search(data_dict):
"""
Helper method that wraps the package_search action.
* unless overridden, sorts results by metadata_modified date
* unless overridden, sets a default item limit
"""
context = {'model': model, 'session': model.Session,
'user': c.user, 'auth_user_obj': c.userobj}
if 'sort' not in data_dict or not data_dict['sort']:
data_dict['sort'] = 'metadata_modified desc'
if 'rows' not in data_dict or not data_dict['rows']:
data_dict['rows'] = ITEMS_LIMIT
# package_search action modifies the data_dict, so keep our copy intact.
query = logic.get_action('package_search')(context, data_dict.copy())
return query['count'], query['results']