diff --git a/taskmanager/routes.py b/taskmanager/routes.py index 7711256..6757940 100644 --- a/taskmanager/routes.py +++ b/taskmanager/routes.py @@ -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/', 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//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') diff --git a/taskmanager/templates/includes/footer.html b/taskmanager/templates/includes/footer.html new file mode 100644 index 0000000..5e0ea02 --- /dev/null +++ b/taskmanager/templates/includes/footer.html @@ -0,0 +1,2 @@ +
+
diff --git a/taskmanager/templates/includes/header.html b/taskmanager/templates/includes/header.html new file mode 100644 index 0000000..c944e80 --- /dev/null +++ b/taskmanager/templates/includes/header.html @@ -0,0 +1,8 @@ +
+ +
diff --git a/taskmanager/templates/includes/index.html b/taskmanager/templates/includes/index.html new file mode 100644 index 0000000..f56b9cb --- /dev/null +++ b/taskmanager/templates/includes/index.html @@ -0,0 +1,31 @@ +{% extends "layouts/base.html" %} +{% block content %} +
+ +
+
+
+ +
+

Tasks

+ {% for task in tasks %} + + {% endfor %} +
+
+
+
+
+{% endblock content %} diff --git a/taskmanager/templates/layouts/base.html b/taskmanager/templates/layouts/base.html new file mode 100644 index 0000000..7222138 --- /dev/null +++ b/taskmanager/templates/layouts/base.html @@ -0,0 +1,15 @@ + + + + + + + Task manager + + + {% include "includes/header.html" %} + {% block content %} + {% endblock content %} + {% include "includes/footer.html" %} + + diff --git a/taskmanager/templates/pages/addtask.html b/taskmanager/templates/pages/addtask.html new file mode 100644 index 0000000..26c4a10 --- /dev/null +++ b/taskmanager/templates/pages/addtask.html @@ -0,0 +1,25 @@ +{% extends "layouts/base.html" %} +{% block content %} +
+

Create new task

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ +
+{% endblock content %} diff --git a/taskmanager/templates/pages/deltask.html b/taskmanager/templates/pages/deltask.html new file mode 100644 index 0000000..dd6dd75 --- /dev/null +++ b/taskmanager/templates/pages/deltask.html @@ -0,0 +1,19 @@ +{% extends "layouts/base.html" %} +{% block content %} + +
+

Create new task

+
+
+

Task creator's password

+

+ + +
+
+ +
+
+ +
+{% endblock content %} diff --git a/taskmanager/templates/pages/index.html b/taskmanager/templates/pages/index.html new file mode 100644 index 0000000..f975f60 --- /dev/null +++ b/taskmanager/templates/pages/index.html @@ -0,0 +1,21 @@ +{% extends "layouts/base.html" %} +{% block content %} +
+
+ +
+

Tasks

+ {% for task in tasks %} + + {% endfor %} +
+
+
+{% endblock content %} diff --git a/taskmanager/templates/pages/project.html b/taskmanager/templates/pages/project.html new file mode 100644 index 0000000..96273eb --- /dev/null +++ b/taskmanager/templates/pages/project.html @@ -0,0 +1,36 @@ +{% extends "layouts/base.html" %} +{% block content %} +
+
+

{{task.name}}

+ +

{{task.desc}}

+
+
+
+ + {% for user in users %} + + {% endfor %} +
+
+ +
+
+
+ + +
+
+ +
+
+

DELETE TASK

+

+
+
+
+{% endblock content %} diff --git a/taskmanager/templates/pages/register.html b/taskmanager/templates/pages/register.html new file mode 100644 index 0000000..078c8b2 --- /dev/null +++ b/taskmanager/templates/pages/register.html @@ -0,0 +1,24 @@ +{% extends "layouts/base.html" %} +{% block content %} +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+{% endblock content %} diff --git a/taskmanager/templates/pages/response.html b/taskmanager/templates/pages/response.html new file mode 100644 index 0000000..2eb65e3 --- /dev/null +++ b/taskmanager/templates/pages/response.html @@ -0,0 +1,8 @@ +{% extends "layouts/base.html" %} +{% block content %} +
+
+

{{response}}

+

+
+{% endblock content %}