本文整理汇总了Python中forms.SettingsForm类的典型用法代码示例。如果您正苦于以下问题:Python SettingsForm类的具体用法?Python SettingsForm怎么用?Python SettingsForm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SettingsForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: settings_form
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))
示例2: user_settings
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),
})
示例3: settings
def settings(_id):
# Authentication
if current_user.id != _id and not current_user.is_admin():
flash("You are not authorised to edit user {}'s settings.".format(_id), "danger")
return redirect(request.referrer or url_for("index"))
# Check user exists
_user = User.query.filter(User.id == _id).first()
if _user is None:
flash("User {} not found.".format(_id), "danger")
return redirect(request.referrer or url_for("index"))
# Validate form, if submitted; else render it.
form = SettingsForm(_user, request.form)
if form.validate_on_submit():
_user.email = form.email.data
_user.show_ads = form.show_ads.data
db.session.add(_user)
db.session.commit()
return redirect(request.args.get("next") or url_for("users.user", _id=_user.id))
return render_template("users/settings.html",
title="Your settings - Dotabank",
user=_user,
form=form)
示例4: settings
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})
示例5: settings
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})
示例6: settings
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})
示例7: post
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)
示例8: settings
def settings():
global config
# we need getattr for WTF
formdata = namedtuple('Struct', config.keys())(*config.values())
form = SettingsForm(obj=formdata, bait_session_retain=config['bait_session_retain'])
if form.validate_on_submit():
# the potential updates that we want to save to config file.
options = {'bait_session_retain': form.bait_session_retain.data,
'malicious_session_retain': form.malicious_session_retain.data,
'ignore_failed_bait_session': form.ignore_failed_bait_session.data}
update_config(options)
return render_template('settings.html', form=form, user=current_user)
示例9: edit_settings
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)
示例10: settings
def settings():
global config
form = SettingsForm(obj=MultiDict(config))
if form.validate_on_submit():
# the potential updates that we want to save to config file.
options = {'honeybee_session_retain': form.honeybee_session_retain.data,
'malicious_session_retain': form.malicious_session_retain.data,
'ignore_failed_honeybees': form.ignore_failed_honeybees.data}
update_config_file(app.config['BEEKEEPER_CONFIG'], options)
# update the global config dict.
config = get_config_dict(app.config['BEEKEEPER_CONFIG'])
return render_template('settings.html', form=form, user=current_user)
示例11: settings
def settings():
bait_session_retain = send_config_request('{0} {1}'.format(Messages.GET_CONFIG_ITEM, 'bait_session_retain'))
ignore_failed_bait_session = ast.literal_eval(send_config_request('{0} {1}'.format(Messages.GET_CONFIG_ITEM, 'ignore_failed_bait_session')))
malicious_session_retain = send_config_request('{0} {1}'.format(Messages.GET_CONFIG_ITEM, 'malicious_session_retain'))
form = SettingsForm(bait_session_retain=bait_session_retain, malicious_session_retain=malicious_session_retain,
ignore_failed_bait_session=ignore_failed_bait_session)
if form.validate_on_submit():
# the potential updates that we want to save to config file.
options = {'bait_session_retain': form.bait_session_retain.data,
'malicious_session_retain': form.malicious_session_retain.data,
'ignore_failed_bait_session': form.ignore_failed_bait_session.data}
send_config_request('{0} {1}'.format(Messages.SET_CONFIG_ITEM, json.dumps(options)))
return render_template('settings.html', form=form, user=current_user)
示例12: settings
def settings():
form = SettingsForm()
if form.validate_on_submit():
pass # TODO - Make this actually do something
elif request.method is not 'POST':
form.username.data = g.user.username
form.email.data = g.user.email
form.gender.data = g.user.gender # FIXME - Currently doesn't fill in radio button
form.location.data = g.user.location
form.about.data = g.user.about
return render_template(
'settings.html',
form=form
)
示例13: settings
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))
示例14: settings
def settings():
pw_form = PasswordChangeForm()
set_form = SettingsForm()
if 'pw_change' in request.form and pw_form.validate_on_submit():
try:
g.user.set_password(pw_form.new_password.data)
db.session.commit()
flash(u'Passwort wurde geändert.')
except:
flash(u'Passwort konnte nicht geändert werden.')
if 'settings_change' in request.form and set_form.validate_on_submit():
g.user.name = set_form.name.data
db.session.commit()
flash(u'Einstellungen wurde geändert.')
return render_template('user/settings.html', pw_form=pw_form, set_form=set_form)
示例15: profile
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})