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


Python LoginForm._errors['desabilitada']方法代码示例

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


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

示例1: user_login

# 需要导入模块: from accounts.forms import LoginForm [as 别名]
# 或者: from accounts.forms.LoginForm import _errors['desabilitada'] [as 别名]
def user_login(request):
    context = RequestContext(request)
    successfull = False
    logged = False
    if request.user.is_authenticated():
        logged = True;
    # if http is post take form data and login
    if request.method == 'POST':
        # get form data
        login_form = LoginForm(data=request.POST)
        if login_form.is_valid():
            ra = request.POST['ra']
            password = request.POST['password']
            user = None
            flag = False
            try:
                username = UserProfile.objects.get(ra=ra).user.username
                user = authenticate(username=username, password=password)
            except UserProfile.DoesNotExist:
                login_form._errors['inexistente'] = login_form.error_class([u'Ra inexistente'])
                flag = True
            finally:
                # pass into django authentication
                # if returned object from authenticate is not none (found the user)
                if user:
                    #checks if account was disabled
                    if user.is_active:
                        login(request, user)
                        # log the user in and successfull is set
                        successfull = True
                    else:
                        # error messages for the form
                        login_form._errors['desabilitada'] = login_form.error_class([u'Sua conta foi desabilitada, '
                                                                                     u'entre com contato com o '
                                                                                     u'administrador'])
                elif not flag:
                    # error messages for the form
                    login_form._errors['invalidos'] = login_form.error_class([u'Login ou senha invalidos'])

        else:
            # errors on the form validation
            pass
    else:
        # generates a blank unbound form
        login_form = LoginForm()
    template = 'accounts/login.html'
    return render(request, template, {'login_form': login_form,
                                         'successfull': successfull,
                                         'logged': logged})
开发者ID:fakegermano,项目名称:webponto,代码行数:51,代码来源:views.py


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