mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
Move Semester functions
This commit is contained in:
parent
1141d1dfb9
commit
6f22253a49
4 changed files with 20 additions and 26 deletions
|
@ -39,11 +39,7 @@ from .customClasses import (
|
|||
)
|
||||
from .database_import import importFromFile
|
||||
from .exceptions import DataBaseException, ModelViewException
|
||||
from .model_dependent_funs import (
|
||||
initActiveSemesterMenuLinks,
|
||||
lastSemester,
|
||||
sortedSemestersStartingWithNewest,
|
||||
)
|
||||
from .model_dependent_funs import initActiveSemesterMenuLinks
|
||||
from .model_independent_funs import randomPassword
|
||||
from .models import (
|
||||
MAX_MARK,
|
||||
|
@ -77,7 +73,7 @@ class SemesterRowFilter(FilterEqual):
|
|||
if not has_request_context():
|
||||
return tuple()
|
||||
|
||||
semesters = sortedSemestersStartingWithNewest()
|
||||
semesters = Semester.sortedSemestersStartingWithNewest()
|
||||
return tuple((semester.id, semester.repr()) for semester in semesters)
|
||||
|
||||
|
||||
|
@ -148,7 +144,7 @@ class UserView(SecureAdminModelView):
|
|||
"Active Semester",
|
||||
query_factory=semesterQueryFactory,
|
||||
validators=[DataRequired()],
|
||||
default=lastSemester,
|
||||
default=Semester.lastSemester,
|
||||
description="Not fixed and users (including assistants) can change it.",
|
||||
)
|
||||
|
||||
|
@ -1519,7 +1515,7 @@ class AnalysisView(SecureAdminBaseView):
|
|||
for part in parts
|
||||
]
|
||||
|
||||
semesters = sortedSemestersStartingWithNewest()
|
||||
semesters = Semester.sortedSemestersStartingWithNewest()
|
||||
semesterLabels = [semester.repr() for semester in semesters]
|
||||
meanFinalPartMarks = np.flip(
|
||||
[
|
||||
|
|
|
@ -9,25 +9,10 @@ from . import app, db
|
|||
from .models import Semester
|
||||
|
||||
|
||||
def sortedSemestersStartingWithNewest(limit=0):
|
||||
# Inserting an older semester is not allowed!
|
||||
# Therefore, the id is enough.
|
||||
stmt = select(Semester).order_by(Semester.id.desc())
|
||||
|
||||
if limit > 0:
|
||||
stmt = stmt.limit(limit)
|
||||
|
||||
return db.session.execute(stmt).scalars()
|
||||
|
||||
|
||||
def lastSemester():
|
||||
return sortedSemestersStartingWithNewest(limit=1).first()
|
||||
|
||||
|
||||
def initActiveSemesterMenuLinks(space):
|
||||
with app.app_context():
|
||||
try:
|
||||
semesters = sortedSemestersStartingWithNewest()
|
||||
semesters = Semester.sortedSemestersStartingWithNewest()
|
||||
for semester in semesters:
|
||||
space.add_link(
|
||||
MenuLink(
|
||||
|
@ -55,7 +40,7 @@ def get_count(table):
|
|||
def active_semester_repr():
|
||||
active_semester = current_user.active_semester
|
||||
repr = active_semester.repr()
|
||||
if active_semester != lastSemester():
|
||||
if active_semester != Semester.lastSemester():
|
||||
flash(f"You are in the old semester {repr}!", "warning")
|
||||
|
||||
return repr
|
||||
|
|
|
@ -479,6 +479,19 @@ class Semester(db.Model):
|
|||
for part in oldSemester.parts:
|
||||
db.session.add(Part(program=part.program, number=part.number, semester=self))
|
||||
|
||||
def sortedSemestersStartingWithNewest(limit=0):
|
||||
# Inserting an older semester is not allowed!
|
||||
# Therefore, the id is enough.
|
||||
stmt = select(Semester).order_by(Semester.id.desc())
|
||||
|
||||
if limit > 0:
|
||||
stmt = stmt.limit(limit)
|
||||
|
||||
return db.session.execute(stmt).scalars()
|
||||
|
||||
def lastSemester():
|
||||
return Semester.sortedSemestersStartingWithNewest(limit=1).first()
|
||||
|
||||
def repr(self):
|
||||
return f"{self.label}{self.year}"
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from flask import flash, redirect, render_template, request, url_for
|
|||
from flask_security import auth_required, current_user, roles_accepted, roles_required
|
||||
|
||||
from . import app, db
|
||||
from .model_dependent_funs import active_semester_repr, lastSemester
|
||||
from .model_dependent_funs import active_semester_repr
|
||||
from .models import Semester
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue