本文整理汇总了Python中kallithea.model.user.UserModel.update方法的典型用法代码示例。如果您正苦于以下问题:Python UserModel.update方法的具体用法?Python UserModel.update怎么用?Python UserModel.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kallithea.model.user.UserModel
的用法示例。
在下文中一共展示了UserModel.update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from kallithea.model.user import UserModel [as 别名]
# 或者: from kallithea.model.user.UserModel import update [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: update
# 需要导入模块: from kallithea.model.user import UserModel [as 别名]
# 或者: from kallithea.model.user.UserModel import update [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))