本文整理汇总了Python中forms.SettingsForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python SettingsForm.save方法的具体用法?Python SettingsForm.save怎么用?Python SettingsForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.SettingsForm
的用法示例。
在下文中一共展示了SettingsForm.save方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def settings(request):
if request.POST:
settingsForm = SettingsForm(request.POST, instance=request.user)
if settingsForm.is_valid():
settingsForm.save()
messages.info(request, 'User settings saved.')
return redirect('dashboard')
else:
settingsForm = SettingsForm(instance=request.user)
return render(request, 'settings.html', {'settingsForm': settingsForm})
示例2: settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def settings(request, user_id):
user = get_object_or_404(User, id=user_id)
if request.user != user and not request.user.is_superuser:
return HttpResponseForbidden("Forbidden operation.")
form = SettingsForm(data=request.POST or None,
initial={"email": user.email, "intro": user.get_profile().intro})
if request.method == "POST" and form.is_valid():
form.save(user)
return redirect(reverse("user_profile", kwargs={"user_id": user_id}))
return render(request, "settings.html",
{"form": form, "settings_user": user})
示例3: post
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def post(self):
args = self.request.arguments()
post_data = {}
for arg in args:
d = self.request.get(arg)
post_data[arg] = d
form = SettingsForm(post_data)
if form.is_valid():
form.save()
self.get(form=form)
示例4: edit_settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def edit_settings(request):
context = {}
settings = Settings.get_by_user(request.user)
if request.method == "POST":
form = SettingsForm(request.POST, instance=settings)
if form.is_valid():
form.save()
return HttpResponseRedirect("/settings")
else:
form = SettingsForm(instance=settings)
context["form"] = form
return r2r(request, "edit_settings", context)
示例5: settings_edit
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def settings_edit(request, response_format='html'):
"Settings"
if request.POST:
form = SettingsForm(request.user.profile, request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('changes_settings_view'))
else:
form = SettingsForm(request.user.profile)
context = _get_default_context(request)
context.update({'form': form})
return render_to_response('changes/settings_edit', context,
context_instance=RequestContext(request), response_format=response_format)
示例6: settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def settings(request):
context_vars = {}
context_vars.update(csrf(request))
if request.method == 'POST':
form = SettingsForm(request.POST, request.FILES, instance=request.user.profile)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('profile', kwargs={"username": request.user.username}))
else:
form = SettingsForm(instance=request.user.profile)
context_vars.update({'form': form})
template = 'settings.html'
context = RequestContext(request)
return render_to_response(template, context_vars, context_instance=context)
示例7: save_settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def save_settings(request, cid):
print 'update_settings request.method = %s' % request.method
if request.method == 'POST':
con = get_construct(request.user, cid)
if not con:
return JsonResponse({
'errors': {
'all':"Construct with id '%s' not found",
},} % cid, ERROR)
form = SettingsForm(request.POST, instance=con.settings)
if form.is_valid():
form.save()
con.reset()
data = {}
for key,value in form.cleaned_data.items():
data[key] = str(value);
return JsonResponse({'modified': con.last_modified(), 'fields': data})
return JsonResponse({'errors': form.errors,}, ERROR)
raise Http404
示例8: settings_edit
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def settings_edit(request, response_format='html'):
"Settings edit"
if request.POST:
if 'cancel' not in request.POST:
form = SettingsForm(
request.user.profile, request.POST, request.FILES)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('core_settings_view'))
else:
return HttpResponseRedirect(reverse('core_settings_view'))
else:
form = SettingsForm(request.user.profile)
return render_to_response('core/administration/settings_edit',
{
'form': form,
},
context_instance=RequestContext(request), response_format=response_format)
示例9: settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def settings(request):
settings_form = SettingsForm()
next = request.REQUEST.get('next')
if request.method == 'POST':
settings_form = SettingsForm(request.POST)
if settings_form.is_valid():
username = settings_form.save()
request.session['username'] = username
if next:
return HttpResponseRedirect(next)
return HttpResponseRedirect('/')
context = {
'settings_form': settings_form,
'next': next,
}
return render_to_response('settings.html', context,
context_instance=RequestContext(request))
示例10: cms_settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def cms_settings(request):
config = None
message = get_messages(request)
config = lookup_settings(request)
if request.method == 'POST':
form = SettingsForm(request.POST)
if form.is_valid():
email = request.user.email
delete_settings(email=email)
config = form.save()
config.email = request.user.email
config.save()
message = "Settings saved."
request.session['cms_email'] = config.email
return HttpResponseRedirect(settings.ROOT_URL+'options/')
else:
form = SettingsForm(instance=config)
return direct_to_template(request, 'settings.html',
{'config': config, 'message': message, 'form': form, })
示例11: render_settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import save [as 别名]
def render_settings(request):
user = User.objects.get(pk=request.user.id)
delete_account_request = False
try:
delete_request = DeleteAccountRequest.objects.filter(user=user).first()
if delete_request:
delete_account_request = True
except ObjectDoesNotExist:
delete_account_request = False
try:
settings = UserProfile.objects.get(user=user)
user_groups = user.groups.all()
group_list = []
for g in user_groups:
group_list.append({
'id': g.id,
'name': g.name,
'receive_updates': settings.get_group_notification_preference(g.id)
})
except UserProfile.DoesNotExist:
settings = None
if request.method == 'POST':
user_form = UserForm(request.POST, instance=user)
if settings:
settings_form = SettingsForm(request.POST, instance=settings)
else:
settings_form = SettingsForm(request.POST)
if user_form.is_valid() and settings_form.is_valid():
user = user_form.save()
settings = settings_form.save(commit=False)
settings.user_id = request.user.id
settings.save()
settings_form.save_m2m()
# update the interface language
if settings.interface_lang:
translation.activate(settings.interface_lang)
request.LANGUAGE_CODE = translation.get_language()
# get group update settings
for g in group_list:
gets_notif = True if request.POST.get('group_notif_' + str(g.get('id'))) else False
settings.set_group_notification_preference(g.get('id'), gets_notif)
g['receive_updates'] = gets_notif
# check for delete account requests
if request.POST.get('delete_account_option') == 'delete':
DeleteAccountRequest.objects.create(user=user)
delete_account_request = True
settings.set_active(False)
ctx = {
"user": user,
}
html = render_to_string('emails/delete_account_request.html', ctx)
email = EmailMessage('Delete user account request',
html,
constance.config.NO_REPLY_EMAIL,
[config.ACTIVATE_USER_EMAIL])
email.content_subtype = "html"
email.send()
else:
if delete_account_request:
DeleteAccountRequest.objects.filter(user=user).delete()
delete_account_request = False
settings.set_active(True)
messages.add_message(request, messages.SUCCESS, 'Profile Update Successful.')
else:
user_form = UserForm(instance=request.user)
settings_form = SettingsForm(instance=settings)
errors = dict(user_form.errors)
errors.update(settings_form.errors)
interest_types = {'languages': [(lang.id, lang.name) for lang in Language.objects.all()],
'interests': [(interest.id, interest.name) for interest in Interest.objects.all()],
'regions': [(region.id, region.name) for region in Region.objects.all()]}
return render_to_response('users/user_settings_v2.html',
{
'settings_form': settings_form,
'user_form': user_form,
'group_list': group_list,
'interest_types': interest_types,
'has_password': user.has_usable_password(),
'errors': errors,
'delete_account_request': delete_account_request,
},
context_instance=RequestContext(request))