本文整理汇总了Python中User.models.User.addUser方法的典型用法代码示例。如果您正苦于以下问题:Python User.addUser方法的具体用法?Python User.addUser怎么用?Python User.addUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User.models.User
的用法示例。
在下文中一共展示了User.addUser方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import addUser [as 别名]
def register(request):
try:
if request.method != 'POST':
return render(request, 'newtpl/register.html', {})
form = RegisterForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
passwd_1 = form.cleaned_data['passwd1']
passwd_2 = form.cleaned_data['passwd2']
if passwd_1 != passwd_2:
raise Exception(u'两次密码不一致')
test_uni = University.getByName('test')
new_user = User.addUser(username, passwd_1, test_uni, 'student')
group = Group.getById(52)
group.addMember(new_user)
messages.add_message(request, messages.SUCCESS, u'注册用户test#%s成功!' % username)
return redirect("/")
# return redirect('User:viewuser', uid = new_user.uid)
else:
raise Exception('注册失败!')
except Exception as e:
logger.error(unicode(e).replace('\n', '\t'))
messages.error(request, u'输入信息不合法或该用户已被注册!')
return render(request, Err.ERROR_PAGE)
示例2:
# 需要导入模块: from User.models import User [as 别名]
# 或者: from User.models.User import addUser [as 别名]
from Privilege.models import Root, AdminInfo
from User.models import User, Admin
r = Root.objects.create(root_name='kari', root_name_cn='kari')
u = User.addUser(username='jffifa', passwd='123456', root=r)
r = Root.objects.create(root_name='bupt', root_name_cn='bupt')
u = User.addUser(username='keyang', passwd='123456', root=r)
a = Admin.objects.create(user=u, parent=None)
ai = AdminInfo.objects.create(admin=a, contest_lim=-1)
u2 = User.addUser(username='zhangyu', passwd='123456', root=r)
a2 = Admin.objects.create(user=u2, parent=a)
ai2 = AdminInfo.objects.create(admin=a2, contest_lim=-1)