本文整理汇总了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})