本文整理汇总了Python中forms.EditProfileForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python EditProfileForm.is_valid方法的具体用法?Python EditProfileForm.is_valid怎么用?Python EditProfileForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.EditProfileForm
的用法示例。
在下文中一共展示了EditProfileForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: editProfile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def editProfile(request):
if request.method == 'POST':
form = EditProfileForm(request.POST, request.FILES)
if form.is_valid():
cleaned_data = form.clean()
first_name = cleaned_data['first_name'].strip()
last_name = cleaned_data['last_name'].strip()
email = cleaned_data['emailAddress']
dorm = cleaned_data['dorm']
pic = request.FILES.get('pic','')
user = User.objects.get(username = request.user)
userdata = user.userdata
if first_name.strip():
user.first_name = first_name
if last_name.strip():
user.last_name = last_name
if email.strip():
user.email = email
if dorm.strip():
userdata.dorm = dorm
if pic:
userdata.pic = pic
user.save()
userdata.save()
return HttpResponseRedirect('/')
else:
user = request.user
userdata = user.userdata
data = {'first_name':user.first_name, 'last_name':user.last_name, 'emailAddress':user.email, 'dorm':userdata.dorm}
form = EditProfileForm(initial = data)
return render(request, 'editProfile.html', {'form':form})
示例2: edit
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def edit(request):
"""
Obsługuje dwa typy żądań:
* GET -- tworzy formularz do edytowania swoich danych
* POST -- sprawdza poprawność danych i zapisuje je w bazie
:returns: jeśli podane dane są poprawne do generuje stronę do edycji danych,
jeśli dane są niepoprawne to wskazuje błędne pola
.. include:: ../source/login_required.rst
"""
if request.method == 'GET':
form = EditProfileForm(initial={
'first_name': request.user.first_name,
'last_name': request.user.last_name,
'email': request.user.email })
elif request.method == 'POST':
form = EditProfileForm(request.POST)
if form.is_valid():
user = request.user
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.email = form.cleaned_data['email']
if form.cleaned_data['password']:
user.set_password(form.cleaned_data['password'])
user.save()
messages.success(request, UPDATED)
return direct_to_template(request, 'profiles/edit.html', locals())
示例3: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def edit_profile(request):
"""
view untuk fungsionalitas perubahan data profile
account
"""
if request.POST:
old_picture = request.user.profile.picture
form = EditProfileForm(request.POST, request.FILES,
instance=request.user.profile)
if form.is_valid():
if 'picture' in request.FILES:
from os import unlink
if old_picture.name != 'profpic/default.jpg':
unlink(old_picture.path)
form.save()
request.user.email = form.cleaned_data['email']
request.user.first_name = form.cleaned_data['first_name']
request.user.last_name = form.cleaned_data['last_name']
request.user.save()
messages.info(request, _('Profile updated'))
return HttpResponseRedirect(reverse('self_profile'))
else:
form = EditProfileForm(instance=request.user.profile,
initial={'email': request.user.email,
'first_name': request.user.first_name,
'last_name': request.user.last_name})
return render_to_response('accounts/edit_profile.html',
{'form': form},
context_instance=RequestContext(request))
示例4: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def edit_profile(request, username):
if username != request.user.username:
return HttpResponseForbidden()
if request.method == 'POST':
form = EditProfileForm(request.POST, request.user)
if form.is_valid():
cd = form.cleaned_data
p = request.user.profile
for item in cd:
try:
if getattr(request.user, item) != cd[item]:
setattr(request.user, item, cd[item])
except:
if getattr(p, item) != cd[item]:
setattr(p, item, cd[item])
request.user.save()
p.save()
return HttpResponseRedirect(reverse(profile, kwargs={'username': request.user.username}))
else:
return render_to_response(request, 'edit_profile.html', {'form': form})
user_data = {}
for field in EditProfileForm():
try:
if 'password' not in field.name:
user_data[field.name] = getattr(request.user, field.name)
except:
if 'password' not in field.name:
user_data[field.name] = getattr(request.user.profile, field.name)
form = EditProfileForm(initial=user_data)
return render_to_response(request, 'edit_profile.html', {'form': form})
示例5: editProfile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def editProfile(request):
if request.method == 'POST': # If the form has been submitted...
form = EditProfileForm(request.POST) # A form bound to the POST data
# assume that we have done the validation on the client side
if(form.is_valid()):
print "here?"
messages.success(request, 'Your new profile information was saved')
# get form data
email = form.cleaned_data['email']
password = form.cleaned_data['password']
first_name = form.cleaned_data['first_name']
last_name = form.cleaned_data['last_name']
# get user object and then bind data to user
user = User.objects.get(id__iexact=request.session['user_id'])
user.first_name = first_name
user.last_name = last_name
user.email = email
user.password = make_password(password)
user.save()
request.session['user_id'] = user.id
request.session['first_name'] = user.first_name
request.session['last_name'] = user.last_name
request.session['email'] = email
return HttpResponseRedirect('/home/profile') # Redirect after POST
return HttpResponseRedirect('/error')
示例6: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def edit_profile(request,id):
if request.method =='GET' :
if request.user.is_authenticated():
now = timezone.make_aware(datetime.now(),timezone.get_default_timezone())
now = formats.date_format(now,"SHORT_DATETIME_FORMAT")
data = User.objects.get(pk=id)
form = EditProfileForm()
dv = {'first_name':data.first_name,'last_name':data.last_name,'email':data.email}
form = EditProfileForm(dv)
return render(request, 'userprofile_edit.html', {'form':form,'timezones':pytz.common_timezones,"date":str(now)})
else:
return redirect('/authen/')
elif request.method == 'POST' :
now = timezone.make_aware(datetime.now(),timezone.get_default_timezone())
now = formats.date_format(now,"SHORT_DATETIME_FORMAT")
data = User.objects.get(pk=id)
if request.POST.get('updateuser'):
user = request.user
time = request.POST['timezone']
form = EditProfileForm(request.POST)
time_user = UserProfile.objects.filter(pk=id).update(user_timezone=time)
request.session['django_timezone'] = request.POST['timezone']
if form.is_valid():
user.first_name = request.POST['first_name']
user.last_name = request.POST['last_name']
user.email = request.POST['email']
user.save()
return redirect('/userprofile/')
elif request.POST.get('canceledituser'):
return redirect('/userprofile/')
示例7: test_edit_profile_form
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def test_edit_profile_form(self):
epf = EditProfileForm({
'first_name': 'Jan',
'last_name': 'Kowalski',
'email': '[email protected]',
})
self.assertTrue(epf.is_valid(), 'Niepoprawny formularz.')
self.assertFalse(EditProfileForm().is_valid(), 'Niepoprawny formularz.')
示例8: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def edit_profile(request):
if request.method == 'POST':
form = EditProfileForm(request.POST, instance=request.user.profile)
if form.is_valid():
form.save()
return redirect('accounts:view_profile', request.user.id)
else:
form = EditProfileForm(instance=request.user.profile)
return render(request, 'accounts/edit_profile.html', {
'form': form,
})
示例9: POST
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def POST(self):
files_req = self.request.FILES
if (files_req.get('photo', '')):
files_req['photo'].name = self.request.user.username
form = EditProfileForm(self.request, self.request.POST,
files_req, instance=self.request.user)
if not form.is_valid():
return self.context_response('user/profile.html', {'form': form})
# Send an email to admins with old data
old_user = self.request.user
subject = I18nString(_("[%(site_name)s] %(username)s modified his data"), {
'site_name': settings.SITE_NAME,
'username': old_user.username
})
message = I18nString(_("Username %(username)s modified his profile. Old data:\n\n"
u" - Name: %(old_name)s\n"
u" - Last name: %(old_surnames)s\n"
u" - Email address: %(old_email)s\n"
u" - Address: %(old_address)s\n"
u" - Birth date: %(old_birth_date)s\n"
u" - Description: %(old_description)s\n\n"
u"New data:\n\n"
u" - Name: %(name)s\n"
u" - Last name: %(surnames)s\n"
u" - Email address: %(email)s\n"
u" - Address: %(address)s\n"
u" - Birth date: %(birth_date)s\n"
u" - Description: %(description)s\n\n"), {
'username': old_user.username,
'old_name': old_user.first_name,
'old_surnames': old_user.last_name,
'old_email': old_user.email,
'old_address': old_user.address,
'old_birth_date': old_user.birth_date,
'old_description': old_user.description,
'name': form.cleaned_data["first_name"],
'surnames': form.cleaned_data["last_name"],
'email': form.cleaned_data["email"],
'address': form.cleaned_data["address"],
'birth_date': form.cleaned_data["birth_date"],
'description': form.cleaned_data["description"]
})
mail_owners(subject, message)
form.save()
self.flash(_("Profile updated: <a href=\"%s\">view your profile</a>.") %
reverse("user-view-current"))
return self.context_response('user/profile.html', {'form': form})
示例10: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def edit_profile(request):
if request.method == 'POST':
edit_form = EditProfileForm(user=request.user, data=request.POST)
if edit_form.is_valid():
user = edit_form.save()
m = request.user.message_set.create()
m.message = 'Your profile has been updated.'
m.save()
return HttpResponseRedirect('.')
if request.method == 'GET':
edit_form = EditProfileForm(user = request.user)
payload = {'edit_form':edit_form}
return render_to_response('accounts/editprofile.html', payload, RequestContext(request))
示例11: user_settings
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def user_settings(request):
if request.method == 'POST':
form = EditProfileForm(request.POST, instance=request.user.drinker)
if form.is_valid():
form.save()
return HttpResponseRedirect('/u/%s' % request.user.username)
else:
form = EditProfileForm(instance=request.user.drinker)
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('settings.html', args, context_instance=RequestContext(request))
示例12: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def edit_profile(request):
if request.method == 'POST':
edit_form = EditProfileForm(user=request.user, data=request.POST)
if edit_form.is_valid():
edit_form.save()
m = request.user.message_set.create()
m.message = 'Your profile has been updated.'
m.save()
return HttpResponseRedirect('.')
if request.method == 'GET':
edit_form = EditProfileForm(user = request.user)
return render_to_response('user/editprofile.html',
context_instance=RequestContext(request,
{'edit_form': edit_form,
}))
示例13: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def edit_profile(request):
if request.method == "POST":
edit_form = EditProfileForm(user=request.user, data=request.POST)
if edit_form.is_valid():
user = edit_form.save()
m = request.user.message_set.create()
m.message = "Your profile has been updated."
m.save()
return HttpResponseRedirect(".")
if request.method == "GET":
edit_form = EditProfileForm(user=request.user)
payload = {"edit_form": edit_form}
return render_to_response(
"user/editprofile.html", context_instance=RequestContext(request, {"edit_form": edit_form})
)
示例14: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def edit_profile(request, username):
user = get_object_or_404(User, username=username)
member = user.get_profile()
if request.method == 'POST':
profile_form = EditProfileForm(request.POST, request.FILES)
if profile_form.is_valid():
profile_form.save()
return HttpResponseRedirect(reverse('members.views.user', kwargs={'username':user.username}))
else:
profile_form = EditProfileForm(initial={'member_id':member.id, 'phone':member.phone, 'phone2':member.phone2, 'email2':member.email2,
'address1':member.address1, 'address2':member.address2, 'city':member.city, 'state':member.state, 'zipcode':member.zipcode,
'company_name':member.company_name, 'url_personal':member.url_personal, 'url_professional':member.url_professional,
'url_facebook':member.url_facebook, 'url_twitter':member.url_twitter, 'url_biznik':member.url_biznik,
'url_linkedin':member.url_linkedin, 'url_loosecubes':member.url_loosecubes, 'gender':member.gender, 'howHeard':member.howHeard,
'industry':member.industry, 'neighborhood':member.neighborhood, 'has_kids':member.has_kids, 'self_employed':member.self_employed})
return render_to_response('members/edit_profile.html',{'user':user, 'profile_form':profile_form}, context_instance=RequestContext(request))
示例15: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import is_valid [as 别名]
def edit_profile(request):
to_return = {}
userprofile = request.user.get_profile()
editprofileForm = EditProfileForm(request.POST or None,instance=userprofile)
for field in editprofileForm.fields:
print editprofileForm[field].errors
if editprofileForm.is_valid():
if editprofileForm.save_profile(request.user):
messages.success(request,'Successfully updated profile.')
return HttpResponseRedirect(request.path)
return_url=reverse('edit_profile')
to_return = {
'form' : editprofileForm,
'title' : 'Edit Profile',
'return_url' : return_url,
'button' : 'Update',
}
return render(request,'form1.html',to_return,context_instance=RequestContext(request))