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