From d81ff0592e4e432837ade1722e96866d97ae9819 Mon Sep 17 00:00:00 2001 From: fram3d Date: Tue, 16 Jan 2024 13:44:51 +0100 Subject: [PATCH] add project page --- taskmanager/routes.py | 46 ++++++++++++++++++++++++------ taskmanager/templates/index.html | 2 +- taskmanager/templates/project.html | 29 +++++++++++++++++++ taskmanager/templates/submit.html | 20 ------------- 4 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 taskmanager/templates/project.html delete mode 100644 taskmanager/templates/submit.html diff --git a/taskmanager/routes.py b/taskmanager/routes.py index ec7e818..dd05bf2 100644 --- a/taskmanager/routes.py +++ b/taskmanager/routes.py @@ -8,20 +8,48 @@ def index(): tasks = Task.query.all() return render_template('index.html', tasks = tasks) -@app.route('/submit', methods=['POST', 'GET']) -def submit(): +@app.route('/register', methods=['POST', 'GET']) +def register(): if request.method == 'GET': - return render_template('submit.html') + return render_template('register.html') elif request.method == 'POST': - userinput1 = request.form['forminput1'] - userinput2 = request.form['forminput2'] - sqlrow = Table(variable1 = int(userinput1), variable2 = int(userinput2)) + username = request.form['username'] + contact = request.form['contact'] + sqladduser = User(username = username, contact = contact) try: - db.session.add(sqlrow) + db.session.add(sqladduser) db.session.commit() - return 'Row added' + return 'User added' except: - return 'Adding row to table failed' + return 'Adding user failed' else: return 'HTTP request method not recogniezed' + + +@app.route('/projects/', methods=['GET','POST']) +def project(task_id:int): + 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'] + try: + userid = User.query.filter_by(username = username).first().id + except: + return 'User not found, please register.' + sqladduser = TaskUser(userid = userid, taskid = task_id) + try: + db.session.add(sqladduser) + db.session.commit() + return 'User added' + except: + return 'Adding user failed' diff --git a/taskmanager/templates/index.html b/taskmanager/templates/index.html index 95bdf2e..2e07280 100644 --- a/taskmanager/templates/index.html +++ b/taskmanager/templates/index.html @@ -12,7 +12,7 @@
{% for task in tasks %} -
  • {{task}}
  • +
  • {{task.name}}
  • {% endfor %}
    diff --git a/taskmanager/templates/project.html b/taskmanager/templates/project.html new file mode 100644 index 0000000..a3b075e --- /dev/null +++ b/taskmanager/templates/project.html @@ -0,0 +1,29 @@ + + + + + + Decentrala + + + +
    +
    +
    +
    +
  • {{task.name}}
  • +
  • {{task.desc}}
  • +
  • {{users}}
  • +
    +

    Add yourself to task

    +
    + + + +
    + +
    +
    +
    + + diff --git a/taskmanager/templates/submit.html b/taskmanager/templates/submit.html deleted file mode 100644 index 002b842..0000000 --- a/taskmanager/templates/submit.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - Submit - - - -
    -
    - - - - - -
    -
    - -