forked from Decentrala/taskmanager
add response.html and deleting user assignment to deleted tasks
This commit is contained in:
parent
4911842d3f
commit
673c04af19
@ -8,4 +8,4 @@ Depends: gunicorn, python3-flask-sqlalchemy
|
|||||||
Homepage: https://gitea.dmz.rs/Decentrala/taskmanager
|
Homepage: https://gitea.dmz.rs/Decentrala/taskmanager
|
||||||
Maintainer: Decentrala <dmz@dmz.rs>
|
Maintainer: Decentrala <dmz@dmz.rs>
|
||||||
Description: Interactive TODO list Web app
|
Description: Interactive TODO list Web app
|
||||||
Version: 1.0.6
|
Version: 1.0.7
|
||||||
|
@ -26,31 +26,31 @@ def addtask():
|
|||||||
username = request.form['username']
|
username = request.form['username']
|
||||||
# Input sanitation
|
# Input sanitation
|
||||||
if not taskname.isalnum():
|
if not taskname.isalnum():
|
||||||
return "Task name has to be made only of letters or numbers."
|
return render_template('response.html', response = "Task name has to be made only of letters or numbers.")
|
||||||
if not username.isalnum():
|
if not username.isalnum():
|
||||||
return "Username has to be made only of letters or numbers."
|
return render_template('response.html', response = "Username has to be made only of letters or numbers.")
|
||||||
if not taskdesc.isprintable():
|
if not taskdesc.isprintable():
|
||||||
return "Task description has to be made of printable characters."
|
return render_template('response.html', response = "Task description has to be made of printable characters.")
|
||||||
if len(taskname) < 1 or len(taskname) > 40:
|
if len(taskname) < 1 or len(taskname) > 40:
|
||||||
return "Task name lenght invalid, only smaller then 40 charachters allowed"
|
return render_template('response.html', response = "Task name lenght invalid, only smaller then 40 charachters allowed")
|
||||||
if len(taskdesc) > 2000:
|
if len(taskdesc) > 2000:
|
||||||
return "Task description lenght invalid, only smaller then 2000 charachters allowed"
|
return render_template('response.html', response = "Task description lenght invalid, only smaller then 2000 charachters allowed")
|
||||||
if username == "":
|
if username == "":
|
||||||
creatorid = None
|
creatorid = None
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
creatorid = User.query.filter_by(username = username).first().id
|
creatorid = User.query.filter_by(username = username).first().id
|
||||||
except:
|
except:
|
||||||
return 'No user with this username. Please <a href="/register">register</a>.'
|
return render_template('response.html', response = 'No user with this username. Please <a href="/register">register</a>.')
|
||||||
if creatorid is None:
|
if creatorid is None:
|
||||||
return 'No user with this username. Please <a href="/register">register</a>.'
|
return render_template('response.html', response = 'No user with this username. Please <a href="/register">register</a>.')
|
||||||
sqladdtask = Task(name = taskname, desc = taskdesc, creatorid = creatorid)
|
sqladdtask = Task(name = taskname, desc = taskdesc, creatorid = creatorid)
|
||||||
try:
|
try:
|
||||||
db.session.add(sqladdtask)
|
db.session.add(sqladdtask)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return 'Task added'
|
return render_template('response.html', response = 'Task added')
|
||||||
except:
|
except:
|
||||||
return 'Adding task failed'
|
return render_template('response.html', response = 'Adding task failed')
|
||||||
|
|
||||||
@app.route('/register', methods=['POST', 'GET'])
|
@app.route('/register', methods=['POST', 'GET'])
|
||||||
def register():
|
def register():
|
||||||
@ -61,27 +61,27 @@ def register():
|
|||||||
contact = request.form['contact']
|
contact = request.form['contact']
|
||||||
password = request.form['password']
|
password = request.form['password']
|
||||||
if not username.isalnum():
|
if not username.isalnum():
|
||||||
return "Username has to be made only of letters or numbers."
|
return render_template('response.html', response = "Username has to be made only of letters or numbers.")
|
||||||
if not contact.isprintable():
|
if not contact.isprintable():
|
||||||
return "Contact information has to be made of printable characters."
|
return render_template('response.html', response = "Contact information has to be made of printable characters.")
|
||||||
if not password.isprintable():
|
if not password.isprintable():
|
||||||
return "Password has to be made of printable characters."
|
return render_template('response.html', response = "Password has to be made of printable characters.")
|
||||||
if len(username) < 1 or len(username) > 40:
|
if len(username) < 1 or len(username) > 40:
|
||||||
return "Username lenght invalid, only smaller then 40 charachters allowed"
|
return render_template('response.html', response = "Username lenght invalid, only smaller then 40 charachters allowed")
|
||||||
if len(contact) > 100:
|
if len(contact) > 100:
|
||||||
return "Contact lenght invalid, only smaller then 100 charachters allowed"
|
return render_template('response.html', response = "Contact lenght invalid, only smaller then 100 charachters allowed")
|
||||||
if len(password) > 500:
|
if len(password) > 500:
|
||||||
return "Password lenght invalid, only smaller then 500 charachters allowed"
|
return render_template('response.html', response = "Password lenght invalid, only smaller then 500 charachters allowed")
|
||||||
sqladduser = User(username = username, contact = contact, password = password)
|
sqladduser = User(username = username, contact = contact, password = password)
|
||||||
try:
|
try:
|
||||||
db.session.add(sqladduser)
|
db.session.add(sqladduser)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return 'User added'
|
return render_template('response.html', response = 'User added')
|
||||||
except:
|
except:
|
||||||
return 'Adding user failed'
|
return render_template('response.html', response = 'Adding user failed')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return 'HTTP request method not recogniezed'
|
return render_template('response.html', response = 'HTTP request method not recogniezed')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/projects/<int:task_id>', methods=['GET','POST'])
|
@app.route('/projects/<int:task_id>', methods=['GET','POST'])
|
||||||
@ -89,63 +89,70 @@ def project(task_id:int):
|
|||||||
try:
|
try:
|
||||||
task = Task.query.get(task_id)
|
task = Task.query.get(task_id)
|
||||||
except:
|
except:
|
||||||
return 'Task not found, bad URL'
|
return render_template('response.html', response = 'Task not found, bad URL')
|
||||||
if task is None:
|
if task is None:
|
||||||
return 'Task not found, bad URL'
|
return render_template('response.html', response = 'Task not found, bad URL')
|
||||||
users = gettaskusers(task_id)
|
users = gettaskusers(task_id)
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
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 len(username) < 1 or len(username) > 40:
|
if len(username) < 1 or len(username) > 40:
|
||||||
return "Username lenght invalid, only smaller then 40 charachters allowed"
|
return render_template('response.html', response = "Username lenght invalid, only smaller then 40 charachters allowed")
|
||||||
for user in users:
|
for user in users:
|
||||||
if username == user.username:
|
if username == user.username:
|
||||||
return 'User already added to task'
|
return render_template('response.html', response = '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:
|
||||||
return 'User not found, please <a href="/register">register</a>.'
|
return render_template('response.html', response = 'User not found, please <a href="/register">register</a>.')
|
||||||
if userid is None:
|
if userid is None:
|
||||||
return 'User not found, please <a href="/register">register</a>.'
|
return render_template('response.html', response = 'User not found, please <a href="/register">register</a>.')
|
||||||
sqladduser = TaskUser(userid = userid, taskid = task_id)
|
sqladduser = TaskUser(userid = userid, taskid = task_id)
|
||||||
try:
|
try:
|
||||||
db.session.add(sqladduser)
|
db.session.add(sqladduser)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return 'User added'
|
return render_template('response.html', response = 'User added')
|
||||||
except:
|
except:
|
||||||
return 'Adding user failed'
|
return render_template('response.html', response = 'Adding user failed')
|
||||||
|
|
||||||
@app.route('/projects/<int:task_id>/del', methods=['GET','POST'])
|
@app.route('/projects/<int:task_id>/del', methods=['GET','POST'])
|
||||||
def deltask(task_id:int):
|
def deltask(task_id:int):
|
||||||
try:
|
try:
|
||||||
task = Task.query.get(task_id)
|
task = Task.query.get(task_id)
|
||||||
except:
|
except:
|
||||||
return 'Task not found, bad URL'
|
return render_template('response.html', response = 'Task not found, bad URL')
|
||||||
|
try:
|
||||||
|
taskusers = TaskUser.query.filter_by(task_id = task_id)
|
||||||
|
except:
|
||||||
|
taskusers = None
|
||||||
if task is None:
|
if task is None:
|
||||||
return 'Task not found, bad URL'
|
return render_template('response.html', response = 'Task not found, bad URL')
|
||||||
creatorid = task.creatorid
|
creatorid = task.creatorid
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
if creatorid is None:
|
if creatorid is None:
|
||||||
try:
|
try:
|
||||||
db.session.delete(task)
|
db.session.delete(task)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return 'Task deleted'
|
if taskusers != None:
|
||||||
|
db.session.delete(taskusers)
|
||||||
|
db.session.commit()
|
||||||
|
return render_template('response.html', response = 'Task deleted')
|
||||||
except:
|
except:
|
||||||
return 'Deleting task failed'
|
return render_template('response.html', response = 'Deleting task failed')
|
||||||
else:
|
else:
|
||||||
return render_template('deltask.html', task = task)
|
return render_template('deltask.html', task = task)
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
password = request.form['password']
|
password = request.form['password']
|
||||||
if len(password) < 1 or len(password) > 500:
|
if len(password) < 1 or len(password) > 500:
|
||||||
return "Password lenght invalid, only smaller then 500 charachters allowed"
|
return render_template('response.html', response = "Password lenght invalid, only smaller then 500 charachters allowed")
|
||||||
# Check password
|
# Check password
|
||||||
if password != ADMINPASS and password != User.query.get(creatorid).password:
|
if password != ADMINPASS and password != User.query.get(creatorid).password:
|
||||||
return 'Wrong password'
|
return render_template('response.html', response = 'Wrong password')
|
||||||
# Delete task
|
# Delete task
|
||||||
try:
|
try:
|
||||||
db.session.delete(task)
|
db.session.delete(task)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return 'Task deleted'
|
return render_template('response.html', response = 'Task deleted')
|
||||||
except:
|
except:
|
||||||
return 'Deleting task failed'
|
return render_template('response.html', response = 'Deleting task failed')
|
||||||
|
26
taskmanager/templates/response.html
Normal file
26
taskmanager/templates/response.html
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<link rel="stylesheet" href="/static/style.css" />
|
||||||
|
<title>{{task.name}}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<nav class="container">
|
||||||
|
<ul>
|
||||||
|
<li><a href="/">Home</a></li>
|
||||||
|
<li><a href="/register">Register</a></li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
<main class="container page page-project">
|
||||||
|
<section >
|
||||||
|
<h1>{{response}}</h1>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
<footer>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user