From 1d41b5a96568d98853656de546b85df8b2358750 Mon Sep 17 00:00:00 2001 From: jakobsn Date: Wed, 13 Nov 2019 16:41:39 +0100 Subject: [PATCH] My projects complete --- src/app/views/new_project.py | 43 ++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/app/views/new_project.py b/src/app/views/new_project.py index a6cbc3c..bb4dab0 100644 --- a/src/app/views/new_project.py +++ b/src/app/views/new_project.py @@ -60,33 +60,44 @@ class New_project: try: # Post the form data and save the project in the database if data["Create Project"]: - projectid = models.project.set_project(data.category_name, str(session.userid), - data.project_title, data.project_description, "open") task_count = self.get_task_count(data) user_count = self.get_user_count(data) + + # Get the "real" user_count, if there is only one field and no users assigned the project is open + if user_count > 0: + if len(data.user_name_0): + status = "in progress" + else: + status = "open" + else: + status = "open" + projectid = models.project.set_project(data.category_name, str(session.userid), + data.project_title, data.project_description, status) + # Save the tasks in the database for i in range(0, task_count): models.project.set_task(str(projectid), (data["task_title_" + str(i)]), (data["task_description_" + str(i)]), (data["budget_" + str(i)])) for i in range(0, user_count): - userid = models.login.get_user_id_by_name(data["user_name_"+str(i)]) - read, write, modify = "FALSE", "FALSE", "FALSE" - try: - if data["read_permission_"+str(i)]: - read = "TRUE" - except Exception as e: + if len(data["user_name_"+str(i)]): + userid = models.login.get_user_id_by_name(data["user_name_"+str(i)]) + read, write, modify = "FALSE", "FALSE", "FALSE" try: - if data["write_permission_"+str(i)]: - write = "TRUE" + if data["read_permission_"+str(i)]: + read = "TRUE" except Exception as e: try: - if data["modify_permission_"+str(i)]: - modify = "TRUE" + if data["write_permission_"+str(i)]: + write = "TRUE" except Exception as e: - # This error will be raised if no permission is set - raise e - models.project.set_projects_user(str(projectid), str(userid), read, write, modify) - raise web.seeother('/') + try: + if data["modify_permission_"+str(i)]: + modify = "TRUE" + except Exception as e: + # This error will be raised if no permission is set + raise e + models.project.set_projects_user(str(projectid), str(userid), read, write, modify) + raise web.seeother('/') except Exception as e: raise e