Create new project
This commit is contained in:
parent
7c21e64c51
commit
5203690748
@ -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
|
||||
|
9
atst/forms/new_project.py
Normal file
9
atst/forms/new_project.py
Normal file
@ -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")
|
@ -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/<workspace_id>/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/<workspace_id>/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/<workspace_id>/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)
|
||||
)
|
||||
|
@ -1,8 +1,42 @@
|
||||
{% from "components/icon.html" import Icon %}
|
||||
{% from "components/text_input.html" import TextInput %}
|
||||
|
||||
{% extends "base_workspace.html" %}
|
||||
|
||||
{% block workspace_content %}
|
||||
<h1>Add a new project</h1>
|
||||
<form method="POST" action="{{ url_for('workspaces.update_project', workspace_id=workspace.id) }}" >
|
||||
{{ form.csrf_token }}
|
||||
<div class="panel">
|
||||
<div class="panel__heading">
|
||||
<h1>Add a new project</h1>
|
||||
</div>
|
||||
|
||||
<div class="panel__content">
|
||||
{{ TextInput(form.name) }}
|
||||
{{ TextInput(form.description, paragraph=True) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<div class="block-list project-list-item">
|
||||
<header class="block-list__header">
|
||||
<h3 class="block-list__title">Project Environments</h3>
|
||||
</header>
|
||||
|
||||
<ul>
|
||||
<li class="block-list__item">
|
||||
<span class="project-list-item__environment">
|
||||
{{ TextInput(form.environment_name) }}
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="action-group">
|
||||
<input type="submit" value="Create Project" class="action-group__action usa-button usa-button-big">
|
||||
<!-- <a href="/styleguide" class="action-group__action">Cancel</a> -->
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user