本文整理汇总了Python中forms.ChangePasswordForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python ChangePasswordForm.save方法的具体用法?Python ChangePasswordForm.save怎么用?Python ChangePasswordForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ChangePasswordForm
的用法示例。
在下文中一共展示了ChangePasswordForm.save方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: changePassword
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import save [as 别名]
def changePassword(request):
otherVars = {}
otherVars["pageType"] = "logon"
otherVars["UserInfo"] = request.user.first_name + " " + request.user.last_name
if request.method == "POST":
form1 = ChangePasswordForm(request.user, request.POST)
# input validation for change password
if form1.is_valid():
# update the user information
form1.save()
request.session["msgNote"] = [
"fileView",
{"sign": "ok", "msg": "Your password has been updated successfully!"},
]
return HttpResponseRedirect(reverse("fileView"))
else:
form1 = ChangePasswordForm(request.user)
# Define header groups
hgrps = ({"name": "Change Password", "lblwidth": "160"},)
# For first header group
form1.fields["oldPwd"].widget.attrs["hgrp"] = "0"
form1.fields["oldPwd"].widget.attrs["wsize"] = "300"
form1.fields["newPwd"].widget.attrs["hgrp"] = "0"
form1.fields["newPwd"].widget.attrs["wsize"] = "300"
form1.fields["cfmPwd"].widget.attrs["hgrp"] = "0"
form1.fields["cfmPwd"].widget.attrs["wsize"] = "300"
return render(request, "main/chgpasswd.html", {"otherVars": otherVars, "form1": form1, "hgrps": hgrps})
示例2: edit_account
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import save [as 别名]
def edit_account(request, entry=None):
if entry not in (None, 'email', 'username', 'password'):
raise Http404
if request.method=='POST' and entry=='email':
email_form = ChangeEmailForm(request.POST, instance=request.user)
if email_form.is_valid():
email_form.save()
return redirect('accounts:edit_account')
else:
email_form = ChangeEmailForm(instance=request.user)
if request.method=='POST' and entry=='username':
username_form = ChangeUsernameForm(request.POST, instance=request.user)
if username_form.is_valid():
username_form.save()
return redirect('accounts:edit_account')
else:
username_form = ChangeUsernameForm(instance=request.user)
if request.method=='POST' and entry=='password':
password_form = ChangePasswordForm(request.POST, instance=request.user)
if password_form.is_valid():
password_form.save()
return redirect('accounts:edit_account')
else:
password_form = ChangePasswordForm(instance=request.user)
return render(request, 'accounts/edit_account.html', {
'email_form': email_form,
'username_form': username_form,
'password_form': password_form,
})
示例3: changepassword
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import save [as 别名]
def changepassword(request):
if request.method == "POST":
form = ChangePasswordForm(user=request.user, data=request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect("/accounts/logout/")
else:
form = password_change_form(user=request.user)
return render_to_response('index.html', {
"title": '主页',
'username': request.user.username,
'form': form}, context_instance=RequestContext(request))
示例4: change_password
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import save [as 别名]
def change_password(request):
redirect_url = reverse("account.views.home")
if request.method == "POST":
form = ChangePasswordForm(user=request.user, data=request.POST)
if form.is_valid():
form.save(commit=True)
return redirect(redirect_url)
else:
form = ChangePasswordForm(user=request.user)
breadcrumb = [{"name": u"首页", "url": "/"}, {'name': u'修改密码'}]
return render_template("change_password.html", request, form=form, breadcrumb=breadcrumb)
示例5: change_password
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import save [as 别名]
def change_password(request):
if request.method == "POST":
form = ChangePasswordForm(user=request.user, data=request.POST)
if form.is_valid():
form.save()
ret = {"status": 1, "msg": "is ok"}
else:
ret = {"status": 0, "msg": "is over"}
obj = json.dumps(ret)
return HttpResponse(obj)
else:
obj = json.dumps({"status": -1, "msg": "error"})
return HttpResponse(obj)
示例6: change_password
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import save [as 别名]
def change_password(request):
temp_name = "accounts/accounts-header.html"
if request.method == 'POST':
form = ChangePasswordForm(user=request.user, data=request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('logout'))
else:
form = ChangePasswordForm(user=request.user)
kwargs = {
'form': form,
'request': request,
'temp_name': temp_name,
}
return render(request, 'accounts/change_password.html', kwargs)
示例7: change_password
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import save [as 别名]
def change_password(request, form):
dajax = Dajax()
form = ChangePasswordForm(deserialize_form(form))
if form.is_valid():
form.save()
dajax.remove_css_class('#change_password_form .control-group', 'error')
dajax.add_data({ 'ret_code' : 0, 'ret_msg' : 'success' }, 'changePasswordCallback')
else:
dajax.remove_css_class('#change_password_form .control-group', 'error')
for error in form.errors:
dajax.add_css_class('#%s' % error, 'error')
dajax.add_data({ 'ret_code' : 1000, 'ret_msg' : 'error' }, 'changePasswordCallback')
return dajax.json()
示例8: profile
# 需要导入模块: from forms import ChangePasswordForm [as 别名]
# 或者: from forms.ChangePasswordForm import save [as 别名]
def profile(request):
profile = Profile.objects.get_or_create(user=request.display_user)[0]
column = Columns.objects.get_or_create(user=request.display_user)[0]
auto = AutoButton.objects.get_or_create(user=request.display_user)[0]
if request.POST:
profile_form = ProfileForm(request.POST, instance=profile)
user_form = UserForm(request.POST, instance=request.display_user)
column_form = ColumnsForm(request.POST, prefix="column", instance=column)
auto_form = AutoForm(request.POST, prefix="auto", instance=auto)
password_form = ChangePasswordForm(request.POST, prefix='pass', user=request.user)
if request.POST.get("submit") == "Delete All Flights":
Flight.objects.filter(user=request.display_user).delete()
edit_logbook.send(sender=request.display_user)
elif request.POST.get("submit") == "Delete All Events":
NonFlight.objects.filter(user=request.display_user).delete()
elif request.POST.get("submit") == "Delete Unused Planes":
Plane.objects.filter(flight__isnull=True, user=request.display_user).delete()
edit_logbook.send(sender=request.display_user)
elif request.POST.get("submit") == "Completely Reset All Data":
NonFlight.objects.filter(user=request.display_user).delete()
Flight.objects.filter(user=request.display_user).delete()
Records.objects.filter(user=request.display_user).delete()
Location.objects.filter(loc_class=3, user=request.display_user).delete()
Plane.objects.filter(user=request.display_user).delete()
edit_logbook.send(sender=request.display_user)
else:
if auto_form.is_valid():
auto_form.save()
if profile_form.is_valid():
profile_form.save()
if column_form.is_valid():
column_form.save()
if user_form.is_valid():
## remove illegal characters and spaces
user = user_form.save(commit=False)
user.username = \
re.sub(r'\W', '', user.username)\
.replace(" ",'')
if request.display_user.id == settings.DEMO_USER_ID:
## don't let anyone change the demo's username or email
## it will break stuff
user_form.cleaned_data['username'] = 'demo'
user_form.cleaned_data['email'] = '[email protected]'
user.save()
if password_form.is_valid():
password_form.save()
else:
profile_form = ProfileForm(instance=profile)
user_form = UserForm(instance=request.display_user)
column_form = ColumnsForm(prefix="column", instance=column)
auto_form = AutoForm(prefix="auto", instance=auto)
password_form = ChangePasswordForm(prefix='pass')
f1 = '<td class="{cls}">{checkbox}</td>'
f2 = '<td class="title">{title}</td><td class="description">{desc}</td>\n'
bool_fields = []
## mix the auto button and the columns fields into the same html table
## FIXME: this should all be in a template tag
for field in OPTION_FIELDS:
row = []
row.append("<tr>\n")
if auto_form.fields.get(field):
checkbox = str(auto_form[field])
else:
checkbox = "<input type='checkbox' style='visibility: hidden'>"
row.append(f1.format(checkbox=checkbox, cls="aauto"))
if column_form.fields.get(field):
formatted = f1.format(checkbox=str(column_form[field]), cls="column")
row.append(formatted)
else:
row.append('<td class="column"></td>')
formatted = f2.format(title=FIELD_TITLES[field], desc=column_form[field].help_text)
row.append(formatted)
row.append("</tr>\n")
bool_fields.append("".join(row))
return locals()