本文整理汇总了Python中users.forms.ProfileForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python ProfileForm.save方法的具体用法?Python ProfileForm.save怎么用?Python ProfileForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.forms.ProfileForm
的用法示例。
在下文中一共展示了ProfileForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_profile
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def edit_profile(request):
user = request.user
users = User.objects.get(username=user)
profile = Profile.objects.get(user=user)
group = Group.objects.get(name='user')
user_members = group.user_set.all()
if user in user_members:
if request.method == 'POST':
form1 = EditUserForm(request.POST, instance=users)
form2 = ProfileForm(request.POST, instance=profile)
if form1.is_valid() and form2.is_valid():
form2.save()
form1.save()
return HttpResponseRedirect('/')
else:
form1 = EditUserForm(instance=users)
form2 = ProfileForm(instance=profile)
variables = RequestContext(request, {'user':user,'user_members':user_members,'form1': form1, 'form2':form2})
else:
if request.method == 'POST':
form1 = MerchantForm(request.POST, instance=users)
if form1.is_valid():
form1.save()
return HttpResponseRedirect('/')
else:
form1 = MerchantForm(instance=users)
variables = RequestContext(request, {'user':user,'user_members':user_members,'form1': form1})
return render_to_response('users/edit_profile.html', variables)
示例2: post
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def post(self, *args, **kwargs):
if not self.request.user.is_authenticated():
return self.render({'error': 'Please log in before posting'})
form = ProfileForm(data=json.load(self.request), instance=self.request.user)
if form.is_valid():
form.save()
return self.get(*args, **kwargs)
else:
return self.render({'error': 'Data is invalid', 'errors_list': form.errors})
示例3: save
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def save(request, user_id): # action
# saves changes to user profile
user = get_object_or_404(User, pk=user_id)
userProfile = Profile.objects.get(user=user)
if request.method == 'POST':
form = ProfileForm(request.POST,instance=userProfile)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('users:profile', args=[user_id]))
else:
return HttpResponseRedirect(reverse('users:edit', args=[user_id]))
示例4: edit_profile
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def edit_profile(request):
profile = get_profile(request.user)
if request.method == "GET":
profile_form = ProfileForm(instance=profile)
elif request.method == "POST":
profile_form = ProfileForm(instance=profile, data=request.POST)
if profile_form.is_valid():
profile_form.save()
messages.add_message(request, messages.SUCCESS,
"Your profile has been updated.")
return render(request, "users/edit_profile.html", {"form": profile_form})
示例5: user_edit
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def user_edit(request, pk):
user = User.get(pk)
form = UserForm(request.POST or None, instance=user)
profile = ProfileForm(request.POST or None, instance=get_profile(user))
if form.is_valid() and profile.is_valid():
form.save()
profile.save()
return HttpResponseRedirect(reverse("user-list"))
return direct_to_template(request, "user_edit.html", extra_context={
"form": form,
"profile": profile,
"nav": {"selected": "users",},
})
示例6: lk
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def lk(request):
c = get_common_context(request)
if not request.user.is_authenticated():
return HttpResponseRedirect('/')
if request.method == 'GET':
c['form'] = ProfileForm(instance=request.user.get_profile())
else:
form = ProfileForm(request.POST, instance=request.user.get_profile())
if form.is_valid():
form.save()
return HttpResponseRedirect('/lk/')
c['form'] = form
return render_to_response('lk.html', c, context_instance=RequestContext(request))
示例7: edit_profile
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def edit_profile(request):
try:
profile = Profile.objects.get(user=request.user)
except Profile.DoesNotExist:
raise Http404
if request.method == 'POST':
form = ProfileForm(data=request.POST, files=request.FILES, instance=profile)
if form.is_valid():
form.save()
return HttpResponseRedirect('/user/')
else:
print profile
form = ProfileForm(instance=profile)
return render(request, 'profiles/edit_profile.html', {"profile": profile, "form": form})
示例8: post
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def post(self, *args, **kwargs):
if not self.request.user.is_authenticated():
return self.render({'error': 'Please log in before posting'})
form = ProfileForm(data=self.post_data(), instance=self.request.user)
if form.is_valid():
form.save()
if not self.request.is_ajax():
messages.success(self.request, u'Data saved.')
return redirect('.')
else:
return self.get(*args, **kwargs)
else:
return self.render({'error': 'Data is invalid', 'errors_list': form.errors})
示例9: profile
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def profile(request):
if request.method == "POST":
form = ProfileForm(request.POST, instance=request.user)
if form.is_valid():
try:
form.save()
messages.add_message(request, messages.SUCCESS, "Your profile has been updated successfully.")
return redirect(reverse('profile'))
except:
pass
else:
form = ProfileForm(instance=request.user)
data = {'form': form}
return render(request, 'registration/profile.html', data)
示例10: post
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def post(self, request):
if request.GET.get('login'):
self.post_login(request)
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username, password=password)
if user:
if user.is_active:
login(request, user)
return redirect('tasks:index')
return render(request, 'users/login.html', {'user_form': UserForm(), 'profile_form': ProfileForm()})
else:
user_form = UserForm(data=request.POST)
profile_form = ProfileForm(data=request.POST)
if user_form.is_valid() and profile_form.is_valid():
with atomic():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=False)
profile.user = user
profile.creating = True
profile.updating = True
thread = Thread()
thread.save()
profile.thread = thread
profile.save()
login(request, user)
return redirect('tasks:index')
else:
return render(request, 'users/login.html', {'user_form':user_form, 'profile_form': profile_form})
示例11: edit_profile
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def edit_profile(request):
"""Edit user profile."""
try:
user_profile = request.user.get_profile()
except Profile.DoesNotExist:
# TODO: Once we do user profile migrations, all users should have a
# a profile. We can remove this fallback.
user_profile = Profile.objects.create(user=request.user)
if request.method == 'POST':
form = ProfileForm(request.POST, request.FILES, instance=user_profile)
if form.is_valid():
user_profile = form.save()
new_timezone = user_profile.timezone
if request.session.get('timezone', None) != new_timezone:
request.session['timezone'] = new_timezone
return HttpResponseRedirect(reverse('users.profile',
args=[request.user.id]))
else: # request.method == 'GET'
form = ProfileForm(instance=user_profile)
# TODO: detect timezone automatically from client side, see
# http://rocketscience.itteco.org/2010/03/13/automatic-users-timezone-determination-with-javascript-and-django-timezones/
return jingo.render(request, 'users/edit_profile.html',
{'form': form, 'profile': user_profile})
示例12: post
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def post(self, request):
user_form = UserForm(request.POST)
profile_form = ProfileForm(request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
profile = profile_form.save(commit=False)
profile.user = user
profile.save()
password = user.password
user.set_password(password)
user.save()
user = authenticate(username=user.username,
password=password)
login(self.request, user)
messages.add_message(
request,
messages.SUCCESS,
"Account Successfully Created.")
return redirect("/")
else:
return render(request, "users/register.html", {"form1": user_form, "form2": profile_form})
示例13: user_register
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def user_register(request):
if request.method == "GET":
user_form = UserForm()
profile_form = ProfileForm()
elif request.method == "POST":
user_form = UserForm(request.POST)
profile_form = ProfileForm(request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
profile = profile_form.save(commit=False)
profile.user = user
profile.save()
password = user.password
# The form doesn't know to call this special method on user.
user.set_password(password)
user.save()
# You must call authenticate before login. :(
user = authenticate(username=user.username,
password=password)
login(request, user)
messages.add_message(
request,
messages.SUCCESS,
"Congratulations, {}, on creating your new account! You are now logged in.".format(
user.username))
return redirect('index')
return render(request, "users/register.html", {'user_form': user_form,
'profile_form': profile_form})
示例14: update_profile
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def update_profile(request):
"""
User Profile linked one2one with user model. Also links user to company
account
Contains basic details such as web_site, about, city
"""
form = ProfileForm(request.POST or None, instance=request.user.get_profile())
if form.is_valid():
form.save()
messages.success(request, "Profile updated successfully")
return redirect("users:settings")
return render(request, "users/update_profile.html", locals())
示例15: settings
# 需要导入模块: from users.forms import ProfileForm [as 别名]
# 或者: from users.forms.ProfileForm import save [as 别名]
def settings(request):
profile = request.user.get_profile()
if request.method == 'POST':
form = ProfileForm(request.POST, instance=profile)
if form.is_valid():
form.save()
messages.success(request, _('Your settings have been updated'))
return redirect(reverse('default_inbox'))
else:
# TODO: handle correctly the error and translate the message
err = "Incorrect config..."
else:
err = ''
form = ProfileForm(instance=profile)
context = {'user': request.user, 'form': form,}
return render(request, 'settings.html', context)