def new_environment(application_id): application = Applications.get(application_id) env_form = EditEnvironmentForm(formdata=http_request.form) if env_form.validate(): Environments.create(g.current_user, application=application, name=env_form.name.data) flash("environment_added", environment_name=env_form.data["name"]) return redirect( url_for( "applications.settings", application_id=application.id, fragment="application-environments", _anchor="application-environments", )) else: return (render_settings_page(application=application), 400)
def handle_update_environment(form, application=None, environment=None): if form.validate(): try: if environment: environment = Environments.update(environment=environment, name=form.name.data) flash("application_environments_updated") else: environment = Environments.create(g.current_user, application=application, name=form.name.data) flash("environment_added", environment_name=form.name.data) return environment except AlreadyExistsError: flash("application_environments_name_error", name=form.name.data) return False else: return False