| @@ -52,7 +52,7 @@ def get_project_by_id(projectid): | |||||
| projectid + "\"") | projectid + "\"") | ||||
| cursor.execute(query) | cursor.execute(query) | ||||
| project = cursor.fetchall() | project = cursor.fetchall() | ||||
| return project | |||||
| return project[0] | |||||
| def get_projects_by_status_and_category(categoryid, project_status): | def get_projects_by_status_and_category(categoryid, project_status): | ||||
| """ | """ | ||||
| @@ -20,7 +20,7 @@ $def with (nav, categories, open_projects) | |||||
| <div class="projects"> | <div class="projects"> | ||||
| $for project in open_projects: | $for project in open_projects: | ||||
| <div class="project" onclick="location.href='/apply?projectid=$project[0]'"><h4>$project[3]</h4><p>$project[4]</p></div> | |||||
| <div class="project" onclick="location.href='/project?projectid=$project[0]'"><h4>$project[3]</h4><p>$project[4]</p></div> | |||||
| </div> | </div> | ||||
| <img src="static/honeybee.png" alt="Honeybee"> | <img src="static/honeybee.png" alt="Honeybee"> | ||||
| @@ -34,6 +34,9 @@ $def with (nav, project, tasks) | |||||
| </li> | </li> | ||||
| </ul> | </ul> | ||||
| $if project[5] == "open" and session.userid != project[2]: | |||||
| <div id="apply" onclick="location.href='/apply?projectid=$project[0]'" name="Apply" description="apply">Apply for this project</div> | |||||
| </body> | </body> | ||||
| @@ -1,5 +1,6 @@ | |||||
| from web import form | from web import form | ||||
| from models.project import get_categories | from models.project import get_categories | ||||
| from models.login import get_users | |||||
| # Define the login form | # Define the login form | ||||
| login_form = form.Form( | login_form = form.Form( | ||||
| @@ -24,9 +25,6 @@ register_form = form.Form( | |||||
| form.Button("Register", type="submit", description="Register"), | form.Button("Register", type="submit", description="Register"), | ||||
| ) | ) | ||||
| # Get categories | |||||
| categories = get_categories() | |||||
| def get_task_form_elements(identifier=0, task_title="", task_description="", budget=""): | def get_task_form_elements(identifier=0, task_title="", task_description="", budget=""): | ||||
| """ | """ | ||||
| Generate a set of task form elements | Generate a set of task form elements | ||||
| @@ -58,6 +56,7 @@ def get_project_form_elements(project_title="", project_description="", category | |||||
| :type category_name: str | :type category_name: str | ||||
| :return: A set of project form elements | :return: A set of project form elements | ||||
| """ | """ | ||||
| categories = get_categories() | |||||
| project_form_elements = ( | project_form_elements = ( | ||||
| form.Textbox("project_title", description="Title", value=project_title), | form.Textbox("project_title", description="Title", value=project_title), | ||||
| form.Textarea("project_description", description="Description", value=project_description), | form.Textarea("project_description", description="Description", value=project_description), | ||||
| @@ -66,9 +65,9 @@ def get_project_form_elements(project_title="", project_description="", category | |||||
| return project_form_elements | return project_form_elements | ||||
| def get_user_form_elements(identifier=0, user_name="", read_permission=True, write_permission=False, modify_permission=False): | def get_user_form_elements(identifier=0, user_name="", read_permission=True, write_permission=False, modify_permission=False): | ||||
| users = get_users() | |||||
| user_form_elements = ( | user_form_elements = ( | ||||
| form.Textbox("user_name_" + str(identifier), description="User", value=user_name), | |||||
| form.Checkbox("read_permission_" + str(identifier), description="Read Permission", checked=read_permission, value=read_permission), | |||||
| form.Textbox("user_name_" + str(identifier), description="User", value=user_name), form.Checkbox("read_permission_" + str(identifier), description="Read Permission", checked=read_permission, value=read_permission), | |||||
| form.Checkbox("write_permission_" + str(identifier), description="Write Permission", checked=write_permission, value=write_permission), | form.Checkbox("write_permission_" + str(identifier), description="Write Permission", checked=write_permission, value=write_permission), | ||||
| form.Checkbox("modify_permission_" + str(identifier), description="Modify Permission", checked=modify_permission, value=modify_permission) | form.Checkbox("modify_permission_" + str(identifier), description="Modify Permission", checked=modify_permission, value=modify_permission) | ||||
| ) | ) | ||||
| @@ -89,14 +88,27 @@ def get_new_project_form(elements): | |||||
| form.Button("Create Project", type="submit", description="Create Project", value="create_project") | form.Button("Create Project", type="submit", description="Create Project", value="create_project") | ||||
| ) | ) | ||||
| 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") | |||||
| ) | |||||
| except TypeError as e: | |||||
| 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") | |||||
| ) | |||||
| return apply_form | |||||
| apply_form = form.Form( | |||||
| form.Button("Apply", type="submit", description="Apply", value="apply") | |||||
| ) | |||||
| def get_user_dropdown(identifier=0): | |||||
| users = get_users() | |||||
| return form.Dropdown("user_name_" + str(identifier), description="User", args=users) | |||||
| # Define the guestbook form | # Define the guestbook form | ||||
| guestbook_form = form.Form( | guestbook_form = form.Form( | ||||
| form.Textbox("entry", description="Entry"), | form.Textbox("entry", description="Entry"), | ||||
| ) | ) | ||||
| @@ -33,7 +33,7 @@ class Login(): | |||||
| # Decode the hash | # Decode the hash | ||||
| decode = base64.b64decode(remember_hash) | decode = base64.b64decode(remember_hash) | ||||
| # Load the decoded hash to receive the host signature and the username | # Load the decoded hash to receive the host signature and the username | ||||
| username, sign = pickle.loads(encode) | |||||
| username, sign = pickle.loads(decode) | |||||
| except AttributeError as e: | except AttributeError as e: | ||||
| # The user did not have the stored remember me cookie | # The user did not have the stored remember me cookie | ||||
| pass | pass | ||||
| @@ -14,7 +14,7 @@ class Logout: | |||||
| """ | """ | ||||
| session = web.ctx.session | session = web.ctx.session | ||||
| session.username = None | session.username = None | ||||
| session.id = None | |||||
| session.userid = None | |||||
| web.setcookie('remember', '', 0) | web.setcookie('remember', '', 0) | ||||
| session.kill() | session.kill() | ||||
| raise web.seeother('/') | raise web.seeother('/') | ||||
| @@ -60,17 +60,16 @@ class New_project: | |||||
| try: | try: | ||||
| # Post the form data and save the project in the database | # Post the form data and save the project in the database | ||||
| if data["Create Project"]: | if data["Create Project"]: | ||||
| task_count = self.get_task_count(data) | |||||
| user_count = self.get_user_count(data) | |||||
| task_count = get_task_count(data) | |||||
| user_count = get_user_count(data) | |||||
| # Get the "real" user_count, if there is only one field and no users assigned the project is open | # Get the "real" user_count, if there is only one field and no users assigned the project is open | ||||
| status = "open" | |||||
| if user_count > 0: | if user_count > 0: | ||||
| if len(data.user_name_0): | if len(data.user_name_0): | ||||
| status = "in progress" | status = "in progress" | ||||
| else: | |||||
| status = "open" | |||||
| else: | |||||
| status = "open" | |||||
| # Save the project to the database | |||||
| projectid = models.project.set_project(data.category_name, str(session.userid), | projectid = models.project.set_project(data.category_name, str(session.userid), | ||||
| data.project_title, data.project_description, status) | data.project_title, data.project_description, status) | ||||
| @@ -100,37 +99,6 @@ class New_project: | |||||
| raise web.seeother('/') | raise web.seeother('/') | ||||
| except Exception as e: | except Exception as e: | ||||
| raise e | raise e | ||||
| def get_task_count(self, data): | |||||
| """ | |||||
| Determine the number of tasks created by removing | |||||
| the four other elements from count and divide by the | |||||
| number of variables in one task. | |||||
| :param data: The data object from web.input | |||||
| :return: The number of tasks opened by the client | |||||
| """ | |||||
| #task_count = int((len(data) - 4) / 3) | |||||
| task_count = 0 | |||||
| while True: | |||||
| try: | |||||
| data["task_title_"+str(task_count)] | |||||
| task_count += 1 | |||||
| except: | |||||
| break | |||||
| return task_count | |||||
| def get_user_count(self, data): | |||||
| user_count = 0 | |||||
| while True: | |||||
| try: | |||||
| data["user_name_"+str(user_count)] | |||||
| user_count += 1 | |||||
| except: | |||||
| break | |||||
| return user_count | |||||
| def compose_form(self, data, operation): | def compose_form(self, data, operation): | ||||
| """ | """ | ||||
| @@ -141,8 +109,8 @@ class New_project: | |||||
| :type add: boolean | :type add: boolean | ||||
| :return: A complete project form object | :return: A complete project form object | ||||
| """ | """ | ||||
| task_count = self.get_task_count(data) | |||||
| user_count = self.get_user_count(data) | |||||
| task_count = get_task_count(data) | |||||
| user_count = get_user_count(data) | |||||
| print(user_count) | print(user_count) | ||||
| if operation == "remove_task" and task_count > 1: | if operation == "remove_task" and task_count > 1: | ||||
| task_count -= 1 | task_count -= 1 | ||||
| @@ -197,3 +165,31 @@ class New_project: | |||||
| project_form = get_new_project_form((project_form_elements + task_form_elements + user_form_elements)) | project_form = get_new_project_form((project_form_elements + task_form_elements + user_form_elements)) | ||||
| return project_form | return project_form | ||||
| def get_task_count(data): | |||||
| """ | |||||
| Determine the number of tasks created by removing | |||||
| the four other elements from count and divide by the | |||||
| number of variables in one task. | |||||
| :param data: The data object from web.input | |||||
| :return: The number of tasks opened by the client | |||||
| """ | |||||
| task_count = 0 | |||||
| while True: | |||||
| try: | |||||
| data["task_title_"+str(task_count)] | |||||
| task_count += 1 | |||||
| except: | |||||
| break | |||||
| return task_count | |||||
| def get_user_count(data): | |||||
| user_count = 0 | |||||
| while True: | |||||
| try: | |||||
| data["user_name_"+str(user_count)] | |||||
| user_count += 1 | |||||
| except: | |||||
| break | |||||
| return user_count | |||||
| @@ -30,8 +30,8 @@ class Project: | |||||
| else: | else: | ||||
| project = [[]] | project = [[]] | ||||
| tasks = [[]] | tasks = [[]] | ||||
| render = web.template.render('templates/', globals={'get_task_files':models.project.get_task_files}) | |||||
| return render.project(nav, project[0], tasks) | |||||
| render = web.template.render('templates/', globals={'get_task_files':models.project.get_task_files, 'session':session}) | |||||
| return render.project(nav, project, tasks) | |||||
| def POST(self): | def POST(self): | ||||
| data = web.input(myfile={}) | data = web.input(myfile={}) | ||||