本文整理汇总了Python中forms.ProfileForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python ProfileForm.save方法的具体用法?Python ProfileForm.save怎么用?Python ProfileForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ProfileForm
的用法示例。
在下文中一共展示了ProfileForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getProfile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def getProfile(request):
# get user profile
user = request.user
profile = user.get_profile()
if request.method == 'POST':
profile_form = ProfileForm(request.POST,
request.FILES,
instance=profile)
user_form = UserForm(request.POST,
instance=request.user)
if profile_form.is_valid() and user_form.is_valid():
profile_form.save()
user_form.save()
resize_post_image.delay(profile_form.save())
messages.success(request, _("Profile updated succesfully."))
return redirect('index')
else:
profile_form = ProfileForm(instance=profile)
user_form = UserForm(instance=request.user)
return render(request, 'account/profile.html', {
'formProfile': profile_form,
'formUser': user_form
})
示例2: edit
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def edit(request):
""" Update UserProfile """
if request.method == 'POST':
form = ProfileForm(request.POST,
instance=UserProfile.objects.get(user=request.user))
if form.is_valid(): # All validation rules pass
try:
User.objects.filter(email=form.cleaned_data['email']).\
exclude(pk=request.user.pk).get()
request.session['flash'] = ['This e-mail is already in use',
'error']
return HttpResponseRedirect(
request.META.get('HTTP_REFERER', '/'))
except User.DoesNotExist:#Check if the e-mail is not already in use
pass
request.user.email = form.cleaned_data['email']
request.user.save()
form.save()
request.session['flash'] = ['Your profile has been updated',
'success']
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
else:
form = ProfileForm(instance=UserProfile.objects.get(user=request.user),
initial = {'email': request.user.email})
return render_to_response('accounts/edit.html', {'form': form},
context_instance=build_context(request))
示例3: update_profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def update_profile(request):
try:
promoter = request.user.promoterprofile
except PromoterProfile.DoesNotExist:
error_meta = {
"method": "promoter.views.update_profile",
}
ErrorLog.objects.create_log(4, "Promoter Object Error", error_meta, request)
raise SuspiciousOperation('Error Code: 4')
form = ProfileForm(request.POST or None, instance=promoter)
context = {
"form": form
}
if request.POST:
if form.is_valid():
form.save()
activity_meta = {
"method": "promoter.views.update_profile",
"form_validation": "True"
}
ActivityLog.objects.create_log(request, "Update Promoter Account", activity_meta)
return redirect('/pr/account/')
else:
return render(request, "promoter/edit_profile.html", context)
else:
activity_meta = {
"method": "promoter.views.update_profile",
}
ActivityLog.objects.create_log(request, "Update Promoter Account", activity_meta)
return render(request, "promoter/edit_profile.html", context)
示例4: profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def profile(request, tplname='userprefs/profile.html'):
update_password = True
if True in events.raiseQueryEvent("PasswordChange", request.user):
update_password = False
if request.method == "POST":
form = ProfileForm(
update_password, request.POST, instance=request.user
)
if form.is_valid():
form.save()
if update_password and form.cleaned_data["confirmation"] != "":
request.session["password"] = encrypt(form.cleaned_data["confirmation"])
return ajax_simple_response(dict(
status="ok", respmsg=_("Profile updated")
))
return ajax_simple_response({
"status": "ko",
"errors": form.errors
})
form = ProfileForm(update_password, instance=request.user)
return ajax_simple_response({
"status": "ok",
"content": _render_to_string(request, tplname, {
"form": form
})
})
示例5: edit
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def edit(request, template_name='edit_profile.html',
redirect_to='auth_profile'):
form = ProfileForm(request.POST, instance=request.user.get_profile())
if request.POST:
if form.is_valid():
form.save()
u = request.user
u.email = form.data['email']
u.first_name = form.data['first_name']
u.last_name = form.data['last_name']
u.save()
else:
return render_to_response(template_name, {'form': form},
context_instance=RequestContext(request))
return HttpResponseRedirect(reverse(redirect_to))
else:
initial_dict = {'email': request.user.email,
'username': request.user.username,
'first_name': request.user.first_name,
'last_name': request.user.last_name}
form = ProfileForm(instance=request.user.get_profile(),
initial=initial_dict)
return render_to_response(template_name, {'form': form},
context_instance=RequestContext(request))
示例6: edit_profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def edit_profile(request):
'''
'''
user = request.user
form = ProfileForm()
if request.method == "POST":
form = ProfileForm(request.POST, request.FILES)
if form.is_valid():
data = form.cleaned_data
'''
if len(data['name']) > NAME_MAX_LEN * 3:
messages.warning(request, u'名号输入过长,被自动截断')
if len(data['signature']) > SIGNATURE_MAX_LEN * 3:
messages.warning(request, u'签名输入过长,被自动截断')
'''
form.save(user.userprofile, data)
messages.success(request, u'个人资料修改成功')
else:
messages.error(request, u'你的输入有误')
profile = request.user.userprofile
return render_to_response('settings/edit_profile.html',
{'time_limit': PROFILE_NAME_CHANGE_DAYS,
'form': form,
'name': profile.name,
'website': profile.website,
'signature': profile.signature,
'detail': profile.detail,
},
context_instance=RequestContext(request))
示例7: profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def profile(request):
"""
Form for modifying and adding profile values
"""
if request.method == 'POST':
form = ProfileForm(request.POST,
instance = request.user)
email = request.POST.get('email', '')
if not email == '' and not email == request.user.email:
#confirm the email
salt = sha_constructor(str(random())).hexdigest()[:5]
confirmation_key = sha_constructor(salt + email).hexdigest()
current_site = Site.objects.get_current()
path = reverse('confirm_email',
args=[confirmation_key])
activate_url = u"http://%s%s" % (unicode(current_site.domain),
path)
context = {
"user": request.user,
"activate_url": activate_url,
"current_site": current_site,
"confirmation_key": confirmation_key,
}
subject = render_to_string(
"email_confirmation_subject.txt",
context)
# remove superfluous line breaks
subject = "".join(subject.splitlines())
message = render_to_string(
"email_confirmation_message.txt",
context)
print email
send_mail(subject,
message,
getattr(settings,
'DEFAULT_FROM_EMAIL',
'[email protected]%s' % current_site),
[email])
Email.objects.create(
owner = request.user,
email = email,
email_is_verified = False,
sent = datetime.now(),
confirmation_key = confirmation_key)
form.save()
return HttpResponseRedirect(request.POST.get('next', '/'))
else:
form = ProfileForm(instance = request.user)
next = request.GET.get('next', '/')
return render_to_response('profile.html',
{'form': form,
'next': next},
context_instance = RequestContext(request))
示例8: activate
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def activate(request, activation_key,
template_name='userena/activate_fail.html',
extra_context=None):
"""
Activate a user with an activation key.
"""
user = UserenaSignup.objects.activate_user(activation_key)
if user:
# Sign the user in.
auth_user = authenticate(identification=user.username,
check_password=False)
UserDetail.set_activation_datetime(auth_user)
login(request, auth_user)
if userena_settings.USERENA_USE_MESSAGES:
messages.success(request, _('Congratulations -- your Art of Gratitude account is confirmed!'),
fail_silently=True)
if request.method == 'POST':
form = ProfileForm(request.POST, user=user)
if form.is_valid():
form.save()
redirect_to = settings.LOGIN_REDIRECT_URL % {'username': user.username }
return redirect(redirect_to)
else:
if not extra_context: extra_context = {}
return ExtraContextTemplateView.as_view(template_name=template_name,
extra_context=extra_context)(request)
示例9: registration
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def registration(request):
if(request.user.is_authenticated()):
return redirect(list_bundles)
if request.method == 'POST':
form = ProfileForm(request.POST)
if form.is_valid():
form.save()
user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password'])
login(request,user)
messages.success(request, 'You have successfully registered!')
if form.data['next']:
return redirect(form.data['next'])
return redirect('/')
else:
for error in form.non_field_errors():
messages.error(request,error)
return render_to_response('server/register.html',{'form': form, 'next': form.data['next']},
context_instance=RequestContext(request))
form = ProfileForm()
if 'next' in request.GET:
next_page = request.GET['next']
else:
next_page = ''
return render_to_response('server/register.html', {'form': form, 'next': next_page},
context_instance=RequestContext(request))
示例10: base_profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def base_profile(request):
f_password = forms.PasswordChangeForm(request.POST)
f_profile = ProfileForm(instance=request.user.profile)
f_user = UserEditForm(instance=request.user)
commit = False
if request.method == "POST":
f_profile = ProfileForm(request.POST, request.FILES, instance=request.user.profile)
f_user = UserEditForm(request.POST, request.FILES, instance=request.user)
if f_password.is_valid():
f_password.save(commit=True)
# handle_uploaded_file(request.FILES['avatar'])
f_profile.save(commit=True)
commit = True
if f_profile.is_valid():
f_profile.save(commit=True)
# handle_uploaded_file(request.FILES['avatar'])
commit = True
if f_user.is_valid():
user = f_user.save(commit=True)
commit = True
return render_to_response(
"user/profile.html",
{"profile": f_profile, "f_pw": f_password, "f_user": f_user, "commit": commit},
context_instance=RequestContext(request),
)
示例11: post
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def post(self, request, pk=None):
if request.user.is_authenticated():
user = Profile.objects.get_or_create(user=request.user)[0]
form = ProfileForm(request.POST, request.FILES or None, instance=user)
if form.is_valid():
form.save()
return redirect("profile")
示例12: edit_user
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def edit_user(request):
profile_form = ProfileForm(request.POST, instance=request.user)
if profile_form.is_valid():
profile_form.save()
messages.success(request, 'Yup, changes made.')
else:
messages.error(request, 'Nop, something is wrong.')
return redirect('view_user', request.user.id)
示例13: profile_edit
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def profile_edit(request):
data = request.POST or None
profile_form = ProfileForm(data, instance=request.user)
if profile_form.is_valid():
profile_form.save()
messages.success(request, "Profile saved")
elif not data is None:
messages.error(request, "Profile could not be saved, because of invalid data")
return render(request, "profiles/edit.html", {'form': profile_form})
示例14: edit_profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def edit_profile(request, curr_user):
"Edit Profile Page"
if request.method == 'POST':
form = ProfileForm(request.POST, instance=curr_user.user_obj)
if form.is_valid():
form.save()
return render(request, 'edit_profile.html', {'form': form, 'saved': True, 'links': main.myprofile_links})
else:
form = ProfileForm(instance=curr_user.user_obj)
return render(request, 'edit_profile.html', {'form': form, 'links': main.myprofile_links})
示例15: edit_profile
# 需要导入模块: from forms import ProfileForm [as 别名]
# 或者: from forms.ProfileForm import save [as 别名]
def edit_profile(request):
if request.method == 'POST':
form = ProfileForm(request.POST, instance=request.user.get_profile())
if form.is_valid():
form.save()
else:
form = ProfileForm(instance=request.user.get_profile())
return render_to_response('users/edit_profile.html',
{'form': form},
context_instance=RequestContext(request))