Compare commits

...

3 Commits

Author SHA1 Message Date
b4344d31a8 Merge pull request 'Izmenjen templates folder tako da bude modularniji' (#4) from svitvojimilioni/taskmanager:better-templates into master
Reviewed-on: #4
2024-01-19 16:17:37 +00:00
2d4b88bc7a Vracen path za config na staro 2024-01-19 11:15:58 -05:00
2721d2a524 Izmenjen templates folder tako da bude modularniji
- dodati folderi layouts, includes, pages
- dodate base layout koji koriste ostale stranice
- dodat header.html i footer.html i includes koji koriste ostale stranice
- sav html refaktorisan tako da koristi base.html layout i header i footer iz includes
2024-01-19 10:53:12 -05:00
11 changed files with 228 additions and 40 deletions

View File

@ -8,18 +8,17 @@ CONFIG_PATH = "/var/taskmanager/taskmanager/config.ini"
config = configparser.ConfigParser()
config.read(CONFIG_PATH)
ADMINPASS = config.get('credentials', 'ADMINPASS')
@app.route('/', methods=['GET'])
def index():
tasks = Task.query.all()
return render_template('index.html', tasks = tasks)
return render_template('pages/index.html', tasks = tasks)
@app.route('/addtask', methods=['GET','POST'])
def addtask():
if request.method == 'GET':
return render_template('addtask.html')
return render_template('pages/addtask.html')
elif request.method == 'POST':
taskname = request.form['taskname']
taskdesc = request.form['taskdesc']
@ -27,9 +26,9 @@ def addtask():
# Input sanitation
# Task name
if not taskname.isprintable():
return render_template('response.html', response = "Task name has to be made only of letters or numbers.")
return render_template('pages/response.html', response = "Task name has to be made only of letters or numbers.")
if len(taskname) < 1 or len(taskname) > 40:
return render_template('response.html', response = "Task name lenght invalid, only smaller then 40 charachters allowed")
return render_template('pages/response.html', response = "Task name lenght invalid, only smaller then 40 charachters allowed")
# Username
if username == "":
@ -38,28 +37,28 @@ def addtask():
try:
creatorid = User.query.filter_by(username = username).first().id
except:
return render_template('response.html', response = 'No user with this username. Please register')
return render_template('pages/response.html', response = 'No user with this username. Please register')
if creatorid is None:
return render_template('response.html', response = 'No user with this username. Please register.')
return render_template('pages/response.html', response = 'No user with this username. Please register.')
# Task descripton
if taskdesc != '':
if not taskdesc.isprintable():
return render_template('response.html', response = "Task description has to be made of printable characters.")
return render_template('pages/response.html', response = "Task description has to be made of printable characters.")
if len(taskdesc) > 2000:
return render_template('response.html', response = "Task description lenght invalid, only smaller then 2000 charachters allowed")
return render_template('pages/response.html', response = "Task description lenght invalid, only smaller then 2000 charachters allowed")
sqladdtask = Task(name = taskname, desc = taskdesc, creatorid = creatorid)
try:
db.session.add(sqladdtask)
db.session.commit()
return render_template('response.html', response = 'Task added')
return render_template('pages/response.html', response = 'Task added')
except:
return render_template('response.html', response = 'Adding task failed')
return render_template('pages/response.html', response = 'Adding task failed')
@app.route('/register', methods=['POST', 'GET'])
def register():
if request.method == 'GET':
return render_template('register.html')
return render_template('pages/register.html')
elif request.method == 'POST':
username = request.form['username']
contact = request.form['contact']
@ -67,34 +66,34 @@ def register():
# Username
if not username.isalnum():
return render_template('response.html', response = "Username has to be made only of letters or numbers.")
return render_template('pages/response.html', response = "Username has to be made only of letters or numbers.")
if len(username) < 1 or len(username) > 40:
return render_template('response.html', response = "Username lenght invalid, only smaller then 40 charachters allowed")
return render_template('pages/response.html', response = "Username lenght invalid, only smaller then 40 charachters allowed")
# Contact
if contact != '':
if not contact.isprintable():
return render_template('response.html', response = "Contact information has to be made of printable characters.")
return render_template('pages/response.html', response = "Contact information has to be made of printable characters.")
if len(contact) > 100:
return render_template('response.html', response = "Contact lenght invalid, only smaller then 100 charachters allowed")
return render_template('pages/response.html', response = "Contact lenght invalid, only smaller then 100 charachters allowed")
# Password
if password != '':
if not password.isprintable():
return render_template('response.html', response = "Password has to be made of printable characters.")
return render_template('pages/response.html', response = "Password has to be made of printable characters.")
if len(password) > 500:
return render_template('response.html', response = "Password lenght invalid, only smaller then 500 charachters allowed")
return render_template('pages/response.html', response = "Password lenght invalid, only smaller then 500 charachters allowed")
sqladduser = User(username = username, contact = contact, password = password)
try:
db.session.add(sqladduser)
db.session.commit()
return render_template('response.html', response = 'User added')
return render_template('pages/response.html', response = 'User added')
except:
return render_template('response.html', response = 'Adding user failed')
return render_template('pages/response.html', response = 'Adding user failed')
else:
return render_template('response.html', response = 'HTTP request method not recogniezed')
return render_template('pages/response.html', response = 'HTTP request method not recogniezed')
@app.route('/projects/<int:task_id>', methods=['GET','POST'])
@ -102,40 +101,40 @@ def project(task_id:int):
try:
task = Task.query.get(task_id)
except:
return render_template('response.html', response = 'Task not found, bad URL')
return render_template('pages/response.html', response = 'Task not found, bad URL')
if task is None:
return render_template('response.html', response = 'Task not found, bad URL')
return render_template('pages/response.html', response = 'Task not found, bad URL')
users = gettaskusers(task_id)
if request.method == 'GET':
return render_template("project.html", task = task, users = users)
return render_template("pages/project.html", task = task, users = users)
elif request.method == 'POST':
# Assigning user to task
username = request.form['username']
for user in users:
if username == user.username:
return render_template('response.html', response = 'User already added to task')
return render_template('pages/response.html', response = 'User already added to task')
try:
userid = User.query.filter_by(username = username).first().id
except:
return render_template('response.html', response = 'User not found, please register.')
return render_template('pages/response.html', response = 'User not found, please register.')
if userid is None:
return render_template('response.html', response = 'User not found, please register.')
return render_template('pages/response.html', response = 'User not found, please register.')
sqladduser = TaskUser(userid = userid, taskid = task_id)
try:
db.session.add(sqladduser)
db.session.commit()
return render_template('response.html', response = 'User added')
return render_template('pages/response.html', response = 'User added')
except:
return render_template('response.html', response = 'Adding user failed')
return render_template('pages/response.html', response = 'Adding user failed')
@app.route('/projects/<int:task_id>/del', methods=['GET','POST'])
def deltask(task_id:int):
try:
task = Task.query.get(task_id)
except:
return render_template('response.html', response = 'Task not found, bad URL')
return render_template('pages/response.html', response = 'Task not found, bad URL')
if task is None:
return render_template('response.html', response = 'Task not found, bad URL')
return render_template('pages/response.html', response = 'Task not found, bad URL')
try:
taskusers = TaskUser.query.filter_by(taskid = task_id).all()
except:
@ -147,35 +146,35 @@ def deltask(task_id:int):
db.session.delete(task)
db.session.commit()
except:
return render_template('response.html', response = 'Deleting task failed')
return render_template('pages/response.html', response = 'Deleting task failed')
try:
if taskusers != None:
for taskuser in taskusers:
db.session.delete(taskuser)
db.session.commit()
except:
return render_template('response.html', response = 'Deleting user assignment to task failed')
return render_template('response.html', response = 'Task deleted')
return render_template('pages/response.html', response = 'Deleting user assignment to task failed')
return render_template('pages/response.html', response = 'Task deleted')
else:
return render_template('deltask.html', task = task)
return render_template('pages/deltask.html', task = task)
if request.method == 'POST':
password = request.form['password']
if len(password) < 1 or len(password) > 500:
return render_template('response.html', response = "Password lenght invalid, only smaller then 500 charachters allowed")
return render_template('pages/response.html', response = "Password lenght invalid, only smaller then 500 charachters allowed")
# Check password
if password != ADMINPASS and password != User.query.get(creatorid).password:
return render_template('response.html', response = 'Wrong password')
return render_template('pages/response.html', response = 'Wrong password')
# Delete task
try:
db.session.delete(task)
db.session.commit()
except:
return render_template('response.html', response = 'Deleting task failed')
return render_template('pages/response.html', response = 'Deleting task failed')
try:
if taskusers != None:
for taskuser in taskusers:
db.session.delete(taskuser)
db.session.commit()
except:
return render_template('response.html', response = 'Deleting user assignment to task failed')
return render_template('response.html', response = 'Task deleted')
return render_template('pages/response.html', response = 'Deleting user assignment to task failed')
return render_template('pages/response.html', response = 'Task deleted')

View File

@ -0,0 +1,2 @@
<footer>
</footer>

View File

@ -0,0 +1,8 @@
<header>
<nav class="container">
<ul>
<li class="current"><a href="/">Home</a></li>
<li><a href="/register">Register</a></li>
</ul>
</nav>
</header>

View File

@ -0,0 +1,31 @@
{% extends "layouts/base.html" %}
{% block content %}
<header>
<nav class="container">
<ul>
<li class="current"><a href="/">Home</a></li>
<li><a href="/register">Register</a></li>
</ul>
</nav>
</header>
<main class="container page page-index">
<section>
<div class="btn">
<a href="/addtask">Add new task</a>
</div>
<div class="tasks-wrap">
<h1>Tasks</h1>
{% for task in tasks %}
<div class="task">
<a href="/projects/{{task.id}}">
<div>{{task.id}}.</div>
<div>{{task.name}}</div>
</a>
</div>
{% endfor %}
</div>
</section>
</main>
<footer>
</footer>
{% endblock content %}

View File

@ -0,0 +1,15 @@
<!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 manager</title>
</head>
<body>
{% include "includes/header.html" %}
{% block content %}
{% endblock content %}
{% include "includes/footer.html" %}
</body>
</html>

View File

@ -0,0 +1,25 @@
{% extends "layouts/base.html" %}
{% block content %}
<main class="container page page-addtask">
<h1>Create new task</h1>
<div class="form-wrap">
<form action="/addtask" method="POST">
<div class="form-input">
<label for="taskname" class="label">Task name:</label>
<input type="text" name="taskname" id="taskname" required />
</div>
<div class="form-input">
<label for="taskdesc" class="label">Description:</label>
<input type="text" name="taskdesc" id="taskdesc" placeholder="optional"/>
</div>
<div class="form-input">
<label for="username" class="label">Username:</label>
<input type="text" name="username" id="username" placeholder="optional"/>
</div>
<div class="btn-wrap">
<button class="btn">Submit</button>
</div>
</div>
</form>
</main>
{% endblock content %}

View File

@ -0,0 +1,19 @@
{% extends "layouts/base.html" %}
{% block content %}
<body>
<main class="container page page-addtask">
<h1>Create new task</h1>
<div class="form-wrap">
<form action="/projects/{{task.id}}/del" method="POST">
<p> Task creator's password <p>
<div class="form-input">
<label for="password" class="label">password:</label>
<input type="password" name="password" id="password" required />
</div>
<div class="btn-wrap">
<button class="btn">DELETE</button>
</div>
</div>
</form>
</main>
{% endblock content %}

View File

@ -0,0 +1,21 @@
{% extends "layouts/base.html" %}
{% block content %}
<main class="container page page-index">
<section>
<div class="btn">
<a href="/addtask">Add new task</a>
</div>
<div class="tasks-wrap">
<h1>Tasks</h1>
{% for task in tasks %}
<div class="task">
<a href="/projects/{{task.id}}">
<div>{{task.id}}.</div>
<div>{{task.name}}</div>
</a>
</div>
{% endfor %}
</div>
</section>
</main>
{% endblock content %}

View File

@ -0,0 +1,36 @@
{% extends "layouts/base.html" %}
{% block content %}
<main class="container page page-project">
<section >
<h1>{{task.name}}</h1>
<label class="label underline">Description</label>
<p>{{task.desc}}</p>
</section>
<section class="section-task">
<div>
<label class="label underline">Users added to this task</label>
{% for user in users %}
<div class="user-info-wrap">
<div><b>Username:</b> {{user.username}}</div>
<div><b>Contact info:</b> {{user.contact}}</div>
</div>
{% endfor %}
</div>
<div>
<label class="label underline"> Add person to task</label>
<div class="form-wrap">
<form action="/projects/{{task.id}}" method="POST">
<div class="form-input">
<label for="username" class="label">Username:</label>
<input type="text" name="username" id="username" required />
</div>
<div class="btn-wrap">
<button class="btn">Submit</button>
</div>
</form>
<p><a href="/projects/{{task.id}}/del">DELETE TASK</a><p>
</div>
</div>
</section>
</main>
{% endblock content %}

View File

@ -0,0 +1,24 @@
{% extends "layouts/base.html" %}
{% block content %}
<main class="container page page-register">
<div class="form-wrap">
<form action="/register" method="POST">
<div class="form-input">
<label for="username">Username:</label>
<input type="text" name="username" id="username" required />
</div>
<div class="form-input">
<label for="contact">Contact:</label>
<input type="text" name="contact" id="contact" required />
</div>
<div class="form-input">
<label for="password">Password:</label>
<input type="password" name="password" placeholder="optional" id="password"/>
</div>
<div class="btn-wrap">
<button class="btn">Submit</button>
</div>
</form>
</div>
</main>
{% endblock content %}

View File

@ -0,0 +1,8 @@
{% extends "layouts/base.html" %}
{% block content %}
<main class="container page page-project">
<section >
<p>{{response}}<p>
</section>
</main>
{% endblock content %}