本文整理汇总了Python中forms.EditProfileForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python EditProfileForm.save方法的具体用法?Python EditProfileForm.save怎么用?Python EditProfileForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.EditProfileForm
的用法示例。
在下文中一共展示了EditProfileForm.save方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import save [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))
示例2: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import save [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,
})
示例3: POST
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import save [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})
示例4: user_settings
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import save [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))
示例5: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import save [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,
}))
示例6: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import save [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))
示例7: edit
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import save [as 别名]
def edit(request):
profile = UserProfile.objects.get_or_create(user=request.user)[0]
if request.method == 'POST':
form = EditProfileForm(request.POST, request.FILES, instance=profile)
if form.is_valid():
form.save()
return HttpResponseRedirect('/profile/my/')
else:
form = EditProfileForm(request.POST, request.FILES, instance=profile)
return render(request, 'profile/edit.html', {'form': form})
else:
profile.birth_date = profile.birth_date.strftime("%m/%d/%Y") if profile.birth_date else profile.birth_date
form = EditProfileForm(instance=profile)
return render(request, 'profile/edit.html',
{'form': form,
'page_title': 'profile/edit',
'sidebar_item': 'view-profile'})
示例8: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import save [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))
示例9: edit_profile
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import save [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})
)
示例10: post
# 需要导入模块: from forms import EditProfileForm [as 别名]
# 或者: from forms.EditProfileForm import save [as 别名]
def post(self, request):
form = EditProfileForm(request.POST, instance=request.user)
if form.is_valid():
form.save()
messages.info(request,"Your profile has been successfully updated!")
return render(request, self.template_name, {'form': form})