def update_environment(environment_id): environment = Environments.get(environment_id) application = environment.application env_form = EditEnvironmentForm(obj=environment, formdata=http_request.form) if env_form.validate(): Environments.update(environment=environment, name=env_form.name.data) flash("application_environments_updated") return redirect( url_for( "applications.settings", application_id=application.id, fragment="application-environments", _anchor="application-environments", active_toggler=environment.id, active_toggler_section="edit", )) else: return ( render_settings_page( application=application, active_toggler=environment.id, active_toggler_section="edit", ), 400, )
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 get_environments_obj_for_app(application): environments_obj = [] for env in application.environments: env_data = { "id": env.id, "name": env.name, "pending": env.is_pending, "edit_form": EditEnvironmentForm(obj=env), "member_count": len(env.roles), "members": [env_role.application_role.user_name for env_role in env.roles], } environments_obj.append(env_data) return environments_obj
def new_environment(application_id): application = Applications.get(application_id) env_form = EditEnvironmentForm(formdata=http_request.form) environment = handle_update_environment(form=env_form, application=application) if environment: return redirect( url_for( "applications.settings", application_id=application.id, fragment="application-environments", _anchor="application-environments", )) else: return (render_settings_page(application=application, show_flash=True), 400)
def update_environment(environment_id): environment = Environments.get(environment_id) application = environment.application env_form = EditEnvironmentForm(obj=environment, formdata=http_request.form) updated_environment = handle_update_environment(form=env_form, application=application, environment=environment) if updated_environment: return redirect( url_for( "applications.settings", application_id=application.id, fragment="application-environments", _anchor="application-environments", )) else: return (render_settings_page(application=application, show_flash=True), 400)
def render_settings_page(application, **kwargs): environments_obj = get_environments_obj_for_app(application=application) new_env_form = EditEnvironmentForm() pagination_opts = Paginator.get_pagination_opts(http_request) audit_events = AuditLog.get_application_events(application, pagination_opts) new_member_form = get_new_member_form(application) members = get_members_data(application) if "application_form" not in kwargs: kwargs["application_form"] = NameAndDescriptionForm( name=application.name, description=application.description) return render_template( "applications/settings.html", application=application, environments_obj=environments_obj, new_env_form=new_env_form, audit_events=audit_events, new_member_form=new_member_form, members=members, **kwargs, )
def get_environments_obj_for_app(application): return sorted( [{ "id": env.id, "name": env.name, "pending": env.is_pending, "edit_form": EditEnvironmentForm(obj=env), "member_count": len(env.roles), "members": sorted( [{ "user_name": env_role.application_role.user_name, "status": env_role.status.value, } for env_role in env.roles], key=lambda env_role: env_role["user_name"], ), } for env in application.environments], key=lambda env: env["name"], )