From d06edf7e9cf40edc525c9829c8ebeab92cf6fc20 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Thu, 18 Mar 2021 23:20:59 +0100 Subject: [PATCH] Added some routes, untils.py, some initial html pages and Bootsrap --- advlabdb/routes.py | 35 ++++++++++++++++++++++++++- advlabdb/templates/appointments.html | 3 +++ advlabdb/templates/assistants.html | 3 +++ advlabdb/templates/experiments.html | 3 +++ advlabdb/templates/groups.html | 3 +++ advlabdb/templates/index.html | 4 ++++ advlabdb/templates/layout.html | 36 ++++++++++++++++++++++++++++ advlabdb/templates/students.html | 3 +++ advlabdb/templates/users.html | 3 +++ advlabdb/utils.py | 10 ++++++++ poetry.lock | 4 ++-- pyproject.toml | 2 +- testDB.py | 14 +++++++---- 13 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 advlabdb/templates/appointments.html create mode 100644 advlabdb/templates/assistants.html create mode 100644 advlabdb/templates/experiments.html create mode 100644 advlabdb/templates/groups.html create mode 100644 advlabdb/templates/index.html create mode 100644 advlabdb/templates/layout.html create mode 100644 advlabdb/templates/students.html create mode 100644 advlabdb/templates/users.html create mode 100644 advlabdb/utils.py diff --git a/advlabdb/routes.py b/advlabdb/routes.py index 1237ced..338220d 100644 --- a/advlabdb/routes.py +++ b/advlabdb/routes.py @@ -1,5 +1,38 @@ from advlabdb import app +from flask import render_template, request, url_for +from advlabdb.utils import * @app.route("/") def index(): - return "Welcome on AdvLabDB!" \ No newline at end of file + page = "index" + return render_template(page + ".html", navbarItems=navbarItems(page)) + +@app.route("/students") +def students(): + page = "students" + return render_template(page + ".html", navbarItems=navbarItems(page)) + +@app.route("/assistants") +def assistants(): + page = "assistants" + return render_template(page + ".html", navbarItems=navbarItems(page)) + +@app.route("/experiments") +def experiments(): + page = "experiments" + return render_template(page + ".html", navbarItems=navbarItems(page)) + +@app.route("/appointments") +def appointments(): + page = "appointments" + return render_template(page + ".html", navbarItems=navbarItems(page)) + +@app.route("/groups") +def groups(): + page = "groups" + return render_template(page + ".html", navbarItems=navbarItems(page)) + +@app.route("/users") +def users(): + page = "users" + return render_template(page + ".html", navbarItems=navbarItems(page)) diff --git a/advlabdb/templates/appointments.html b/advlabdb/templates/appointments.html new file mode 100644 index 0000000..39e893d --- /dev/null +++ b/advlabdb/templates/appointments.html @@ -0,0 +1,3 @@ +{% extends "layout.html" %} +{% block content %} +{% endblock content %} diff --git a/advlabdb/templates/assistants.html b/advlabdb/templates/assistants.html new file mode 100644 index 0000000..39e893d --- /dev/null +++ b/advlabdb/templates/assistants.html @@ -0,0 +1,3 @@ +{% extends "layout.html" %} +{% block content %} +{% endblock content %} diff --git a/advlabdb/templates/experiments.html b/advlabdb/templates/experiments.html new file mode 100644 index 0000000..39e893d --- /dev/null +++ b/advlabdb/templates/experiments.html @@ -0,0 +1,3 @@ +{% extends "layout.html" %} +{% block content %} +{% endblock content %} diff --git a/advlabdb/templates/groups.html b/advlabdb/templates/groups.html new file mode 100644 index 0000000..39e893d --- /dev/null +++ b/advlabdb/templates/groups.html @@ -0,0 +1,3 @@ +{% extends "layout.html" %} +{% block content %} +{% endblock content %} diff --git a/advlabdb/templates/index.html b/advlabdb/templates/index.html new file mode 100644 index 0000000..d2f6365 --- /dev/null +++ b/advlabdb/templates/index.html @@ -0,0 +1,4 @@ +{% extends "layout.html" %} +{% block content %} +Welcome on AdvLabDB! +{% endblock content %} diff --git a/advlabdb/templates/layout.html b/advlabdb/templates/layout.html new file mode 100644 index 0000000..247d43d --- /dev/null +++ b/advlabdb/templates/layout.html @@ -0,0 +1,36 @@ + + + + + + + + + + + {% if title %} + {{title}} + {% else %} + AdvLabDB + {% endif %} + + + + {% block content %}{% endblock content %} + + + + + diff --git a/advlabdb/templates/students.html b/advlabdb/templates/students.html new file mode 100644 index 0000000..39e893d --- /dev/null +++ b/advlabdb/templates/students.html @@ -0,0 +1,3 @@ +{% extends "layout.html" %} +{% block content %} +{% endblock content %} diff --git a/advlabdb/templates/users.html b/advlabdb/templates/users.html new file mode 100644 index 0000000..39e893d --- /dev/null +++ b/advlabdb/templates/users.html @@ -0,0 +1,3 @@ +{% extends "layout.html" %} +{% block content %} +{% endblock content %} diff --git a/advlabdb/utils.py b/advlabdb/utils.py new file mode 100644 index 0000000..25440c6 --- /dev/null +++ b/advlabdb/utils.py @@ -0,0 +1,10 @@ +def navbarItems(activePage): + pages = ["Students", "Assistants", "Experiments", "Appointments", "Groups", "Users"] + items = "" + for page in pages: + active = "" + lowerPage = page.lower().replace(" ", "_") + if lowerPage == activePage: + active = " active" + items += '' + page + '\n' + return items diff --git a/poetry.lock b/poetry.lock index 832f276..4806eef 100644 --- a/poetry.lock +++ b/poetry.lock @@ -101,8 +101,8 @@ watchdog = ["watchdog"] [metadata] lock-version = "1.1" -python-versions = "^3.9" -content-hash = "6bef6d6f4639eb91713858a87c48769c41232753299fd7b5846e7b18f3950ddd" +python-versions = "^3.8" +content-hash = "8462227db94bf1e53825a934934960f64010d387c302dc71a359123acdff0be9" [metadata.files] click = [ diff --git a/pyproject.toml b/pyproject.toml index d119f57..9f55c39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ description = "DB for the advanced physics lab on JGU-Mainz." authors = ["Mohamad Bitar "] [tool.poetry.dependencies] -python = "^3.9" +python = "^3.8" Flask = "^1.1.2" Flask-SQLAlchemy = "^2.4.4" SQLAlchemy = "<1.4" diff --git a/testDB.py b/testDB.py index 530a9cd..e78ef56 100644 --- a/testDB.py +++ b/testDB.py @@ -1,4 +1,4 @@ -from advlabdb import * +from advlabdb import db from advlabdb.models import * from datetime import datetime @@ -37,9 +37,11 @@ db.session.add(ps1) db.session.add(ps2) db.session.add(ps3) -ex1 = Experiment(name="exp", room="123", building="phy", responsibility="none", duration_in_days=2, oral_weighting=0.5, protocol_weighting=0.5, final_weighting=1) +ex1 = Experiment(name="exp", room="123", building="phy", responsibility="none", duration_in_days=2, + oral_weighting=0.5, protocol_weighting=0.5, final_weighting=1) -ex2 = Experiment(name="exp2", room="123", building="phy", responsibility="none", duration_in_days=2, oral_weighting=0.5, protocol_weighting=0.5, final_weighting=1) +ex2 = Experiment(name="exp2", room="123", building="phy", responsibility="none", duration_in_days=2, + oral_weighting=0.5, protocol_weighting=0.5, final_weighting=1) db.session.add(ex1) db.session.add(ex2) @@ -62,9 +64,13 @@ us2 = User(email="test2@test.com", password_hash="h2") db.session.add(us1) db.session.add(us2) -as1 = Assistant(first_name="As1", last_name="l", email="test@test.com", phone_number="012333212", mobile_phone_number="012334123", user=us1) +as1 = Assistant(first_name="As1", last_name="l", email="test@test.com", phone_number="012333212", + mobile_phone_number="012334123", user=us1) as2 = Assistant(first_name="As2", last_name="l", email="test2@test.com", user=us1) +as1.part_experiments.append(px1) +as2.part_experiments.append(px2) + db.session.add(as1) db.session.add(as2)