1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-09-17 18:31:15 +00:00

Added login/logout, edited navbar and updated packages

This commit is contained in:
Mo 2021-04-16 14:21:53 +02:00
parent 8d690a1476
commit 0f95b1ca35
3 changed files with 110 additions and 64 deletions

View file

@ -1,6 +1,6 @@
from advlabdb import app, user_datastore
from flask import render_template, request, url_for, flash, redirect
from flask_security import auth_required, roles_required, hash_password
from flask_security import auth_required, roles_required, hash_password, current_user
from advlabdb.utils import *
from advlabdb.models import *
@ -19,11 +19,27 @@ def util_processor():
str(semester.id) + '">' + semester.label + '</a></li>')
return items
pages = ["Index", "Students", "Assistants", "Experiments", "Appointments", "Groups", "Users", "Semesters"]
def navbarItems(title):
adminPages = ["Students", "Assistants", "Experiments", "Appointments", "Groups", "Users", "Semesters"]
assistantPages = ["Students", "Assistants", "Experiments", "Appointments", "Groups"]
if current_user.is_authenticated:
roleNames = [role.name for role in current_user.roles]
if "assistant" in roleNames:
pages = assistantPages
if "admin" in roleNames:
for p in adminPages:
if p not in pages:
pages.append(p)
elif "admin" in roleNames:
pages = adminPages
pages.append("Logout")
else:
pages = ["Login"]
items = []
for page in pages[1:]:
for page in pages:
if page == title:
active = " active"
else:
@ -34,8 +50,9 @@ def util_processor():
return dict(semesterDropDownItems=semesterDropDownItems,
activeSemesterLabel=Semester.query.get(activeSemester_id).label,
pages=pages,
navbarItems=navbarItems)
navbarItems=navbarItems,
current_user=current_user,
)
@app.route("/")
@ -43,7 +60,9 @@ def index():
global activeSemester_id
activeSemester_id = Semester.query.all()[-1].id
title = "Index"
return render_template(titleToTemplate(title) + ".html", title=title)
return render_template(titleToTemplate(title) + ".html",
title=title,
)
@app.route("/students")
@ -71,8 +90,11 @@ def students():
tables.append(makeTable(headerAndDataList=headerAndDataList,
rows=part.part_students))
title = "Students"
return render_template(titleToTemplate(title) + ".html", title=title,
tables=tables, tablesLabels=tablesLabels)
return render_template(titleToTemplate(title) + ".html",
title=title,
tables=tables,
tablesLabels=tablesLabels,
)
@app.route("/assistants")
@ -93,8 +115,10 @@ def assistants():
rows=Assistant.query.filter(Assistant.user_id != None).all())
title = "Assistants"
return render_template(titleToTemplate(title) + ".html", title=title,
table=table)
return render_template(titleToTemplate(title) + ".html",
title=title,
table=table,
)
@app.route("/experiments")
@ -116,15 +140,20 @@ def experiments():
rows=part.part_experiments))
title = "Experiments"
return render_template(titleToTemplate(title) + ".html", title=title,
tables=tables, tablesLabels=tablesLabels)
return render_template(titleToTemplate(title) + ".html",
title=title,
tables=tables,
tablesLabels=tablesLabels,
)
@app.route("/appointments")
@roles_required("admin")
def appointments():
title = "Appointments"
return render_template(titleToTemplate(title) + ".html", title=title)
return render_template(titleToTemplate(title) + ".html",
title=title,
)
@app.route("/groups")
@ -147,8 +176,11 @@ def groups():
rows=part.groups))
title = "Groups"
return render_template(titleToTemplate(title) + ".html", title=title,
tables=tables, tablesLabels=tablesLabels)
return render_template(titleToTemplate(title) + ".html",
title=title,
tables=tables,
tablesLabels=tablesLabels,
)
@app.route("/users")
@ -162,8 +194,10 @@ def users():
rows=User.query.all())
title = "Users"
return render_template(titleToTemplate(title) + ".html", title=title,
table=table)
return render_template(titleToTemplate(title) + ".html",
title=title,
table=table,
)
@app.route("/set_semester", methods=["GET"])
@ -172,7 +206,9 @@ def set_semester():
global activeSemester_id
activeSemester_id = int(request.args.get("semester_id"))
title = "Index"
return render_template(titleToTemplate(title) + ".html", title=title)
return render_template(titleToTemplate(title) + ".html",
title=title,
)
@app.route("/semesters")
@ -185,8 +221,10 @@ def semesters():
rows=Semester.query.all())
title = "Semesters"
return render_template(titleToTemplate(title) + ".html", title=title,
table=table)
return render_template(titleToTemplate(title) + ".html",
title=title,
table=table,
)
@app.route("/register", methods=["GET", "POST"])
@ -203,6 +241,13 @@ def register():
user_datastore.create_user(email=email, password=passwordHash, roles=roles)
db.session.commit()
return render_template("registered.html", title="Registered",
email=email, password=password, admin=admin)
return render_template("register.html", title="Register", form=form)
return render_template("registered.html",
title="Registered",
email=email,
password=password,
admin=admin,
)
return render_template("register.html",
title="Register",
form=form,
)

