def configuration_page(request, template='configuration.html'): if request.method == 'POST': configuration_form = ConfigurationForm(request.POST) if configuration_form.is_valid(): set_session_with_attributes(configuration_form, request) return HttpResponseRedirect('/getbuilds/') else: configuration_form = ConfigurationForm() return render(request, template, {'configuration_form': configuration_form, })
def updateConfiguration(request, key): if not admin(): return HttpResponseRedirect(users.create_login_Configuration('/blogs')) form = ConfigurationForm(request.POST) if form.is_valid(): configuration = Configuration.get(key) configuration.title = form.cleaned_data['title'] configuration.motto = form.cleaned_data['motto'] configuration.put() return HttpResponseRedirect('/blogs') else: return editConfiguration(request, key)
def edit_configuration(id): qry = db_session.query(Configuration).filter(Configuration.id==id) configuration = qry.first() if configuration: form = ConfigurationForm(formdata=request.form, obj=configuration) if request.method == 'POST' and form.validate(): save_changes_configuration(configuration, form) return redirect('/configurations') return render_template('edit_configuration.html', form=form) else: return 'Error loading #{id}'.format(id=id)
def createConfiguration(request): if not admin(): return HttpResponseRedirect(users.create_login_Configuration("/blogs")) form = ConfigurationForm(request.POST) if form.is_valid(): configuration = Configuration() configuration.title = form.cleaned_data["title"] configuration.motto = form.cleaned_data["motto"] configuration.pagesize = form.cleaned_data["pagesize"] configuration.put() return HttpResponseRedirect("/blogs") else: return newConfiguration(request)
def build_project(request, object_id): project = get_object_or_404(Project, id=object_id) if project.project_builder == PROJECT_BUILDER_DJANGO: # Create variables builder = DjangoBuilder(project) if request.method == 'POST': form = ConfigurationForm(project, request.POST) if form.is_valid(): builder.build() return TemplateResponse(request, 'core/build_success.html', {'project': project}) else: form = ConfigurationForm(project) return TemplateResponse(request, 'core/build.html', {'form': form, 'project': project})
def create_conf(): form = ConfigurationForm(request.form) if request.method == 'POST' and form.validate(): try: configuration = Configuration() form.populate_obj(configuration) db.session.add(configuration) db.session.commit() return redirect(url_for('conf', id=configuration.id)) except Exception as error: flash("Error creating configuration.", category="danger") app.logger.error("Error creating configuration {}\n{}".format( error, traceback.format_exc())) return render_template('forms/model.jinja', form=form, action=url_for('create_conf'), section='other')
def settings(): form = ConfigurationForm(obj=config) if form.validate_on_submit(): # auth__admin is special, because it needs to be hashed before being # passed to the config and saved auth__admin = form.auth__admin.data form.auth__admin.data = None form.populate_obj(config) if auth__admin: config.auth__admin = hash_pwd(auth__admin) config.save() flash("Settings successfully updated") return redirect(url_for("settings")) # No need to present a hash digest to the user :) form.auth__admin.data = None return render_template("settings.html", form=form)
def new_configuration(): """ Add a new album """ form = ConfigurationForm(request.form) if request.method == 'POST': # save the album configuration = Configuration() save_changes_configuration(configuration, form, new=True) return redirect('/configurations') return render_template('new_configuration.html', form=form)
def edit_conf(id): conf = Configuration.query.get(id) form = ConfigurationForm(obj=conf) if request.method == 'POST': try: form = ConfigurationForm(request.form, obj=conf) if form.validate(): form.populate_obj(conf) db.session.commit() flash("Stillingum var breytt", category='success') return redirect(url_for("conf", id=conf.id)) except Exception as error: app.logger.error('Error updating a configuration : {}\n{}'.format( error, traceback.format_exc())) return render_template('forms/model.jinja', form=form, type='edit', action=url_for('edit_conf', id=id), section='other')