本文整理匯總了Python中kallithea.model.user.UserModel.create方法的典型用法代碼示例。如果您正苦於以下問題:Python UserModel.create方法的具體用法?Python UserModel.create怎麽用?Python UserModel.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類kallithea.model.user.UserModel
的用法示例。
在下文中一共展示了UserModel.create方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create
# 需要導入模塊: from kallithea.model.user import UserModel [as 別名]
# 或者: from kallithea.model.user.UserModel import create [as 別名]
def create(self):
c.default_extern_type = User.DEFAULT_AUTH_TYPE
c.default_extern_name = ''
user_model = UserModel()
user_form = UserForm()()
try:
form_result = user_form.to_python(dict(request.POST))
user = user_model.create(form_result)
action_logger(request.authuser, 'admin_created_user:%s' % user.username,
None, request.ip_addr)
h.flash(_('Created user %s') % user.username,
category='success')
Session().commit()
except formencode.Invalid as errors:
return htmlfill.render(
render('admin/users/user_add.html'),
defaults=errors.value,
errors=errors.error_dict or {},
prefix_error=False,
encoding="UTF-8",
force_defaults=False)
except UserCreationError as e:
h.flash(e, 'error')
except Exception:
log.error(traceback.format_exc())
h.flash(_('Error occurred during creation of user %s') \
% request.POST.get('username'), category='error')
raise HTTPFound(location=url('edit_user', id=user.user_id))
示例2: create
# 需要導入模塊: from kallithea.model.user import UserModel [as 別名]
# 或者: from kallithea.model.user.UserModel import create [as 別名]
def create(self):
"""POST /users: Create a new item"""
# url('users')
c.default_extern_type = auth_modules.auth_internal.KallitheaAuthPlugin.name
user_model = UserModel()
user_form = UserForm()()
try:
form_result = user_form.to_python(dict(request.POST))
user = user_model.create(form_result)
usr = form_result['username']
action_logger(self.authuser, 'admin_created_user:%s' % usr,
None, self.ip_addr, self.sa)
h.flash(h.literal(_('Created user %s') % h.link_to(h.escape(usr), url('edit_user', id=user.user_id))),
category='success')
Session().commit()
except formencode.Invalid, errors:
return htmlfill.render(
render('admin/users/user_add.html'),
defaults=errors.value,
errors=errors.error_dict or {},
prefix_error=False,
encoding="UTF-8",
force_defaults=False)