mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Fixed active semester, added StudentModelView
This commit is contained in:
parent
c86091fe39
commit
48fda40c2c
6 changed files with 43 additions and 26 deletions
File diff suppressed because one or more lines are too long
|
@ -8,6 +8,10 @@ from advlabdb import admin, app, user_datastore, db
|
|||
from advlabdb.models import *
|
||||
from advlabdb.utils import randomPassword
|
||||
|
||||
|
||||
partsLabels = ["A/1", "A/2", "B/1", "B/2"]
|
||||
|
||||
|
||||
class UserModelView(SecureModelView):
|
||||
column_list = ["email", "active", "roles", "assistant"]
|
||||
column_searchable_list = ["email"]
|
||||
|
@ -40,10 +44,8 @@ class SemesterModelView(SecureModelView):
|
|||
column_list = ["label", "parts"]
|
||||
form_columns = ["label", "create_parts"]
|
||||
|
||||
parts = ["A/1", "A/2", "B/1", "B/2"]
|
||||
|
||||
form_extra_fields = {
|
||||
"create_parts": BooleanField("Create parts:" + ", ".join(parts) + ".", default=True)
|
||||
"create_parts": BooleanField("Create parts:" + ", ".join(partsLabels) + ".", default=True)
|
||||
}
|
||||
|
||||
def after_model_change(self, form, model, is_created):
|
||||
|
@ -58,7 +60,16 @@ class PartModelView(SecureModelView):
|
|||
column_details_list = ["label", "semester", "part_experiments", "part_students", "groups"]
|
||||
form_columns = ["label", "semester"]
|
||||
|
||||
admin.add_view(SecureModelView(Student, db.session))
|
||||
|
||||
class StudentModelView(SecureModelView):
|
||||
can_view_details = True
|
||||
column_list = ["student_number", "first_name", "last_name", "email", "part_students"]
|
||||
column_details_list = column_list + ["bachelor_thesis", "bachelor_thesis_work_group"]
|
||||
column_searchable_list = ["student_number", "email", "first_name", "last_name"]
|
||||
form_columns = column_list
|
||||
|
||||
|
||||
admin.add_view(StudentModelView(Student, db.session))
|
||||
admin.add_view(SecureModelView(PartStudent, db.session))
|
||||
admin.add_view(SecureModelView(Group, db.session))
|
||||
admin.add_view(SecureModelView(GroupExperiment, db.session))
|
||||
|
|
|
@ -134,7 +134,7 @@ class Part(db.Model):
|
|||
|
||||
class Semester(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
label = db.Column(db.String(100), nullable=False) # WS2122 for example
|
||||
label = db.Column(db.String(100), nullable=False, unique=True) # WS2122 for example
|
||||
parts = db.relationship("Part", backref="semester", lazy=True)
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -154,6 +154,7 @@ class ExperimentMark(db.Model):
|
|||
|
||||
class User(db.Model, FsUserMixin):
|
||||
assistant = db.relationship("Assistant", backref="user", lazy=True, uselist=False)
|
||||
active_semester_id = db.Column(db.Integer, nullable=True)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<User {self.email}>"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import json
|
||||
from advlabdb import app, user_datastore
|
||||
from flask import render_template, request, url_for, flash, redirect, session
|
||||
from flask import render_template, request, url_for, flash, redirect
|
||||
from flask_security import auth_required, roles_required, hash_password, current_user
|
||||
|
||||
from advlabdb.utils import *
|
||||
|
@ -18,19 +18,6 @@ def util_processor():
|
|||
str(semester.id) + '">' + semester.label + '</a></li>')
|
||||
return items
|
||||
|
||||
def activeSemesterLabel():
|
||||
lastSemesterId = Semester.query.all()[-1].id
|
||||
if "activeSemesterId" not in session:
|
||||
session["activeSemesterId"] = lastSemesterId
|
||||
elif session["activeSemesterId"] != lastSemesterId:
|
||||
activeSemester = Semester.query.get(session['activeSemesterId'])
|
||||
if activeSemester:
|
||||
flash(f"You are in the old semester {activeSemester.label}!", "warning")
|
||||
else:
|
||||
flash(f"Semester changed!", "warning")
|
||||
session["activeSemesterId"] = lastSemesterId
|
||||
return Semester.query.get(session["activeSemesterId"]).label
|
||||
|
||||
def navbarItems(title):
|
||||
adminPages = ["Students", "Assistants", "Experiments", "Appointments", "Groups", "Users", "Semesters"]
|
||||
assistantPages = ["Students", "Assistants", "Experiments", "Appointments", "Groups"]
|
||||
|
@ -61,7 +48,7 @@ def util_processor():
|
|||
return items
|
||||
|
||||
return dict(semesterDropDownItems=semesterDropDownItems,
|
||||
activeSemesterLabel=activeSemesterLabel,
|
||||
userActiveSemester=userActiveSemester,
|
||||
navbarItems=navbarItems,
|
||||
current_user=current_user,
|
||||
)
|
||||
|
@ -76,7 +63,7 @@ def index():
|
|||
@app.route("/students")
|
||||
@roles_required("admin")
|
||||
def students():
|
||||
semester = Semester.query.get(session["activeSemesterId"])
|
||||
semester = Semester.query.get(current_user.active_semester_id)
|
||||
parts = semester.parts
|
||||
tables = []
|
||||
tablesLabels = []
|
||||
|
@ -128,7 +115,7 @@ def assistants():
|
|||
@app.route("/experiments")
|
||||
@roles_required("admin")
|
||||
def experiments():
|
||||
semester = Semester.query.get(session["activeSemesterId"])
|
||||
semester = Semester.query.get(current_user.active_semester_id)
|
||||
parts = semester.parts
|
||||
tables = []
|
||||
tablesLabels = []
|
||||
|
@ -159,7 +146,7 @@ def appointments():
|
|||
@app.route("/groups")
|
||||
@roles_required("admin")
|
||||
def groups():
|
||||
semester = Semester.query.get(session["activeSemesterId"])
|
||||
semester = Semester.query.get(current_user.active_semester_id)
|
||||
parts = semester.parts
|
||||
tables = []
|
||||
tablesLabels = []
|
||||
|
@ -219,5 +206,5 @@ def semesters():
|
|||
@app.route("/set_semester", methods=["GET"])
|
||||
@auth_required()
|
||||
def set_semester():
|
||||
session["activeSemesterId"] = int(request.args.get("semester_id"))
|
||||
current_user.active_semester_id = int(request.args.get("semester_id"))
|
||||
return redirect(request.referrer)
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
{% 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()}}
|
||||
Semester {{userActiveSemester().label}}
|
||||
</a>
|
||||
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||
{% for item in semesterDropDownItems() %}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
from random import choice
|
||||
from string import digits, ascii_letters
|
||||
from flask_security import current_user
|
||||
|
||||
from advlabdb.models import Semester
|
||||
|
||||
def makeTable(headerAndDataList, rows, tableId="table"):
|
||||
def cellString(cell):
|
||||
|
@ -54,6 +57,7 @@ data-export-types="['json', 'xml', 'csv', 'txt', 'sql', 'pdf']">
|
|||
<br>'''
|
||||
return table
|
||||
|
||||
|
||||
def appointmentDate(date):
|
||||
return date.strftime("%a %d.%m.%Y")
|
||||
|
||||
|
@ -64,3 +68,17 @@ def randomPassword():
|
|||
|
||||
def titleToTemplate(page):
|
||||
return page.lower().replace(" ", "_")
|
||||
|
||||
|
||||
def userActiveSemester():
|
||||
lastSemesterId = Semester.query.all()[-1].id
|
||||
if current_user.active_semester_id is None:
|
||||
current_user.active_semester_id = lastSemesterId
|
||||
elif current_user.active_semester_id != lastSemesterId:
|
||||
activeSemester = Semester.query.get(current_user.active_semester_id)
|
||||
if activeSemester:
|
||||
flash(f"You are in the old semester {activeSemester.label}!", "warning")
|
||||
else:
|
||||
flash(f"Semester changed!", "warning")
|
||||
current_user.active_semester_id = lastSemesterId
|
||||
return Semester.query.get(current_user.active_semester_id)
|
||||
|
|
Loading…
Reference in a new issue