本文整理汇总了Python中kallithea.model.user.UserModel.get方法的典型用法代码示例。如果您正苦于以下问题:Python UserModel.get方法的具体用法?Python UserModel.get怎么用?Python UserModel.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kallithea.model.user.UserModel
的用法示例。
在下文中一共展示了UserModel.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from kallithea.model.user import UserModel [as 别名]
# 或者: from kallithea.model.user.UserModel import get [as 别名]
def update(self, id):
"""PUT /users/id: Update an existing item"""
# Forms posted to this method should contain a hidden field:
# <input type="hidden" name="_method" value="PUT" />
# Or using helpers:
# h.form(url('update_user', id=ID),
# method='put')
# url('user', id=ID)
c.active = 'profile'
user_model = UserModel()
c.user = user_model.get(id)
c.extern_type = c.user.extern_type
c.extern_name = c.user.extern_name
c.perm_user = AuthUser(user_id=id, ip_addr=self.ip_addr)
_form = UserForm(edit=True, old_data={'user_id': id,
'email': c.user.email})()
form_result = {}
try:
form_result = _form.to_python(dict(request.POST))
skip_attrs = ['extern_type', 'extern_name']
#TODO: plugin should define if username can be updated
if c.extern_type != kallithea.EXTERN_TYPE_INTERNAL:
# forbid updating username for external accounts
skip_attrs.append('username')
user_model.update(id, form_result, skip_attrs=skip_attrs)
usr = form_result['username']
action_logger(self.authuser, 'admin_updated_user:%s' % usr,
None, self.ip_addr, self.sa)
h.flash(_('User updated successfully'), category='success')
Session().commit()
except formencode.Invalid, errors:
defaults = errors.value
e = errors.error_dict or {}
defaults.update({
'create_repo_perm': user_model.has_perm(id,
'hg.create.repository'),
'fork_repo_perm': user_model.has_perm(id, 'hg.fork.repository'),
'_method': 'put'
})
return htmlfill.render(
render('admin/users/user_edit.html'),
defaults=defaults,
errors=e,
prefix_error=False,
encoding="UTF-8",
force_defaults=False)
示例2: __init__
# 需要导入模块: from kallithea.model.user import UserModel [as 别名]
# 或者: from kallithea.model.user.UserModel import get [as 别名]
def __init__(self, user_id=None, dbuser=None, authenticating_api_key=None,
is_external_auth=False):
self.is_authenticated = False
self.is_external_auth = is_external_auth
self.authenticating_api_key = authenticating_api_key
user_model = UserModel()
self._default_user = User.get_default_user(cache=True)
# These attributes will be overridden by fill_data, below, unless the
# requested user cannot be found and the default anonymous user is
# not enabled.
self.user_id = None
self.username = None
self.api_key = None
self.name = ''
self.lastname = ''
self.email = ''
self.admin = False
self.inherit_default_permissions = False
# Look up database user, if necessary.
if user_id is not None:
log.debug('Auth User lookup by USER ID %s', user_id)
dbuser = user_model.get(user_id)
else:
# Note: dbuser is allowed to be None.
log.debug('Auth User lookup by database user %s', dbuser)
is_user_loaded = self._fill_data(dbuser)
# If user cannot be found, try falling back to anonymous.
if not is_user_loaded:
is_user_loaded = self._fill_data(self._default_user)
self.is_default_user = (self.user_id == self._default_user.user_id)
self.is_anonymous = not is_user_loaded or self.is_default_user
if not self.username:
self.username = 'None'
log.debug('Auth User is now %s', self)
示例3: update
# 需要导入模块: from kallithea.model.user import UserModel [as 别名]
# 或者: from kallithea.model.user.UserModel import get [as 别名]
def update(self, id):
user_model = UserModel()
user = user_model.get(id)
_form = UserForm(edit=True, old_data={'user_id': id,
'email': user.email})()
form_result = {}
try:
form_result = _form.to_python(dict(request.POST))
skip_attrs = ['extern_type', 'extern_name',
] + auth_modules.get_managed_fields(user)
user_model.update(id, form_result, skip_attrs=skip_attrs)
usr = form_result['username']
action_logger(request.authuser, 'admin_updated_user:%s' % usr,
None, request.ip_addr)
h.flash(_('User updated successfully'), category='success')
Session().commit()
except formencode.Invalid as errors:
defaults = errors.value
e = errors.error_dict or {}
defaults.update({
'create_repo_perm': user_model.has_perm(id,
'hg.create.repository'),
'fork_repo_perm': user_model.has_perm(id, 'hg.fork.repository'),
})
return htmlfill.render(
self._render_edit_profile(user),
defaults=defaults,
errors=e,
prefix_error=False,
encoding="UTF-8",
force_defaults=False)
except Exception:
log.error(traceback.format_exc())
h.flash(_('Error occurred during update of user %s') \
% form_result.get('username'), category='error')
raise HTTPFound(location=url('edit_user', id=id))