mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Prevent creating semesters older than newest
This commit is contained in:
parent
45359b2c87
commit
813d6102a2
2 changed files with 14 additions and 6 deletions
|
@ -261,17 +261,18 @@ class UserView(SecureAdminModelView):
|
||||||
class SemesterView(SecureAdminModelView):
|
class SemesterView(SecureAdminModelView):
|
||||||
class CreateForm(Form):
|
class CreateForm(Form):
|
||||||
def defaultFormLabel():
|
def defaultFormLabel():
|
||||||
if current_user.active_semester.label == "WS":
|
last_semester = Semester.lastSemester()
|
||||||
|
if last_semester.label == "WS":
|
||||||
return "SS"
|
return "SS"
|
||||||
else:
|
else:
|
||||||
return "WS"
|
return "WS"
|
||||||
|
|
||||||
def defaultFormYear():
|
def defaultFormYear():
|
||||||
activeSemester = current_user.active_semester
|
last_semester = Semester.lastSemester()
|
||||||
if activeSemester.label == "WS":
|
if last_semester.label == "WS":
|
||||||
return activeSemester.year + 1
|
return last_semester.year + 1
|
||||||
else:
|
else:
|
||||||
return activeSemester.year
|
return last_semester.year
|
||||||
|
|
||||||
label = RadioField(
|
label = RadioField(
|
||||||
"Semester",
|
"Semester",
|
||||||
|
|
|
@ -455,7 +455,14 @@ class Semester(db.Model):
|
||||||
|
|
||||||
__table_args__ = (db.UniqueConstraint(label, year),)
|
__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):
|
def initFromOldSemester(label, year, oldSemester, transferParts, transferAssistants):
|
||||||
semester = Semester(label=label, year=year)
|
semester = Semester(label=label, year=year)
|
||||||
|
|
Loading…
Reference in a new issue