| @@ -77,7 +77,7 @@ CREATE TABLE tasks ( | |||||
| title VARCHAR(200) NOT NULL, | title VARCHAR(200) NOT NULL, | ||||
| task_description VARCHAR(500), | task_description VARCHAR(500), | ||||
| budget INT NOT NULL, | budget INT NOT NULL, | ||||
| task_status VARCHAR(64) NOT NULL, -- This should be Waiting for delivery, Delivered and waiting for acceptance, Delivery has been accepted, awaiting payment, Payment for delivery is done or Declined delivery, please revise | |||||
| task_status VARCHAR(64) NOT NULL, -- This should be Waiting for delivery, delivered, accepted and declined delivery | |||||
| feedback VARCHAR(500) NULL, | feedback VARCHAR(500) NULL, | ||||
| PRIMARY KEY (taskid), | PRIMARY KEY (taskid), | ||||
| FOREIGN KEY (teamid) REFERENCES teams(teamid), | FOREIGN KEY (teamid) REFERENCES teams(teamid), | ||||
| @@ -64,6 +64,18 @@ def update_project_status(projectid, status): | |||||
| db.commit() | db.commit() | ||||
| cursor.close() | cursor.close() | ||||
| def get_user_permissions(userid, projectid): | |||||
| cursor = db.cursor() | |||||
| query = ("SELECT read_permission, write_permission, modify_permission \ | |||||
| FROM projects_users WHERE projectid = \"" + projectid + | |||||
| "\" AND userid = \"" + userid + "\"") | |||||
| cursor.execute(query) | |||||
| permissions = cursor.fetchall() | |||||
| cursor.close() | |||||
| if len(permissions): | |||||
| return permissions[0] | |||||
| return [0,0,0] | |||||
| def get_projects_by_status_and_category(categoryid, project_status): | def get_projects_by_status_and_category(categoryid, project_status): | ||||
| """ | """ | ||||
| Retrieve all projects from a category with a specific status | Retrieve all projects from a category with a specific status | ||||
| @@ -145,6 +157,14 @@ def set_task(projectid, task_title, task_description, budget): | |||||
| db.commit() | db.commit() | ||||
| cursor.close | cursor.close | ||||
| def update_task_status(taskid, status): | |||||
| cursor = db.cursor() | |||||
| query = ("UPDATE tasks SET task_status = \"" + status + | |||||
| "\" WHERE taskid = \"" + taskid + "\"") | |||||
| cursor.execute(query) | |||||
| db.commit() | |||||
| cursor.close() | |||||
| def get_tasks_by_project_id(projectid): | def get_tasks_by_project_id(projectid): | ||||
| """ | """ | ||||
| Get all tasks belonging to a project | Get all tasks belonging to a project | ||||
| @@ -1,4 +1,4 @@ | |||||
| $def with (nav, project, tasks) | |||||
| $def with (nav, project, tasks, permissions) | |||||
| <head> | <head> | ||||
| <title>Beelance2</title> | <title>Beelance2</title> | ||||
| @@ -33,6 +33,9 @@ $def with (nav, project, tasks) | |||||
| <br/> | <br/> | ||||
| <input type="hidden" name="taskid" value="$task[0]"/> | <input type="hidden" name="taskid" value="$task[0]"/> | ||||
| <input type="submit" name="submit"/> | <input type="submit" name="submit"/> | ||||
| $if permissions[2]: | |||||
| <button type="submit" name="deliver" value="1">Deliver</button> | |||||
| </form> | </form> | ||||
| </li> | </li> | ||||
| </ul> | </ul> | ||||
| @@ -24,6 +24,9 @@ class Project: | |||||
| nav = get_nav_bar(session) | nav = get_nav_bar(session) | ||||
| data = web.input(projectid=0) | data = web.input(projectid=0) | ||||
| permissions = models.project.get_user_permissions(str(session.userid), data.projectid) | |||||
| if data.projectid: | if data.projectid: | ||||
| project = models.project.get_project_by_id(data.projectid) | project = models.project.get_project_by_id(data.projectid) | ||||
| tasks = models.project.get_tasks_by_project_id(data.projectid) | tasks = models.project.get_tasks_by_project_id(data.projectid) | ||||
| @@ -31,15 +34,24 @@ class Project: | |||||
| project = [[]] | project = [[]] | ||||
| tasks = [[]] | tasks = [[]] | ||||
| render = web.template.render('templates/', globals={'get_task_files':models.project.get_task_files, 'session':session}) | render = web.template.render('templates/', globals={'get_task_files':models.project.get_task_files, 'session':session}) | ||||
| return render.project(nav, project, tasks) | |||||
| return render.project(nav, project, tasks,permissions) | |||||
| def POST(self): | def POST(self): | ||||
| data = web.input(myfile={}) | |||||
| # Get session | |||||
| session = web.ctx.session | |||||
| data = web.input(myfile={}, deliver=None) | |||||
| fileitem = data['myfile'] | fileitem = data['myfile'] | ||||
| permissions = models.project.get_user_permissions(str(session.userid), data.projectid) | |||||
| print(data.deliver) | |||||
| # Test if the file was uploaded | # Test if the file was uploaded | ||||
| if fileitem.filename: | if fileitem.filename: | ||||
| if not permissions[1]: | |||||
| print("Permission denied") | |||||
| raise web.seeother(('/project?projectid=' + data.projectid)) | |||||
| data = web.input(projectid=0) | data = web.input(projectid=0) | ||||
| fn = fileitem.filename | fn = fileitem.filename | ||||
| @@ -60,10 +72,12 @@ class Project: | |||||
| open(path + '/' + fn, 'wb').write(fileitem.file.read()) | open(path + '/' + fn, 'wb').write(fileitem.file.read()) | ||||
| message = 'The file "' + fn + '" was uploaded successfully' | message = 'The file "' + fn + '" was uploaded successfully' | ||||
| models.project.set_task_file(data.taskid, (path + "/" + fn)) | models.project.set_task_file(data.taskid, (path + "/" + fn)) | ||||
| elif data.deliver: | |||||
| models.project.update_task_status(data.taskid, "delivered") | |||||
| print(data.taskid) | |||||
| else: | else: | ||||
| message = 'No file was uploaded' | message = 'No file was uploaded' | ||||
| print (message) | |||||
| raise web.seeother(('/project?projectid=' + data.projectid)) | raise web.seeother(('/project?projectid=' + data.projectid)) | ||||