Przeglądaj źródła

Deliver button now changes the status to delivered

https
jakobsn 6 lat temu
rodzic
commit
2285ccd3bc
4 zmienionych plików z 43 dodań i 6 usunięć
  1. +1
    -1
      mysql/sql/init.sql
  2. +20
    -0
      src/app/models/project.py
  3. +4
    -1
      src/app/templates/project.html
  4. +18
    -4
      src/app/views/project.py

+ 1
- 1
mysql/sql/init.sql Wyświetl plik

@@ -77,7 +77,7 @@ CREATE TABLE tasks (
title VARCHAR(200) NOT NULL,
task_description VARCHAR(500),
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,
PRIMARY KEY (taskid),
FOREIGN KEY (teamid) REFERENCES teams(teamid),


+ 20
- 0
src/app/models/project.py Wyświetl plik

@@ -64,6 +64,18 @@ def update_project_status(projectid, status):
db.commit()
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):
"""
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()
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):
"""
Get all tasks belonging to a project


+ 4
- 1
src/app/templates/project.html Wyświetl plik

@@ -1,4 +1,4 @@
$def with (nav, project, tasks)
$def with (nav, project, tasks, permissions)

<head>
<title>Beelance2</title>
@@ -33,6 +33,9 @@ $def with (nav, project, tasks)
<br/>
<input type="hidden" name="taskid" value="$task[0]"/>
<input type="submit" name="submit"/>

$if permissions[2]:
<button type="submit" name="deliver" value="1">Deliver</button>
</form>
</li>
</ul>


+ 18
- 4
src/app/views/project.py Wyświetl plik

@@ -24,6 +24,9 @@ class Project:
nav = get_nav_bar(session)

data = web.input(projectid=0)

permissions = models.project.get_user_permissions(str(session.userid), data.projectid)

if data.projectid:
project = models.project.get_project_by_id(data.projectid)
tasks = models.project.get_tasks_by_project_id(data.projectid)
@@ -31,15 +34,24 @@ class Project:
project = [[]]
tasks = [[]]
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):
data = web.input(myfile={})
# Get session
session = web.ctx.session

data = web.input(myfile={}, deliver=None)

fileitem = data['myfile']

permissions = models.project.get_user_permissions(str(session.userid), data.projectid)
print(data.deliver)
# Test if the file was uploaded
if fileitem.filename:
if not permissions[1]:
print("Permission denied")
raise web.seeother(('/project?projectid=' + data.projectid))

data = web.input(projectid=0)

fn = fileitem.filename
@@ -60,10 +72,12 @@ class Project:
open(path + '/' + fn, 'wb').write(fileitem.file.read())
message = 'The file "' + fn + '" was uploaded successfully'
models.project.set_task_file(data.taskid, (path + "/" + fn))
elif data.deliver:
models.project.update_task_status(data.taskid, "delivered")
print(data.taskid)
else:
message = 'No file was uploaded'
print (message)

raise web.seeother(('/project?projectid=' + data.projectid))


Ładowanie…
Anuluj
Zapisz