diff --git a/src/app/templates/apply.html b/src/app/templates/apply.html index 2f7704a..c1c4f7a 100644 --- a/src/app/templates/apply.html +++ b/src/app/templates/apply.html @@ -22,7 +22,7 @@ $def with (nav, apply_form, project, applicants)
diff --git a/src/app/views/apply.py b/src/app/views/apply.py index d4b948c..9815489 100644 --- a/src/app/views/apply.py +++ b/src/app/views/apply.py @@ -19,19 +19,17 @@ class Apply: data = web.input(projectid=0) if data.projectid: project = models.project.get_project_by_id(data.projectid) - #tasks = models.project.get_tasks_by_project_id(data.projectid) else: project = [[]] tasks = [[]] - #render = web.template.render('templates/', globals={'get_task_files':models.project.get_task_files, 'session':session}) - #render_project = render.project(nav, project[0], tasks) + user_dropdown = get_user_dropdown() apply_form = get_apply_form(user_dropdown) applicants = [[session.userid, session.username]] return render.apply(nav, apply_form, project, applicants) def POST(self): - data = web.input(projectid=0) + data = web.input(projectid=0, add_user=None, remove_user=None, apply=None) session = web.ctx.session nav = get_nav_bar(session) applicants = [session.username] @@ -41,29 +39,22 @@ class Apply: print(data) if data.projectid: project = models.project.get_project_by_id(data.projectid) - try: - if data["Add User"]: - #project_form = self.compose_form(data, "add_user") - applicants = self.get_applicants(data, "add_user") - return render.apply(nav, apply_form, project, applicants) - except Exception as e: - try: - if data["Remove User"]: - #project_form = self.compose_form(data, "remove_user") + + if data.add_user: + applicants = self.get_applicants(data, "add_user") + return render.apply(nav, apply_form, project, applicants) + + elif data.remove_user: applicants = self.get_applicants(data, "remove_user") return render.apply(nav, apply_form, project, applicants) - except Exception as e: - try: - if data["Apply"]: - applicants = self.get_applicants(data, "") - for applicant in applicants: - print("Add", applicant, data.projectid) - models.project.set_projects_user(data.projectid, str(applicant[0]), "TRUE", "TRUE", "FALSE") - models.project.update_project_status(data.projectid, "in progress") - raise web.seeother(('/project?projectid=' + str(data.projectid))) - except Exception as e: - raise - + + elif data.apply: + applicants = self.get_applicants(data, "") + for applicant in applicants: + models.project.set_projects_user(data.projectid, str(applicant[0]), "TRUE", "TRUE", "FALSE") + models.project.update_project_status(data.projectid, "in progress") + raise web.seeother(('/project?projectid=' + str(data.projectid))) + def get_applicants(self, data, operation): print(operation) print(data) @@ -77,7 +68,7 @@ class Apply: if operation == "remove_user": print("remove") - user_to_remove = data["Remove User"][1:][:-1].split(",") + user_to_remove = data.remove_user[1:][:-1].split(",") user_to_remove = [int(user_to_remove[0]), user_to_remove[1][2:][:-1]] for i in range (0, user_count): print(user_to_remove, applicants[i]) diff --git a/src/app/views/forms.py b/src/app/views/forms.py index b60c0c2..956683a 100644 --- a/src/app/views/forms.py +++ b/src/app/views/forms.py @@ -102,18 +102,20 @@ project_buttons = form.Form( def get_apply_form(elements): try: apply_form = form.Form(*elements, - form.Button("Add User", type="submit", description="Add User", value="add_user"), - form.Button("Remove User", type="submit", description="Remove User", value="remove_user"), - form.Button("Apply", type="submit", description="Apply", value="apply") + form.Button("add_user", type="submit", description="Add User", value="add_user", html="Add User"), + form.Button("apply", type="submit", description="Apply", value="apply", html="apply") ) # Exception will occur if the form only contains one element except TypeError as e: apply_form = form.Form(elements, - form.Button("Add User", type="submit", description="Add User", value="add_user"), - form.Button("Apply", type="submit", description="Apply", value="apply") + form.Button("add_user", type="submit", description="Add User", value="add_user", html="Add User"), + form.Button("apply", type="submit", description="Apply", value="apply", html="apply") ) return apply_form def get_user_dropdown(identifier=0): users = get_users() + #form.Checkbox("read_permission_" + str(identifier), description="Read Permission", checked=read_permission, value=True), + #form.Checkbox("write_permission_" + str(identifier), description="Write Permission", checked=write_permission, value=True), + #form.Checkbox("modify_permission_" + str(identifier), description="Modify Permission", checked=modify_permission, value=True) return form.Dropdown("user_id_" + str(identifier), description="User", args=users)