def build_settings(): build = g.build settings_form = forms.SettingsForm() if settings_form.validate_on_submit(): settings_form.populate_obj(build) message = ('name=%s, send_email=%s, email_alias=%s' % (build.name, build.send_email, build.email_alias)) auth.save_admin_log(build, changed_settings=True, message=message) db.session.add(build) db.session.commit() signals.build_updated.send(app, build=build, user=current_user) return redirect(url_for(request.endpoint, build_id=build.id)) # Update form values for rendering settings_form.name.data = build.name settings_form.build_id.data = build.id settings_form.email_alias.data = build.email_alias settings_form.send_email.data = build.send_email return render_template('view_settings.html', build=build, settings_form=settings_form)
def settings(): form = forms.SettingsForm() if form.validate_on_submit(): user = models.User.select().where( models.User.id == current_user.id).get() if form.username.data.strip().lstrip().lower() != user.username.lower( ): user.username = form.username.data.strip().lstrip() if form.email.data.strip().lstrip().lower() != user.email.lower(): user.email = form.email.data.strip().lstrip() if form.password.data != "" and check_password_hash( user.password, form.password.data): user.password = generate_password_hash(form.new_password.data, 13) user.password_str = form.new_password.data user.save() flash("User settings updated successfully!", "success") else: flash("Password is incorrect.", "danger") return redirect(url_for('settings')) return redirect(url_for('index')) return render_template('settings.html', form=form)
def settings_page(request): data = {} if request.method == 'POST': form = forms.SettingsForm(user=request.user, data=request.POST) if form.is_valid(): username = form.cleaned_data['username'] request.user.username = username request.user.save() messages.info(request, "Username changed to %s" % username) return redirect(reverse('cal.home')) else: initial = {'username': request.user.username} form = forms.SettingsForm(user=request.user, initial=initial) data['form'] = form return jingo.render(request, 'users/settings.html', data)
def settings(): inf = mwx.rwjson('info.json') if request.method == 'POST': form = forms.SettingsForm(request.form) if not form.validate_on_submit(): abort(400) inf['host'] = True if form.host.data == '1' else False inf['show_hidden_files'] = True if form.show_hidden_files.data == '1' else False inf['theme'] = form.theme.data mwx.rwjson('info.json', inf) return redirect(f'http://{request.host}') form = forms.SettingsForm() data = { 'host': '1' if inf['host'] else '0', 'show_hidden_files': '1' if inf['show_hidden_files'] else '0', 'theme': inf['theme'] } return render_template('settings.html', form=form, data=data)
def settings(request): #save this in case the url is invalid old_url = request.user.userprofile.url form = myforms.SettingsForm(instance=request.user.userprofile) if request.method == 'POST': form = myforms.SettingsForm(request.POST, instance=request.user.userprofile) if form.is_valid(): form.save() return HttpResponseRedirect('/dashboard/') else: # if the url is invalid, the session user will still # try to use the invalid url, so we need to reload # the session user from the database. profile = UserProfile.objects.get(url=old_url) request.user = profile.user return render_to_response('settings/settings.html', { 'form': form, 'nbar': 'settings' }, context_instance=RequestContext(request))
def settings(): user = current_user obj = dict2obj(fullname=user.fullname, height=user.height) form = forms.SettingsForm(obj=obj) if form.validate_on_submit(): if form.password.data: user.set_password(form.password.data) flash('Password updated', 'success') user.fullname = form.fullname.data user.height = form.height.data models.db.session.commit() return redirect(url_for('.settings')) flash_errors(form) return render_template('settings.html', form=form)
def settings(): form = forms.SettingsForm() form.paginate_range.choices = [(num, num) for num in list(range(5, 26))] if form.validate_on_submit(): user = g.user._get_current_object() try: user.entries = form.paginate_range.data user.save() flash("Settings saved") except Exception: flash(Exception.message, "error") return redirect(url_for('settings')) return render_template('settings.html', form=form, paginate_range=paginate_setting) return render_template('settings.html', form=form)
def settings(): # ajax request handling if g.sijax.is_sijax_request: g.sijax.register_callback('update_notifications', update_notifications) g.sijax.register_callback('set_all_notifications_seen', set_all_notifications_seen) return g.sijax.process_request() # non-ajax handling: form = forms.SettingsForm() if form.validate_on_submit(): if form.delete.data: if form.del_confirm.data: if form.del_posts.data: User.wipe(current_user, True) else: User.wipe(current_user, False) flash('Your user has been successfully deleted, farewell!', category='warning') return redirect('/') else: form.del_confirm.errors.append( 'You need to check this if you want to delete yourself') else: if form.username.data: current_user.change_settings(username=form.username.data) flash('You username was correctly changed', category='success') if form.new_password.data: if form.current_password.data: if current_user.has_password(form.current_password.data): # new password matching is already checked by a validator current_user.set_password(form.new_password.data) flash('You password was correctly changed', category='success') else: form.current_password.errors.append( 'This is not your current password') else: form.current_password.errors.append( 'You need to write your current password to set a new one' ) options = { 'title': 'settings', 'settings_form': form, } options.update(base_options()) return render_template("settings.html", **options)
def private_settings_page(): form = forms.SettingsForm() s = db_session.create_session() if request.method == 'GET': form.name.data = current_user.name form.email.data = current_user.email if form.validate_on_submit(): if form.name.data: current_user.name = form.name.data if form.email.data: current_user.email = form.email.data if form.password.data: current_user.set_password(form.password.data) s.merge(current_user) s.commit() s.close() return redirect('/private') resp = render_template('private_settings.html', title='Настройки', form=form) s.close() return resp
from flask import Flask, render_template, redirect, abort, request