本文整理汇总了Python中ckan.model.User.get方法的典型用法代码示例。如果您正苦于以下问题:Python User.get方法的具体用法?Python User.get怎么用?Python User.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ckan.model.User
的用法示例。
在下文中一共展示了User.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_email
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def send_email(req):
requestee = User.get(req.user_id)
pkg = Package.get(req.pkg_id)
selrole = False
for role in pkg.roles:
if role.role == "admin":
selrole = role
if not selrole:
return
admin = User.get(selrole.user_id)
msg = _("""%s (%s) is requesting editor access to a dataset you have created
%s.
Please click this link if you want to give this user write access:
%s%s""")
controller = 'ckanext.kata.controllers:AccessRequestController'
body = msg % (requestee.name, requestee.email, pkg.title if pkg.title else pkg.name,
config.get('ckan.site_url', ''),
h.url_for(controller=controller,
action="unlock_access",
id=req.id))
email_dict = {}
email_dict["subject"] = _("Access request for dataset %s" % pkg.title if pkg.title else pkg.name)
email_dict["body"] = body
send_notification(admin.as_dict(), email_dict)
示例2: send
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def send(self, pkg_id):
package = Package.get(pkg_id)
url = h.url_for(controller='package',
action="read",
id=package.id)
if c.user:
userid = None
for role in package.roles:
if role.role == "admin":
userid = role.user_id
break
if userid:
owner = User.get(userid)
msg = request.params.get('msg', '')
if msg:
send_contact_email(owner, c.userobj, package,\
msg)
else:
h.flash_error(_("No message"))
return redirect(url)
else:
h.flash_error(_("No owner found"))
return redirect(url)
h.flash_notice(_("Message sent"))
else:
h.flash_error(_("Please login"))
return redirect(url)
示例3: is_owner
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def is_owner(context, data_dict):
'''
This is used in "request edit rights" feature.
Checks if the user is admin or editor of the
package in question
:param context: context
:param data_dict: package data
:type data_dict: dictionary
:rtype: dictionary
'''
pkg = context.get('package', None)
roles = pkg.roles if pkg else Package.get(data_dict['id']).roles
user = context.get('user', False)
if user:
for role in roles:
ruser = User.get(role.user.id)
if user == ruser.name and role.role in ('admin', 'editor'):
return {'success': True}
# Check if the user has editor rights to this dataset through an organization
package = get_package_object(context, data_dict)
if new_authz.has_user_permission_for_group_or_org(package.owner_org, user, 'delete_dataset'):
return {'success': True}
return {'success': False}
示例4: harvest_jobs_run
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def harvest_jobs_run(context,data_dict):
model = context['model']
user = context.get('user')
# Check user is logged in
if not user:
return {'success': False, 'msg': _('Only logged users are authorized to run harvest jobs')}
user_obj = User.get(user)
# Checks for non sysadmin users
if not Authorizer().is_sysadmin(user):
if not user_obj or len(user_obj.get_groups(u'publisher')) == 0:
return {'success': False, 'msg': _('User %s must belong to a publisher to run harvest jobs') % str(user)}
source_id = data_dict.get('source_id',False)
if not source_id:
return {'success': False, 'msg': _('Only sysadmins can run all harvest jobs') % str(user)}
source = HarvestSource.get(source_id)
if not source:
raise NotFound
if not source.publisher_id in [g.id for g in user_obj.get_groups(u'publisher')]:
return {'success': False, 'msg': _('User %s not authorized to run jobs from source %s') % (str(user),source.id)}
return {'success': True}
示例5: is_owner
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def is_owner(context, data_dict):
pkg = context.get('package', None)
roles = pkg.roles if pkg else Package.get(data_dict['id']).roles
user = context.get('user', False)
if user:
for role in roles:
ruser = User.get(role.user_id)
if user == ruser.name and role.role in ('admin', 'editor'):
return {'success': True}
else:
return {'success': False}
return {'success': False}
示例6: authenticate
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def authenticate(self, environ, identity):
if 'shibboleth_auth' in identity:
userid = identity['shibboleth_auth']
user = User.get(userid)
if user is None or not user.is_active():
log.info("ShibbolethAuthenticator: user not found: %s", userid)
return None
else:
log.info("ShibbolethAuthenticator: user found %s", userid)
return user.name
return None
示例7: send_edit_access_request_email
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def send_edit_access_request_email(req):
"""
Send edit access request email.
:param user_id: user who requests access
:param pkg_id: dataset's id
"""
requester = User.get(req.user_id)
pkg = Package.get(req.pkg_id)
selrole = False
for role in pkg.roles:
if role.role == "admin":
selrole = role
if not selrole:
return
admin = User.get(selrole.user_id)
admin_dict = admin.as_dict()
admin_dict['name'] = admin.fullname if admin.fullname else admin.name
msg = u'{a} ({b}) is requesting editing rights to the metadata in dataset\n\n{c}\n\n\
for which you are currently an administrator. Please click this \
link if you want to allow this user to edit the metadata of the dataset:\n\
{d}\n\n{a} ({b}) pyytää muokkausoikeuksia tietoaineiston\n\n{c}\n\n\
metatietoihin, joiden ylläpitäjä olet. Klikkaa linkkiä, jos haluat tämän käyttäjän \
saavan muokkausoikeudet aineiston metatietoihin:\n\
{d}\n'
controller = 'ckanext.kata.controllers:EditAccessRequestController'
requester_name = requester.fullname if requester.fullname else requester.name
accessurl = config.get('ckan.site_url', '') + h.url_for(controller=controller, action="unlock_access", id=req.id)
body = msg.format(a=requester_name, b=requester.email, c=pkg.title if pkg.title else pkg.name, d=accessurl)
email_dict = {}
email_dict["subject"] = u"Access request for dataset / pyyntö koskien tietoaineistoa %s" % pkg.title if pkg.title else pkg.name
email_dict["body"] = body
send_notification(admin_dict, email_dict)
示例8: _get_sources_for_user
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def _get_sources_for_user(context, data_dict):
model = context['model']
session = context['session']
user = context.get('user', '')
only_active = data_dict.get('only_active', False)
only_to_run = data_dict.get('only_to_run', False)
query = session.query(HarvestSource) \
.order_by(HarvestSource.created.desc())
if only_active:
query = query.filter(HarvestSource.active) \
if only_to_run:
query = query.filter(HarvestSource.frequency != 'MANUAL')
query = query.filter(or_(HarvestSource.next_run <=
datetime.datetime.utcnow(),
HarvestSource.next_run is None))
user_obj = User.get(user)
# Sysadmins will get all sources
if user_obj and not user_obj.sysadmin:
# This only applies to a non sysadmin user when using the
# publisher auth profile. When using the default profile,
# normal users will never arrive at this point, but even if they
# do, they will get an empty list.
publisher_filters = []
publishers_for_the_user = user_obj.get_groups(u'publisher')
for publisher_id in [g.id for g in publishers_for_the_user]:
publisher_filters.append(
HarvestSource.publisher_id == publisher_id)
if len(publisher_filters):
query = query.filter(or_(*publisher_filters))
else:
# This user does not belong to a publisher yet, no sources for
# him/her
return []
log.debug('User %s with publishers %r has Harvest Sources: %r',
user, publishers_for_the_user,
[(hs.id, hs.url) for hs in query])
sources = query.all()
return sources
示例9: harvesters_info_show
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def harvesters_info_show(context,data_dict):
model = context['model']
user = context.get('user','')
# Non-logged users can not create sources
if not user:
return {'success': False, 'msg': _('Non-logged in users can not see the harvesters info')}
# Sysadmins and the rest of logged users can see the harvesters info,
# as long as they belong to a publisher
user_obj = User.get(user)
if not user_obj or not authz.is_sysadmin(user) and len(user_obj.get_groups(u'publisher')) == 0:
return {'success': False, 'msg': _('User %s must belong to a publisher to see the harvesters info') % str(user)}
else:
return {'success': True}
示例10: harvest_source_create
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def harvest_source_create(context, data_dict):
model = context["model"]
user = context.get("user", "")
# Non-logged users can not create sources
if not user:
return {"success": False, "msg": _("Non-logged in users are not authorized to create harvest sources")}
# Sysadmins and the rest of logged users can create sources,
# as long as they belong to a publisher
user_obj = User.get(user)
if not user_obj or not authz.is_sysadmin(user) and len(user_obj.get_groups(u"publisher")) == 0:
return {"success": False, "msg": _("User %s must belong to a publisher to create harvest sources") % str(user)}
else:
return {"success": True}
示例11: harvest_source_create
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def harvest_source_create(context,data_dict):
model = context['model']
user = context.get('user','')
# Non-logged users can not create sources
if not user:
return {'success': False, 'msg': _('Non-logged in users are not authorized to create harvest sources')}
# Sysadmins and the rest of logged users can create sources,
# as long as they belong to a publisher
user_obj = User.get(user)
if not user_obj or not Authorizer().is_sysadmin(user) and len(user_obj.get_groups(u'publisher')) == 0:
return {'success': False, 'msg': _('User %s must belong to a publisher to create harvest sources') % str(user)}
else:
return {'success': True}
示例12: user_autocomplete
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def user_autocomplete(context, data_dict):
'''
Override to explicitly allow logged in users to have
user autocompletion even if user_list is disallowed.
:param context:
:param data_dict:
:return:
'''
user_name = context.get('user')
user_obj = User.get(user_name) if user_name else None
if user_obj:
return {'success': True}
else:
return {'success': False}
示例13: unlock_access
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def unlock_access(self, id):
q = model.Session.query(KataAccessRequest)
q = q.filter_by(id=id)
req = q.first()
if req:
user = User.get(req.user_id)
pkg = Package.get(req.pkg_id)
add_user_to_role(user, 'editor', pkg)
url = h.url_for(controller='package', action='read', id=req.pkg_id)
h.flash_success(_("%s now has editor rights to package %s" % (user.name, pkg.name)))
req.delete()
meta.Session.commit()
redirect(url)
else:
h.flash_error(_("No such request found!"))
redirect('/')
示例14: after_search
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def after_search(self, search_params, search_results):
context = {'model': ckan.model,
'session': ckan.model.Session,
'user': pylons.c.user}
#set permission level: read (default is edit)
data_dict = {'user': pylons.c.user, 'permission': 'read'}
#get list of organisations that the user is a member of
orgs = ckan.logic.get_action('organization_list_for_user')(context, data_dict)
#user doesn't belong to an organisation
if not orgs:
print ('User is not a member of any organisations!')
c.maintainers = []
return search_params
#get a distinct list of members who belong to the organisations
members = []
for org in orgs:
params = {'id': org['id'], 'object_type': 'user'}
member_list = ckan.logic.get_action('member_list')(context, params)
for m in member_list:
members.append(m)
memberset = set(members)
#need the user name to match with the maintainer field
current_user_name = None
member_names = []
for member in memberset:
user = User.get(member[0]) #user id
member_names.append(user.name)
#get all maintainers
maintainers = [p[0] for p in meta.Session.query(distinct(Package.maintainer)) if p[0]]
maintset = set(maintainers)
#filter maintainers by user-related organisation members
results = maintset.intersection(member_names)
c.maintainers = results
return search_params
示例15: harvest_job_show
# 需要导入模块: from ckan.model import User [as 别名]
# 或者: from ckan.model.User import get [as 别名]
def harvest_job_show(context,data_dict):
model = context['model']
user = context.get('user')
job = get_job_object(context,data_dict)
if not user:
return {'success': False, 'msg': _('Non-logged in users are not authorized to see harvest jobs')}
if Authorizer().is_sysadmin(user):
return {'success': True}
user_obj = User.get(user)
if not user_obj or not job.source.publisher_id in [g.id for g in user_obj.get_groups(u'publisher')]:
return {'success': False, 'msg': _('User %s not authorized to read harvest job %s') % (str(user),job.id)}
else:
return {'success': True}