本文整理匯總了Python中forms.EditProfileForm.clean方法的典型用法代碼示例。如果您正苦於以下問題:Python EditProfileForm.clean方法的具體用法?Python EditProfileForm.clean怎麽用?Python EditProfileForm.clean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類forms.EditProfileForm
的用法示例。
在下文中一共展示了EditProfileForm.clean方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: editProfile
# 需要導入模塊: from forms import EditProfileForm [as 別名]
# 或者: from forms.EditProfileForm import clean [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})