View file

@ -22,7 +22,6 @@
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="{{url_for('index')}}">AdvLabDB</a>
{% if title in pages %}
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
@ -33,6 +32,7 @@
{{item|safe}}
</li>
{% endfor %}
{% if current_user.is_authenticated %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Semester {{activeSemesterLabel}}
@ -43,9 +43,9 @@
{% endfor %}
</ul>
</li>
{% endif %}
</ul>
</div>
{% endif %}
</div>
</nav>
<div class="container-fluid">

77
poetry.lock generated
View file

@ -85,13 +85,14 @@ Flask = "*"
[[package]]
name = "flask-security-too"
version = "4.0.0"
version = "4.0.1"
description = "Simple security for Flask apps."
category = "main"
optional = false
python-versions = ">=3.6"
[package.dependencies]
blinker = ">=1.4"
email-validator = ">=1.1.1"
Flask = ">=1.1.1"
Flask-Login = ">=0.4.1"
@ -190,7 +191,7 @@ totp = ["cryptography"]
[[package]]
name = "sqlalchemy"
version = "1.4.5"
version = "1.4.8"
description = "Database Abstraction Library"
category = "main"
optional = false
@ -280,8 +281,8 @@ flask-principal = [
{file = "Flask-Principal-0.4.0.tar.gz", hash = "sha256:f5d6134b5caebfdbb86f32d56d18ee44b080876a27269560a96ea35f75c99453"},
]
flask-security-too = [
{file = "Flask-Security-Too-4.0.0.tar.gz", hash = "sha256:4aa0a076fe0faabf01017d727e81fce0800170ce1cbf01534d16549fa6464d87"},
{file = "Flask_Security_Too-4.0.0-py2.py3-none-any.whl", hash = "sha256:1d8388e05e46eb74f33d779d2aa6bcf55622437b650656850dcb777200c2bee6"},
{file = "Flask-Security-Too-4.0.1.tar.gz", hash = "sha256:c2967fce08cbe2a1c6ada8eaafc717626d90f296efa7a17f859c13f46bfef1e0"},
{file = "Flask_Security_Too-4.0.1-py2.py3-none-any.whl", hash = "sha256:3ca961b2daebeced863af5477e1c61626d14408eab68061dd9fea889e900e5bb"},
]
flask-sqlalchemy = [
{file = "Flask-SQLAlchemy-2.5.1.tar.gz", hash = "sha256:2bda44b43e7cacb15d4e05ff3cc1f8bc97936cc464623424102bfc2c35e95912"},
@ -407,40 +408,40 @@ passlib = [
{file = "passlib-1.7.4.tar.gz", hash = "sha256:defd50f72b65c5402ab2c573830a6978e5f202ad0d984793c8dde2c4152ebe04"},
]
sqlalchemy = [
{file = "SQLAlchemy-1.4.5-cp27-cp27m-macosx_10_14_x86_64.whl", hash = "sha256:c3810ebcf1d42c532c8f5c3f442c705d94442a27a32f2df5344f0857306ab321"},
{file = "SQLAlchemy-1.4.5-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:7481f9c2c832a3bf37c80bee44d91ac9938b815cc06f7e795b976e300914aab9"},
{file = "SQLAlchemy-1.4.5-cp27-cp27m-win32.whl", hash = "sha256:94040a92b6676f9ffdab6c6b479b3554b927a635c90698c761960b266b04fc88"},
{file = "SQLAlchemy-1.4.5-cp27-cp27m-win_amd64.whl", hash = "sha256:02b039e0e7e6de2f15ea2d2de3995e31a170e700ec0b37b4eded662171711d19"},
{file = "SQLAlchemy-1.4.5-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:f16801795f1ffe9472360589a04301018c79e4582a85e68067275bb4f765e4e2"},
{file = "SQLAlchemy-1.4.5-cp36-cp36m-macosx_10_14_x86_64.whl", hash = "sha256:82f11b679df91275788be6734dd4a9dfa29bac67b85326992609f62b05bdab37"},
{file = "SQLAlchemy-1.4.5-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:a08027ae84efc563f0f2f341dda572eadebeca38c0ae028a009988f27e9e6230"},
{file = "SQLAlchemy-1.4.5-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:70a1387396ea5b3022539b560c287daf79403d8b4b365f89b56d660e625a4457"},
{file = "SQLAlchemy-1.4.5-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:4f7ce3bfdab6520554af4a5b1df4513d45388624d015ba4d921daf48ce1d6503"},
{file = "SQLAlchemy-1.4.5-cp36-cp36m-manylinux2014_x86_64.whl", hash = "sha256:08943201a1e3c6238e48f4d5d56c27ea1e1b39d3d9f36a9d81fc3cfb0e1b83bd"},
{file = "SQLAlchemy-1.4.5-cp36-cp36m-win32.whl", hash = "sha256:fbb0fda1c574975807aceb0e2332e0ecfe9e5656c191ed482c1a5eafe7a33823"},
{file = "SQLAlchemy-1.4.5-cp36-cp36m-win_amd64.whl", hash = "sha256:8d6a9feb5efd2fdab25c6d5a0a5589fed9d789f5ec57ec12263fd0e60ce1dea6"},
{file = "SQLAlchemy-1.4.5-cp37-cp37m-macosx_10_14_x86_64.whl", hash = "sha256:c22bfac8d3b955cdb13f0fcd6343156bf56d925196cf7d9ab9ce9f61d3f1e11c"},
{file = "SQLAlchemy-1.4.5-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:7c0c7bb49167ac738ca6ee6e7f94a9988a7e4e261d8da335341e8c8c8f3b2e9b"},
{file = "SQLAlchemy-1.4.5-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:344b58b4b4193b72e8b768a51ef6eb5a4c948ce313a0f23e2ea081e71ce8ac0e"},
{file = "SQLAlchemy-1.4.5-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:48540072f43b3c080159ec1f24a4b014c0ee83d3b73795399974aa358a8cf71b"},
{file = "SQLAlchemy-1.4.5-cp37-cp37m-manylinux2014_x86_64.whl", hash = "sha256:81badd7d3e0e6aba70a5d1b50fabe8112e9835a6fdb0684054c3fe5378ce0d01"},
{file = "SQLAlchemy-1.4.5-cp37-cp37m-win32.whl", hash = "sha256:a103294583383660d9e06dbd82037dc8e94c184bdcb27b2be44ae4457dafc6b4"},
{file = "SQLAlchemy-1.4.5-cp37-cp37m-win_amd64.whl", hash = "sha256:5361e25181b9872d6906c8c9be7dc05cb0a0951d71ee59ee5a71c1deb301b8a8"},
{file = "SQLAlchemy-1.4.5-cp38-cp38-macosx_10_14_x86_64.whl", hash = "sha256:7f5087104c3c5af11ea59e49ae66c33ca98b14a47d3796ae97498fca53f84aef"},
{file = "SQLAlchemy-1.4.5-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:11e7a86209f69273e75d2dd64b06c0c2660e39cd942fce2170515c404ed7358a"},
{file = "SQLAlchemy-1.4.5-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:8301ecf3e819eb5dbc171e84654ff60872807775301a55fe35b0ab2ba3742031"},
{file = "SQLAlchemy-1.4.5-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:44e11a06168782b6d485daef197783366ce7ab0d5eea0066c899ae06cef47bbc"},
{file = "SQLAlchemy-1.4.5-cp38-cp38-manylinux2014_x86_64.whl", hash = "sha256:6f8fdad2f335d2f3ca2f3ee3b01404f7abcf519b03de2c510f1f42d16e39ffb4"},
{file = "SQLAlchemy-1.4.5-cp38-cp38-win32.whl", hash = "sha256:f62c57ceadedeb8e7b98b48ac4d684bf2b0f73b9d882fed3ca260d9aedf6403f"},
{file = "SQLAlchemy-1.4.5-cp38-cp38-win_amd64.whl", hash = "sha256:301d0cd6ef1dc73b607748183da857e712d6f743de8d92b1e1f8facfb0ba2aa2"},
{file = "SQLAlchemy-1.4.5-cp39-cp39-macosx_10_14_x86_64.whl", hash = "sha256:915d4fa08776c0252dc5a34fa15c6490f66f411ea1ac9492022f98875d6baf20"},
{file = "SQLAlchemy-1.4.5-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:7de84feb31af3d8fdf819cac2042928d0b60d3cb16f49c4b2f48d88db46e79f6"},
{file = "SQLAlchemy-1.4.5-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:45b091ccbf94374ed14abde17e9a04522b0493a17282eaaf4383efdd413f5243"},
{file = "SQLAlchemy-1.4.5-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:4df07161897191ed8d4a0cfc92425c81296160e5c5f76c9256716d3085172883"},
{file = "SQLAlchemy-1.4.5-cp39-cp39-manylinux2014_x86_64.whl", hash = "sha256:ee4ddc904fb6414b5118af5b8d45e428aac2ccda01326b2ba2fe4354b0d8d1ae"},
{file = "SQLAlchemy-1.4.5-cp39-cp39-win32.whl", hash = "sha256:2f11b5783933bff55291ca06496124347627d211ff2e509e846af1c35de0a3fb"},
{file = "SQLAlchemy-1.4.5-cp39-cp39-win_amd64.whl", hash = "sha256:0ee0054d4a598d2920cae14bcbd33e200e02c5e3b47b902627f8cf5d4c9a2a4b"},
{file = "SQLAlchemy-1.4.5.tar.gz", hash = "sha256:1294f05916c044631fd626a4866326bbfbd17f62bd37510d000afaef4b35bd74"},
{file = "SQLAlchemy-1.4.8-cp27-cp27m-macosx_10_14_x86_64.whl", hash = "sha256:dec822c2a9436092798998475b3b8edd0d59be7fecdd5fb8411ac8db1575ed64"},
{file = "SQLAlchemy-1.4.8-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:15480706c51bdf72d726d0efde77eef6b5f09fbef65bc520f2c4e1f3a429fddf"},
{file = "SQLAlchemy-1.4.8-cp27-cp27m-win32.whl", hash = "sha256:221ead411c5e455bbe32b8eb2e8521a31a0769684a93b6895e515e9ce3a49906"},
{file = "SQLAlchemy-1.4.8-cp27-cp27m-win_amd64.whl", hash = "sha256:46a454a366f6274c18d3204d11b9e4b98a5c99cba99230e24848d82bef069f75"},
{file = "SQLAlchemy-1.4.8-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:81ea6270359629b9c56251bdfc12f2a8afb55034a3ff3698b6a764b300bfe605"},
{file = "SQLAlchemy-1.4.8-cp36-cp36m-macosx_10_14_x86_64.whl", hash = "sha256:831aa088b0056b8040423c53543b5bf5663d1d5ffbc175387f2216de7780113e"},
{file = "SQLAlchemy-1.4.8-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:b8280da3f36b9156ff251a14e5a3e82a4bb58958bdddbd0867cd29e6f3f809de"},
{file = "SQLAlchemy-1.4.8-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:767c0bbe5af14c2ebcad7314faea9709b59593daa3250fe6224429a344c21438"},
{file = "SQLAlchemy-1.4.8-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:8a067fbf3ea3f53e4223990d92a8e44259571ef182039ddcb4ffcf217e08a901"},
{file = "SQLAlchemy-1.4.8-cp36-cp36m-manylinux2014_x86_64.whl", hash = "sha256:43b4958d959b1ee00540b963620f6bffacdd8ac0a19d31450828a1cbacf3693c"},
{file = "SQLAlchemy-1.4.8-cp36-cp36m-win32.whl", hash = "sha256:b6106343fb97771f20cd945ce6b1d07f8247121d1d4baad062c028e5f0a1f034"},
{file = "SQLAlchemy-1.4.8-cp36-cp36m-win_amd64.whl", hash = "sha256:fc5dea79bd2626ee2ed034144f6c590441e7c8c036c57c1939ec4a18481c0de1"},
{file = "SQLAlchemy-1.4.8-cp37-cp37m-macosx_10_14_x86_64.whl", hash = "sha256:1dc4f31124cc359065dceef1a9afe4e2d07a05b2e1e184f5fa48cba96c2249a3"},
{file = "SQLAlchemy-1.4.8-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:c1457a86209c56dfdd1a62904445bc727f962226bf8866f3834fffff8bd7282d"},
{file = "SQLAlchemy-1.4.8-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:ddc9de7e46e8044099a94b8d8b92b02693df030ca8684aa775908295270a3556"},
{file = "SQLAlchemy-1.4.8-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:6d18aec6f16b48b2903940776d0f455d82b0c35f4b307ae5393987c600f8fcda"},
{file = "SQLAlchemy-1.4.8-cp37-cp37m-manylinux2014_x86_64.whl", hash = "sha256:64a6645ee39f45f153b45addace5727aef7eb517b115c8bdc77e02be8c8c43a3"},
{file = "SQLAlchemy-1.4.8-cp37-cp37m-win32.whl", hash = "sha256:d37683c5d84f0694f159a2a515a34f81daf7da96e7efb9ba9d5daf4ae8dde47e"},
{file = "SQLAlchemy-1.4.8-cp37-cp37m-win_amd64.whl", hash = "sha256:de2e700a2e98b4c621976fdb3174e9e5947c38efedcf60e6d7c20cc7dddb3a99"},
{file = "SQLAlchemy-1.4.8-cp38-cp38-macosx_10_14_x86_64.whl", hash = "sha256:e7a4bcb79aa64f1bf995dc2f5966fccc7d21b99cdfb63b57c609cfdba2ea5906"},
{file = "SQLAlchemy-1.4.8-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:fccd2de1b3b47ca62c2fa5d344e16266a6edc8cce8b80f32e40126df60dbd2c4"},
{file = "SQLAlchemy-1.4.8-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:ed660a67c0d8690078560d62767a69b359409863827b367167f18fa14ca51ff6"},
{file = "SQLAlchemy-1.4.8-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:fe2558be48c92a9be69bd9e7c41bfc46714c5eafc4d59f85fdc338d6999c4962"},
{file = "SQLAlchemy-1.4.8-cp38-cp38-manylinux2014_x86_64.whl", hash = "sha256:859cf5aae0ecc1aa526f9cebdf6ae8078527f0f3aa3fb10156ecc1d044c1c545"},
{file = "SQLAlchemy-1.4.8-cp38-cp38-win32.whl", hash = "sha256:4b0404b7a18658d5661120ae0f6f57b220c57126d07a067bfdff304d4c50eaa3"},
{file = "SQLAlchemy-1.4.8-cp38-cp38-win_amd64.whl", hash = "sha256:49a85c143f90c74b1d000506e125476d4dec3342f8052ad98e007fb5c657c46c"},
{file = "SQLAlchemy-1.4.8-cp39-cp39-macosx_10_14_x86_64.whl", hash = "sha256:29e135f8c890c16251162dd40022074430fc39668c8666220a73cb500a3697af"},
{file = "SQLAlchemy-1.4.8-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:a7641c8a2d008ee8cef21d3b9eaf7f68259b965318055148fbc5ae6961ae287e"},
{file = "SQLAlchemy-1.4.8-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:aa470facb52b927a5a5a1a4755b1452f7e77dcf93e822077354075e7a811bec2"},
{file = "SQLAlchemy-1.4.8-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:76354282fbb3e5b33aee8fcfc2394c7b26d08c53025960d41abc57a6222321cc"},
{file = "SQLAlchemy-1.4.8-cp39-cp39-manylinux2014_x86_64.whl", hash = "sha256:cb08be4a43ce6729b37efb95816258b00bbd3442eef4a740c09384fb9fe99076"},
{file = "SQLAlchemy-1.4.8-cp39-cp39-win32.whl", hash = "sha256:eff2c66e930030110a6139b0374013fa1f1a397a67a0c8a1a5d387ca2a112b45"},
{file = "SQLAlchemy-1.4.8-cp39-cp39-win_amd64.whl", hash = "sha256:1e1c2c65f732f7740d184b4133e5207c0f8974663ab1b79ce1b599ecf55bd3e9"},
{file = "SQLAlchemy-1.4.8.tar.gz", hash = "sha256:3bc31ad707f8587c9f93d50cd7cee80ba352162d322808ddbb5bcb5fcfd2bb83"},
]
werkzeug = [
{file = "Werkzeug-1.0.1-py2.py3-none-any.whl", hash = "sha256:2de2a5db0baeae7b2d2664949077c2ac63fbd16d98da0ff71837f7d1dea3fd43"},