当前位置: 首页>>代码示例>>Python>>正文


Python UserForm.errors['passwd1']方法代码示例

本文整理汇总了Python中users.forms.UserForm.errors['passwd1']方法的典型用法代码示例。如果您正苦于以下问题:Python UserForm.errors['passwd1']方法的具体用法?Python UserForm.errors['passwd1']怎么用?Python UserForm.errors['passwd1']使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在users.forms.UserForm的用法示例。


在下文中一共展示了UserForm.errors['passwd1']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: reg_page

# 需要导入模块: from users.forms import UserForm [as 别名]
# 或者: from users.forms.UserForm import errors['passwd1'] [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))
开发者ID:kpx13,项目名称:derm_svp,代码行数:52,代码来源:client_views.py

示例2: profile

# 需要导入模块: from users.forms import UserForm [as 别名]
# 或者: from users.forms.UserForm import errors['passwd1'] [as 别名]
def profile(request):
    c = get_client_context(request)
    
    if c['client'].legal_entity:
        client_form = ClientForm(initial={'name': c['client'].legal_entity.name})
    profile_form = ProfileForm(instance=c['user_profile'])
    user_form = UserForm(instance=c['user'])
    robokassa_form = RobokassaForm(initial={
               'OutSum': 500,
               'InvId': 13,
               'Desc': u'Описание',
               'Email': '[email protected]',
               # 'IncCurrLabel': '',
               # 'Culture': 'ru'
           })
    
    if request.method == 'POST':
        action = request.POST.get('action')
        if action == 'user':
            user_form = UserForm(request.POST, instance=c['user'])
            
            if 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 user_form.is_valid():
                try:
                    u = user_form.save()
                    u.set_password(user_form.data['passwd1'])
                    u.save()
                    messages.success(request, u'Учетные данные успешно изменены.')
                    return HttpResponseRedirect('/profile')
                except:
                    u = None
                    user_form.errors['email'] = ErrorList([u'Пользователь с таким email уже существует'])
            
        elif action == 'profile':
            profile_form = ProfileForm(request.POST, instance=c['user_profile'])
            if profile_form.is_valid():
                profile_form.save()
                messages.success(request, u'Данные профиля успешно обновлены.')
                return HttpResponseRedirect('/profile')
        
        elif action == 'client':
            client_form = ClientForm(request.POST)
            #if client_form.is_valid():
            #    c = client_form.save()
            le = c['client'].legal_entity
            le.name = client_form.data['name']
            le.save()
            messages.success(request, u'Данные об организации успешно обновлены.')
            return HttpResponseRedirect('/profile')
        
        elif action == 'to_pay':
            pass
            
    
    c['client_form'] = client_form
    c['profile_form'] = profile_form
    c['user_form'] = user_form
    c['robokassa_form'] = robokassa_form
    print c['robokassa_form'] 
    
    
    return render_to_response('client/profile.html', c, context_instance=RequestContext(request))
开发者ID:kpx13,项目名称:derm_svp,代码行数:67,代码来源:client_views.py


注:本文中的users.forms.UserForm.errors['passwd1']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。