def create_project(): form = StartProjectForm() if form.validate_on_submit(): if Project.find_by_title(form.title.data, current_user.user_id) == None: project = Project(title = form.title.data, description = form.description.data, user_id = current_user.user_id) project.save_to_db() return redirect(url_for("projects.overview", title=project.title)) return render_template("projects/create.html", form=form, action="create")
def add_project_comment(project_title): form = AddCommentForm() if form.validate_on_submit(): project = Project.find_by_title(project_title, current_user.user_id) comment = ProjectComment(project.project_id, current_user.user_id, form.comment.data) comment.save_to_db() return redirect(url_for("projects.overview", title=project_title)) return render_template("comments/add.html", form=form, title=project_title, action="create")
def update(title): form = StartProjectForm() form.submit.label.text = "Update" project = Project.find_by_title(title, current_user.user_id) if form.validate_on_submit(): project.title = form.title.data project.description = form.description.data project.save_to_db() return redirect(url_for("projects.overview", title=project.title)) elif request.method == "GET": form.title.data = title form.description.data = project.description return render_template("projects/create.html", form=form, action="update")
def test_project(self): self.create_user(user_name="testuser", email="*****@*****.**", password="******") user = User.query.filter_by(user_name="testuser").first() self.create_project(title="test_project", description="A test project", user_id=user.get_id()) self.create_project(title="test_project2", description="Another test project", user_id=user.get_id()) project = Project.find_by_title("test_project", 1) self.assertEquals(project.project_id, 1) self.assertEquals(project.description, "A test project") self.assertEquals(project.status_id, 1)
def add_task(project_title): form = AddTaskForm() if form.validate_on_submit(): if Task.find_by_title(form.title.data, current_user.user_id) == None: project = Project.find_by_title(project_title, current_user.user_id) task = Task(title=form.title.data, description=form.description.data, project_id=project.project_id, user_id=current_user.user_id) task.save_to_db() return redirect(url_for("tasks.overview", title=task.title)) return render_template("tasks/add.html", form=form, project_title=project_title, action="create")
def create_project(self, title, description, user_id): project = Project(title=title, description=description, user_id=user_id) project.save_to_db()
def delete(title): project = Project.find_by_title(title, current_user.user_id) project.delete() return redirect(url_for("users.home"))
def overview(title): project = Project.find_by_title(title, current_user.user_id) return render_template("projects/overview.html", project=project)