diff --git a/mysql/sql/init.sql b/mysql/sql/init.sql index f3fd5f1..27ca999 100644 --- a/mysql/sql/init.sql +++ b/mysql/sql/init.sql @@ -143,4 +143,4 @@ Create default database user CREATE USER 'root'@'10.5.0.6' IDENTIFIED BY 'root'; GRANT ALL PRIVILEGES ON db.* TO 'root'@'10.5.0.6'; -GRANT ALL PRIVILEGES ON db.* TO 'root'@'localhost'; +/*GRANT ALL PRIVILEGES ON db.* TO 'root'@'localhost';*/ diff --git a/src/app/models/database.py b/src/app/models/database.py index 317b0f8..48b824a 100644 --- a/src/app/models/database.py +++ b/src/app/models/database.py @@ -8,8 +8,8 @@ preconfigured docker container address use the Docker address. The default port db = mysql.connector.connect( user='root', password='root', - #host='10.5.0.5', # Docker address - host='0.0.0.0', # Local address + host='10.5.0.5', # Docker address + #host='0.0.0.0', # Local address database='db' ) \ No newline at end of file diff --git a/src/app/templates/project.html b/src/app/templates/project.html index 86e59fa..ee54be5 100644 --- a/src/app/templates/project.html +++ b/src/app/templates/project.html @@ -31,6 +31,7 @@ $def with (nav, project_form, project, tasks, permissions, categories)

Task: $task[2]

Description: $task[3]

Budget: $task[4]

+

Status: $task[5]

$if project[5] != "open": $for filename in get_task_files(task[0]): $filename[0].split("/")[-1] diff --git a/src/app/views/app.py b/src/app/views/app.py index 6d4158e..15bd5ba 100644 --- a/src/app/views/app.py +++ b/src/app/views/app.py @@ -31,7 +31,7 @@ app = web.application(urls, globals()) render = web.template.render('templates/') # Set session timeout -web.config.session_parameters['timeout'] = None +web.config.session_parameters['timeout'] = 10000000 # Workaround to use sessions with reloader (debugger) http://webpy.org/cookbook/session_with_reloader if web.config.get('_session') is None: diff --git a/src/app/views/project.py b/src/app/views/project.py index 23fc92e..66ccd70 100644 --- a/src/app/views/project.py +++ b/src/app/views/project.py @@ -44,13 +44,38 @@ class Project: def POST(self): # Get session session = web.ctx.session - data = web.input(myfile={}, deliver=None, accepted=None, declined=None, projectid=0) fileitem = data['myfile'] + permissions = models.project.get_user_permissions(str(session.userid), data.projectid) categories = models.project.get_categories() tasks = models.project.get_tasks_by_project_id(data.projectid) + # Upload file (if present) + try: + if fileitem.filename: + # Check if user has write permission + if not permissions[1]: + raise web.seeother(('/project?projectid=' + data.projectid)) + + fn = fileitem.filename + # Create the project directory if it doesnt exist + path = 'static/project' + data.projectid + if not os.path.isdir(path): + command = 'mkdir ' + path + os.popen(command) + sleep(0.2) + path = path + '/task' + data.taskid + if not os.path.isdir(path): + command = 'mkdir ' + path + os.popen(command) + sleep(0.2) + open(path + '/' + fn, 'wb').write(fileitem.file.read()) + models.project.set_task_file(data.taskid, (path + "/" + fn)) + except: + # Throws exception if no file present + pass + # Determine status of the targeted task all_tasks_accepted = True task_waiting = False @@ -82,27 +107,6 @@ class Project: # Decline task delivery elif data.declined: models.project.update_task_status(data.taskid, "declined") - - # Upload file - elif fileitem.filename: - # Check if user has write permission - if not permissions[1] or not task_waiting: - raise web.seeother(('/project?projectid=' + data.projectid)) - - fn = fileitem.filename - # Create the project directory if it doesnt exist - path = 'static/project' + data.projectid - if not os.path.isdir(path): - command = 'mkdir ' + path - os.popen(command) - sleep(0.2) - path = path + '/task' + data.taskid - if not os.path.isdir(path): - command = 'mkdir ' + path - os.popen(command) - sleep(0.2) - open(path + '/' + fn, 'wb').write(fileitem.file.read()) - models.project.set_task_file(data.taskid, (path + "/" + fn)) raise web.seeother(('/project?projectid=' + data.projectid))