implement addtask and addusers to a task features
This commit is contained in:
parent
d81ff0592e
commit
9f2817fcf8
@ -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
|
@ -8,6 +8,21 @@ def index():
|
|||||||
tasks = Task.query.all()
|
tasks = Task.query.all()
|
||||||
return render_template('index.html', tasks = tasks)
|
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'])
|
@app.route('/register', methods=['POST', 'GET'])
|
||||||
def register():
|
def register():
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
@ -29,19 +44,17 @@ def register():
|
|||||||
|
|
||||||
@app.route('/projects/<int:task_id>', methods=['GET','POST'])
|
@app.route('/projects/<int:task_id>', methods=['GET','POST'])
|
||||||
def project(task_id:int):
|
def project(task_id:int):
|
||||||
|
users = gettaskusers(task_id)
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
try:
|
try:
|
||||||
task = Task.query.get(task_id)
|
task = Task.query.get(task_id)
|
||||||
except:
|
except:
|
||||||
return 'Task not found, bad URL'
|
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)
|
return render_template("project.html", task = task, users = users)
|
||||||
elif request.method == 'POST':
|
elif request.method == 'POST':
|
||||||
username = request.form['username']
|
username = request.form['username']
|
||||||
|
if username in users:
|
||||||
|
return 'User already added to task'
|
||||||
try:
|
try:
|
||||||
userid = User.query.filter_by(username = username).first().id
|
userid = User.query.filter_by(username = username).first().id
|
||||||
except:
|
except:
|
||||||
|
20
taskmanager/templates/addtask.html
Normal file
20
taskmanager/templates/addtask.html
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Add new task</title>
|
||||||
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
<form action="/addtask" method="POST">
|
||||||
|
<label for="taskname">taskname</label>
|
||||||
|
<input type="text" name="taskname" id="taskname" required>
|
||||||
|
<label for="taskdesc">taskdesc</label>
|
||||||
|
<input type="text" name="taskdesc" id="taskdesc" required>
|
||||||
|
<button> Submit </button>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>Decentrala</title>
|
<title>Task manager</title>
|
||||||
<link rel="stylesheet" href="/static/style.css">
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -15,6 +15,7 @@
|
|||||||
<li><a href="/projects/{{task.id}}"> {{task.name}} </a></li>
|
<li><a href="/projects/{{task.id}}"> {{task.name}} </a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</section>
|
</section>
|
||||||
|
<p> <a href="/addtask">Add</a> new task <p>
|
||||||
</main>
|
</main>
|
||||||
<footer>
|
<footer>
|
||||||
</footer>
|
</footer>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>Decentrala</title>
|
<title>{{task.name}}</title>
|
||||||
<link rel="stylesheet" href="/static/style.css">
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -13,8 +13,13 @@
|
|||||||
<section>
|
<section>
|
||||||
<li>{{task.name}}</li>
|
<li>{{task.name}}</li>
|
||||||
<li>{{task.desc}}</li>
|
<li>{{task.desc}}</li>
|
||||||
<li>{{users}}</li>
|
|
||||||
</section>
|
</section>
|
||||||
|
<h1> Users added to this task </h1>
|
||||||
|
|
||||||
|
{% for user in users %}
|
||||||
|
<li>{{user.username}}, {{user.contact}}</li>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
<h1> Add yourself to task </h1>
|
<h1> Add yourself to task </h1>
|
||||||
<form action="/projects/{{task.id}}" method="POST">
|
<form action="/projects/{{task.id}}" method="POST">
|
||||||
<label for="username">username</label>
|
<label for="username">username</label>
|
||||||
|
Loading…
Reference in New Issue
Block a user