diff --git a/atst/domain/workspaces.py b/atst/domain/workspaces.py index 0fedcc05..985447f0 100644 --- a/atst/domain/workspaces.py +++ b/atst/domain/workspaces.py @@ -4,6 +4,7 @@ from atst.database import db from atst.models.workspace import Workspace from atst.models.workspace_role import WorkspaceRole from atst.models.project import Project +from atst.models.environment import Environment from atst.domain.exceptions import NotFoundError, UnauthorizedError from atst.domain.roles import Roles @@ -72,6 +73,15 @@ class Projects(object): return project +class Environments(object): + @classmethod + def create(cls, project, name): + environment = Environment(project=project, name=name) + db.session.add(environment) + db.session.commit() + return environment + + class Members(object): def __init__(self): pass diff --git a/atst/forms/new_project.py b/atst/forms/new_project.py new file mode 100644 index 00000000..1552a1ab --- /dev/null +++ b/atst/forms/new_project.py @@ -0,0 +1,9 @@ +from flask_wtf import Form +from wtforms.fields import StringField, TextAreaField + + +class NewProjectForm(Form): + + name = StringField(label="Project Name") + description = TextAreaField(label="Description") + environment_name = StringField(label="Environment Name") diff --git a/atst/routes/workspaces.py b/atst/routes/workspaces.py index 3dd193de..3cee0fab 100644 --- a/atst/routes/workspaces.py +++ b/atst/routes/workspaces.py @@ -1,6 +1,7 @@ -from flask import Blueprint, render_template, request as http_request, g +from flask import Blueprint, render_template, request as http_request, g, redirect, url_for -from atst.domain.workspaces import Workspaces, Members +from atst.domain.workspaces import Workspaces, Members, Projects, Environments +from atst.forms.new_project import NewProjectForm bp = Blueprint("workspaces", __name__) @@ -36,4 +37,27 @@ def workspace_members(workspace_id): @bp.route("/workspaces//reports") def workspace_reports(workspace_id): - return render_template("workspace_reports.html") + return render_template("workspace_reports.html", workspace_id=workspace_id) + + +@bp.route("/workspaces//projects/new") +def new_project(workspace_id): + workspace = Workspaces.get(g.current_user, workspace_id) + form = NewProjectForm() + return render_template("workspace_project_new.html", workspace=workspace, form=form) + + +@bp.route("/workspaces//projects", methods=["POST"]) +def update_project(workspace_id): + workspace = Workspaces.get(g.current_user, workspace_id) + form = NewProjectForm(request.form) + + if form.validate(): + project_data = form.data + project = Projects.create( + workspace, project_data["name"], project_data["description"] + ) + Environments.create(project, project_data["environment_name"]) + return redirect( + url_for("workspaces.workspace_projects", workspace_id=workspace.id) + ) diff --git a/templates/workspace_project_new.html b/templates/workspace_project_new.html index 0996946d..5fdfe042 100644 --- a/templates/workspace_project_new.html +++ b/templates/workspace_project_new.html @@ -1,8 +1,42 @@ {% from "components/icon.html" import Icon %} +{% from "components/text_input.html" import TextInput %} {% extends "base_workspace.html" %} {% block workspace_content %} -

Add a new project

+
+ {{ form.csrf_token }} +
+
+

Add a new project

+
+ +
+ {{ TextInput(form.name) }} + {{ TextInput(form.description, paragraph=True) }} +
+
+ +
+
+
+

Project Environments

+
+ +
    +
  • + + {{ TextInput(form.environment_name) }} + +
  • +
+
+
+ +
+ + +
+
{% endblock %}