本文整理汇总了Python中users.forms.UserForm.errors['confirm']方法的典型用法代码示例。如果您正苦于以下问题:Python UserForm.errors['confirm']方法的具体用法?Python UserForm.errors['confirm']怎么用?Python UserForm.errors['confirm']使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.forms.UserForm
的用法示例。
在下文中一共展示了UserForm.errors['confirm']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reg_page
# 需要导入模块: from users.forms import UserForm [as 别名]
# 或者: from users.forms.UserForm import errors['confirm'] [as 别名]
def reg_page(request):
c = get_common_context(request)
if request.method == 'GET':
client_form = ClientForm()
profile_form = ProfileForm()
user_form = UserForm()
elif request.method == 'POST':
client_form = ClientForm(request.POST)
profile_form = ProfileForm(request.POST)
user_form = UserForm(request.POST)
if request.POST.get('confirm', None) is None:
user_form.errors['confirm'] = ErrorList([u'Необходимо согласиться с договором.'])
elif user_form.data['passwd1'] != user_form.data['passwd2']:
user_form.errors['passwd1'] = ErrorList([u'Пароли не совпадают.'])
elif not user_form.data['email']:
user_form.errors['email'] = ErrorList([u'Обязательное поле.'])
elif client_form.is_valid() and profile_form.is_valid() and user_form.is_valid():
try:
u = auth.models.User(username=user_form.data['email'],
email=user_form.data['email'],
first_name=user_form.data['first_name'],
)
u.save()
u.set_password(user_form.data['passwd1'])
u.save()
except:
u = None
user_form.errors['email'] = ErrorList([u'Пользователь с таким email уже существует'])
if u: # user saved, all is right
p = u.get_profile()
p.phone = profile_form.data['phone']
p.work_phone=profile_form.data['work_phone']
p.qiwi=profile_form.data['qiwi']
p.user = u
p.type = 'c'
p.save()
Client.add(u, client_form.data['name'])
user = auth.authenticate(username=user_form.data['email'], password=user_form.data['passwd1'])
auth.login(request, user)
messages.success(request, u'Вы успешно зарегистрировались в системе в качестве клиента.')
return HttpResponseRedirect('/cabinet')
c['client_form'] = client_form
c['profile_form'] = profile_form
c['user_form'] = user_form
return render_to_response('client/reg.html', c, context_instance=RequestContext(request))