From f5d6e29664fe83094403ebe39a19383d35c5d19d Mon Sep 17 00:00:00 2001 From: Mo8it Date: Mon, 18 Apr 2022 18:37:21 +0200 Subject: [PATCH] Change year to IntegerField --- advlabdb/adminModelViews.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/advlabdb/adminModelViews.py b/advlabdb/adminModelViews.py index bcb1c4d..7283fc9 100644 --- a/advlabdb/adminModelViews.py +++ b/advlabdb/adminModelViews.py @@ -49,7 +49,9 @@ from advlabdb.exceptions import DataBaseException, ModelViewException from advlabdb.independent_funs import randomPassword from advlabdb.models import ( MAX_MARK, + MAX_YEAR, MIN_MARK, + MIN_YEAR, Admin, Appointment, Assistant, @@ -98,15 +100,12 @@ class UserView(SecureAdminModelView): def semesterQueryFactory(): return Semester.query - def activeSemesterDefault(): - return userActiveSemester() - email = StringField("Email", validators=[DataRequired(), Email()]) roles = QuerySelectMultipleField( "Roles", query_factory=roleQueryFactory, validators=[DataRequired()], - default=[Role.query.filter(Role.name == "assistant").first()], + default=[user_datastore.find_role("assistant")], ) first_name = StringField("First Name", validators=[DataRequired()]) @@ -130,7 +129,7 @@ class UserView(SecureAdminModelView): query_factory=semesterQueryFactory, allow_blank=True, blank_text="-", - default=activeSemesterDefault, + default=userActiveSemester, description="Not fixed and users (including assistants) can change it.", ) @@ -266,21 +265,26 @@ class RoleView(SecureAdminModelView): class SemesterView(SecureAdminModelView): class CreateForm(Form): - def labelDefault(): + def defaultFormLabel(): if userActiveSemester().label == "WS": return "SS" else: return "WS" - def yearDefault(): + def defaultFormYear(): activeSemester = userActiveSemester() if activeSemester.label == "WS": return activeSemester.year + 1 else: return activeSemester.year - label = RadioField("Semester", choices=["WS", "SS"], validators=[DataRequired()], default=labelDefault) - year = StringField("Year", validators=[DataRequired()], default=yearDefault) + label = RadioField("Semester", choices=["WS", "SS"], validators=[DataRequired()], default=defaultFormLabel) + year = IntegerField( + "Year", + validators=[DataRequired(), NumberRange(MIN_YEAR, MAX_YEAR)], + default=defaultFormYear, + description=f"Between {MIN_YEAR} and {MAX_YEAR}", + ) transfer_parts = BooleanField( "Transfer parts", description="This option transfers the parts you have in your current active semester. Make sure that your semester is the last semester before creating a new one (recommended)!", @@ -713,7 +717,7 @@ class SemesterExperimentView(SecureAdminModelView): oral_weighting = DecimalField( "Oral weighting", - validators=[DataRequired(), NumberRange(min=0, max=1)], + validators=[DataRequired(), NumberRange(0, 1)], default=0.5, description="Between 0 and 1", places=2, @@ -721,7 +725,7 @@ class SemesterExperimentView(SecureAdminModelView): ) protocol_weighting = DecimalField( "Protocol weighting", - validators=[DataRequired(), NumberRange(min=0, max=1)], + validators=[DataRequired(), NumberRange(0, 1)], default=0.5, description="Between 0 and 1. Oral and protocol weightings have to add to 1! Both are rounded to 2 decimal digits.", places=2, @@ -729,7 +733,7 @@ class SemesterExperimentView(SecureAdminModelView): ) final_weighting = DecimalField( "Final weighting", - validators=[DataRequired(), NumberRange(min=0, max=1)], + validators=[DataRequired(), NumberRange(0, 1)], default=1.0, description="Between 0 and 1", places=2, @@ -1277,12 +1281,12 @@ class ExperimentMarkView(SecureAdminModelView): class EditForm(Form): oral_mark = IntegerField( "Oral Mark", - validators=[NumberRange(min=MIN_MARK, max=MAX_MARK), Optional()], + validators=[Optional(), NumberRange(MIN_MARK, MAX_MARK)], description=f"Between {MIN_MARK} and {MAX_MARK}", ) protocol_mark = IntegerField( "Protocol Mark", - validators=[NumberRange(min=MIN_MARK, max=MAX_MARK), Optional()], + validators=[Optional(), NumberRange(MIN_MARK, MAX_MARK)], description=f"Between {MIN_MARK} and {MAX_MARK}", )