本文整理汇总了Python中ckan.plugins.toolkit._属性的典型用法代码示例。如果您正苦于以下问题:Python toolkit._属性的具体用法?Python toolkit._怎么用?Python toolkit._使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类ckan.plugins.toolkit
的用法示例。
在下文中一共展示了toolkit._属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [as 别名]
def convert(data, type_name):
if data is None:
return None
if type_name == 'nested':
return json.loads(data[0])
# array type
if type_name.startswith('_'):
sub_type = type_name[1:]
return [convert(item, sub_type) for item in data]
if type_name == 'tsvector':
return unicode(data, 'utf-8')
if isinstance(data, datetime.datetime):
return data.isoformat()
if isinstance(data, (int, float)):
return data
return unicode(data)
示例2: harvest_source_update
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [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 _ [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_source_show
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [as 别名]
def harvest_source_show(context, data_dict):
'''
Authorization check for getting the details of a harvest source
It forwards the checks to package_show, 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_show', context, data_dict)
return {'success': True}
except pt.NotAuthorized:
return {'success': False,
'msg': pt._('User {0} not authorized to read harvest source {1}')
.format(user, source_id)}
示例5: harvest_job_show
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [as 别名]
def harvest_job_show(context, data_dict):
'''
Authorization check for getting the details of a harvest job
It forwards the checks to harvest_source_update, ie if the user can
update the parent source (eg create new jobs), she can get the details
for the job, including the reports
'''
user = context.get('user')
job = get_job_object(context, data_dict)
try:
pt.check_access('harvest_source_update',
context,
{'id': job.source.id})
return {'success': True}
except pt.NotAuthorized:
return {'success': False,
'msg': pt._('User {0} not authorized to see jobs from source {1}')
.format(user, job.source.id)}
示例6: harvest_job_list
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [as 别名]
def harvest_job_list(context, data_dict):
'''
Authorization check for getting a list of jobs for a source
It forwards the checks to harvest_source_update, ie if the user can
update the parent source (eg create new jobs), she can get the list of
jobs
'''
user = context.get('user')
source_id = data_dict['source_id']
try:
pt.check_access('harvest_source_update',
context,
{'id': source_id})
return {'success': True}
except pt.NotAuthorized:
return {'success': False,
'msg': pt._('User {0} not authorized to list jobs for source {1}')
.format(user, source_id)}
示例7: validate_comment
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [as 别名]
def validate_comment(context, request_data):
comment = request_data.get('comment', '')
# Check if the data request exists
try:
datarequest = tk.get_action(constants.SHOW_DATAREQUEST)(context, {'id': request_data['datarequest_id']})
except Exception:
raise tk.ValidationError({tk._('Data Request'): [tk._('Data Request not found')]})
if not comment or len(comment) <= 0:
raise tk.ValidationError({tk._('Comment'): [tk._('Comments must be a minimum of 1 character long')]})
if len(comment) > constants.COMMENT_MAX_LENGTH:
raise tk.ValidationError({tk._('Comment'): [tk._('Comments must be a maximum of %d characters long') % constants.COMMENT_MAX_LENGTH]})
return datarequest
示例8: convert_package_name_or_id_to_id_for_type
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [as 别名]
def convert_package_name_or_id_to_id_for_type(package_name_or_id,
context, package_type='dataset'):
'''
Return the id for the given package name or id. Only works with packages
of type package_type.
Also validates that a package with the given name or id exists.
:returns: the id of the package with the given name or id
:rtype: string
:raises: ckan.lib.navl.dictization_functions.Invalid if there is no
package with the given name or id
'''
session = context['session']
model = context['model']
result = session.query(model.Package) \
.filter_by(id=package_name_or_id, type=package_type).first()
if not result:
result = session.query(model.Package) \
.filter_by(name=package_name_or_id, type=package_type).first()
if not result:
raise Invalid('%s: %s' % (_('Not found'), _('Dataset')))
return result.id
示例9: new
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [as 别名]
def new(self, data=None, errors=None, error_summary=None):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'auth_user_obj': c.userobj,
'save': 'save' in request.params}
# Check access here, then continue with PackageController.new()
# PackageController.new will also check access for package_create.
# This is okay for now, while only sysadmins can create Showcases, but
# may not work if we allow other users to create Showcases, who don't
# have access to create dataset package types. Same for edit below.
try:
check_access('ckanext_showcase_create', context)
except NotAuthorized:
abort(401, _('Unauthorized to create a package'))
return super(ShowcaseController, self).new(data=data, errors=errors,
error_summary=error_summary)
示例10: read
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [as 别名]
def read(self, id, format='html'):
'''
Detail view for a single showcase, listing its associated datasets.
'''
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'for_view': True,
'auth_user_obj': c.userobj}
data_dict = {'id': id}
# check if showcase exists
try:
c.pkg_dict = get_action('package_show')(context, data_dict)
except NotFound:
abort(404, _('Showcase not found'))
except NotAuthorized:
abort(401, _('Unauthorized to read showcase'))
# get showcase packages
c.showcase_pkgs = get_action('ckanext_showcase_package_list')(
context, {'showcase_id': c.pkg_dict['id']})
package_type = DATASET_TYPE_NAME
return render(self._read_template(package_type),
extra_vars={'dataset_type': package_type})
示例11: get_unique_user_name
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [as 别名]
def get_unique_user_name(base_name):
'''Create a unique, valid, non existent user name from the given base name
:param base_name: Base name
:returns: A valid user name not currently in use based on base_name
'''
base_name = re.sub(u'[^-a-z0-9_]', u'_', base_name.lower())
base_name = base_name[0:100]
if len(base_name) < 2:
base_name = (base_name + u'__')[0:2]
count = 0
user_name = base_name
while (ckan_user_exists(user_name))[u'exists']:
count += 1
user_name = u'{base}{count}'.format(base=base_name[0:100 - len(str(count))],
count=str(count))
return user_name
示例12: user_create
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [as 别名]
def user_create(next_auth, context, data_dict=None):
'''
:param next_auth: the next auth function in the chain
:param context:
:param data_dict: (Default value = None)
'''
if data_dict and u'name' in data_dict:
ldap_user_dict = find_ldap_user(data_dict[u'name'])
if ldap_user_dict:
return {
u'success': False,
u'msg': toolkit._(u'An LDAP user by that name already exists')
}
return next_auth(context, data_dict)
示例13: datapusher_status_description
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [as 别名]
def datapusher_status_description(status):
_ = toolkit._
if status.get('status'):
captions = {
'complete': _('Complete'),
'pending': _('Pending'),
'submitting': _('Submitting'),
'error': _('Error'),
}
return captions.get(status['status'], status['status'].capitalize())
else:
return _('Not Uploaded Yet')
示例14: _is_valid_field_name
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [as 别名]
def _is_valid_field_name(name):
'''
Check that field name is valid:
* can't start or end with whitespace characters
* can't start with underscore
* can't contain double quote (")
* can't be empty
'''
return (name and name == name.strip() and not name.startswith('_')
and not '"' in name)
示例15: _get_fields
# 需要导入模块: from ckan.plugins import toolkit [as 别名]
# 或者: from ckan.plugins.toolkit import _ [as 别名]
def _get_fields(context, data_dict):
fields = []
all_fields = context['connection'].execute(
u'SELECT * FROM "{0}" LIMIT 1'.format(data_dict['resource_id'])
)
for field in all_fields.cursor.description:
if not field[0].startswith('_'):
fields.append({
'id': field[0].decode('utf-8'),
'type': _get_type(context, field[1])
})
return fields