本文整理汇总了Python中forms.SettingsForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python SettingsForm.is_valid方法的具体用法?Python SettingsForm.is_valid怎么用?Python SettingsForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.SettingsForm
的用法示例。
在下文中一共展示了SettingsForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [as 别名]
def user_settings(request):
if request.method == 'POST':
form = SettingsForm(request.POST, request.FILES)
if form.is_valid():
im = Image.open(request.FILES['profile_pic'])
im = ImageOps.fit(im, (120, 120), Image.ANTIALIAS)
if not os.path.exists(os.path.join(settings.MEDIA_ROOT, "profile")):
os.makedirs(os.path.join(settings.MEDIA_ROOT, "profile"))
im.save(os.path.join(settings.MEDIA_ROOT, "profile/{}.png".format(request.user.netid)))
request.user.photo = "png"
request.user.save()
messages.success(request, 'Votre profil a été mis à jour.')
return render(request, "users/settings.html", {'form': SettingsForm()})
else:
form = SettingsForm()
return render(request, 'users/settings.html', {
'form': form,
'stream': actor_stream(request.user),
})
示例2: settings_form
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [as 别名]
def settings_form( request, template = 'settings_form.html' ):
context = {}
user = request.user
if request.method == 'POST':
form = SettingsForm(request.POST.copy())
if form.is_valid():
# Cycle through the settings and save them
data = form.cleaned_data
for setting in USER_SETTINGS:
name = setting['name']
set_setting(user, name, data[name])
context['saved'] = True
else:
# Read user settings and build the form
settings = {}
for setting in USER_SETTINGS:
name = setting['name']
settings[name] = get_setting(user, name)
form = SettingsForm(settings)
context['form'] = form
return render_to_response(template,
context, context_instance=RequestContext(request))
示例3: settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [as 别名]
def settings(request):
if request.method == "POST":
form = SettingsForm(request.POST)
if form.is_valid():
request.user.topic_set = form.cleaned_data["topics"]
return HttpResponseRedirect("/")
else:
form = SettingsForm()
return render(request, "settings.html", {"form": form})
示例4: settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [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})
示例5: settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [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})
示例6: post
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [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)
示例7: edit_settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [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)
示例8: settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [as 别名]
def settings(request):
if request.method == 'POST':
form = SettingsForm(request.POST)
if form.is_valid():
try:
Alert.objects.get(user=request.user).delete()
except:
pass
data = form.cleaned_data
client_t = data['user_time']
server_t = datetime.now().strftime('%H')
tz_diff = int(server_t) - int(client_t)
as_time = datetime(2013, 1, 1, data['time'].hour, data['time'].minute)
as_time = as_time + timedelta(hours=tz_diff)
a = Alert(
user=request.user,
alert_server_time=as_time,
start=data['start'],
finish=data['finish'],
period=data['period'],
time=data['time'],
alert_email=data['alert_email'],
email=data['email'],
alert_sms=data['alert_sms'],
phone=data['phone']
)
alert = {}
try:
a.save()
alert['txt'] = 'Настройки сохранены'
alert['cls'] = 'alert-success'
except:
alert['txt'] = 'Не удалось сохранить настройки, попробуйте повторить позже'
alert['cls'] = 'alert-danger'
return render_to_response('settings.html', {'form': form, 'alert': alert}, RequestContext(request))
else:
try:
a = Alert.objects.get(user=request.user)
form = SettingsForm(instance=a)
except:
form = SettingsForm()
return render_to_response('settings.html', {'form': form}, RequestContext(request))
示例9: profile
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [as 别名]
def profile(request):
if request.method == 'POST':
form = SettingsForm(request.POST, request.FILES)
if form.is_valid():
if request.user.check_password(request.POST['old_pass']):
if request.POST['username'] != '':
request.user.username = request.POST['username']
if request.POST['email'] != '':
request.user.email = request.POST['email']
if request.POST['pass_new'] != '':
request.user.password = request.POST['pass_new']
request.user.set_password(request.user.password)
request.user.save()
return home(request)
form = SettingsForm()
return render(request, 'external/profile.html', {'form': form})
示例10: settings_edit
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [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)
示例11: settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [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)
示例12: settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [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))
示例13: save_settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [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
示例14: update_settings
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [as 别名]
def update_settings(request):
if request.method == 'POST':
form = SettingsForm(request.POST)
if form.is_valid():
show_on_rankings = form.cleaned_data['show_on_rankings']
user = UserProfile.objects.get(user = request.user)
if show_on_rankings:
user.show_on_rankings = True
else:
user.show_on_rankings = False
user.save()
messages.add_message(request, messages.SUCCESS, 'Your profile has been successfully updated.')
else:
messages.add_message(request, messages.ERROR, message = 'Error occured when trying to update your settings.')
return render_to_response('other/message.html', {}, context_instance = RequestContext(request))
示例15: settings_edit
# 需要导入模块: from forms import SettingsForm [as 别名]
# 或者: from forms.SettingsForm import is_valid [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)