From 9f2817fcf8f6effd2a02dbce8345073e06c69048 Mon Sep 17 00:00:00 2001 From: fram3d Date: Tue, 16 Jan 2024 14:44:06 +0100 Subject: [PATCH] implement addtask and addusers to a task features --- taskmanager/functions.py | 17 +++++++++++++++++ taskmanager/routes.py | 23 ++++++++++++++++++----- taskmanager/templates/addtask.html | 20 ++++++++++++++++++++ taskmanager/templates/index.html | 3 ++- taskmanager/templates/project.html | 9 +++++++-- 5 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 taskmanager/templates/addtask.html diff --git a/taskmanager/functions.py b/taskmanager/functions.py index e69de29..3b0881c 100644 --- a/taskmanager/functions.py +++ b/taskmanager/functions.py @@ -0,0 +1,17 @@ +from taskmanager.models import * + +def gettaskusers(taskid): + users = list() + userids = list() + try: + taskusers = TaskUser.query.filter_by(taskid = taskid).all() + except: + taskusers = list() + + for taskuser in taskusers: + userids.append(taskuser.userid) + + for userid in userids: + users.append(User.query.get(userid)) + + return users diff --git a/taskmanager/routes.py b/taskmanager/routes.py index dd05bf2..3d5827d 100644 --- a/taskmanager/routes.py +++ b/taskmanager/routes.py @@ -8,6 +8,21 @@ def index(): tasks = Task.query.all() return render_template('index.html', tasks = tasks) +@app.route('/addtask', methods=['GET','POST']) +def addtask(): + if request.method == 'GET': + return render_template('addtask.html') + elif request.method == 'POST': + taskname = request.form['taskname'] + taskdesc = request.form['taskdesc'] + sqladdtask = Task(name = taskname, desc = taskdesc) + try: + db.session.add(sqladdtask) + db.session.commit() + return 'Task added' + except: + return 'Adding task failed' + @app.route('/register', methods=['POST', 'GET']) def register(): if request.method == 'GET': @@ -29,19 +44,17 @@ def register(): @app.route('/projects/', methods=['GET','POST']) def project(task_id:int): + users = gettaskusers(task_id) if request.method == 'GET': try: task = Task.query.get(task_id) except: return 'Task not found, bad URL' - try: - userid = TaskUser.query.filter_by(taskid = task_id).first().userid - users = User.query.get(userid).username - except: - users = "No users added to this task" return render_template("project.html", task = task, users = users) elif request.method == 'POST': username = request.form['username'] + if username in users: + return 'User already added to task' try: userid = User.query.filter_by(username = username).first().id except: diff --git a/taskmanager/templates/addtask.html b/taskmanager/templates/addtask.html new file mode 100644 index 0000000..742d728 --- /dev/null +++ b/taskmanager/templates/addtask.html @@ -0,0 +1,20 @@ + + + + + + Add new task + + + +
+
+ + + + + +
+
+ + diff --git a/taskmanager/templates/index.html b/taskmanager/templates/index.html index 2e07280..2a769dd 100644 --- a/taskmanager/templates/index.html +++ b/taskmanager/templates/index.html @@ -3,7 +3,7 @@ - Decentrala + Task manager @@ -15,6 +15,7 @@
  • {{task.name}}
  • {% endfor %} +

    Add new task

    diff --git a/taskmanager/templates/project.html b/taskmanager/templates/project.html index a3b075e..877234f 100644 --- a/taskmanager/templates/project.html +++ b/taskmanager/templates/project.html @@ -3,7 +3,7 @@ - Decentrala + {{task.name}} @@ -13,8 +13,13 @@
  • {{task.name}}
  • {{task.desc}}
  • -
  • {{users}}
  • +

    Users added to this task

    + + {% for user in users %} +
  • {{user.username}}, {{user.contact}}
  • + {% endfor %} +

    Add yourself to task