diff --git a/advlabdb/adminModelViews.py b/advlabdb/adminModelViews.py index f318ba5..c6dd50f 100644 --- a/advlabdb/adminModelViews.py +++ b/advlabdb/adminModelViews.py @@ -261,17 +261,18 @@ class UserView(SecureAdminModelView): class SemesterView(SecureAdminModelView): class CreateForm(Form): def defaultFormLabel(): - if current_user.active_semester.label == "WS": + last_semester = Semester.lastSemester() + if last_semester.label == "WS": return "SS" else: return "WS" def defaultFormYear(): - activeSemester = current_user.active_semester - if activeSemester.label == "WS": - return activeSemester.year + 1 + last_semester = Semester.lastSemester() + if last_semester.label == "WS": + return last_semester.year + 1 else: - return activeSemester.year + return last_semester.year label = RadioField( "Semester", diff --git a/advlabdb/models.py b/advlabdb/models.py index 1e77644..07c9332 100644 --- a/advlabdb/models.py +++ b/advlabdb/models.py @@ -455,7 +455,14 @@ class Semester(db.Model): __table_args__ = (db.UniqueConstraint(label, year),) - # TODO: def __init__(self, label, year): + def __init__(self, label, year): + last_semester = Semester.lastSemester() + + if last_semester is not None: + if year < last_semester.year or (year == last_semester.year and label == "SS"): + raise DataBaseException(f"You can only create semesters older than the last semester {last_semester}!") + + super().__init__(label=label, year=year) def initFromOldSemester(label, year, oldSemester, transferParts, transferAssistants): semester = Semester(label=label, year=year)