mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-12 21:40:41 +00:00
Deduplication
This commit is contained in:
parent
8c34cb71f7
commit
2790652475
1 changed files with 52 additions and 72 deletions
|
@ -666,6 +666,17 @@ def assistantQueryFactory():
|
||||||
return Assistant.query.join(User).where(User.active == True)
|
return Assistant.query.join(User).where(User.active == True)
|
||||||
|
|
||||||
|
|
||||||
|
def weighting_field(label: str, default: float):
|
||||||
|
return DecimalField(
|
||||||
|
label,
|
||||||
|
validators=[DataRequired(), NumberRange(0, 1)],
|
||||||
|
default=default,
|
||||||
|
description="Between 0 and 1.",
|
||||||
|
places=2,
|
||||||
|
widget=NumberInput(step=0.01),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SemesterExperimentView(SecureAdminModelView):
|
class SemesterExperimentView(SecureAdminModelView):
|
||||||
class ProgramFilter(ProgramRowFilter):
|
class ProgramFilter(ProgramRowFilter):
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
|
@ -687,30 +698,9 @@ class SemesterExperimentView(SecureAdminModelView):
|
||||||
blank_text="-",
|
blank_text="-",
|
||||||
)
|
)
|
||||||
|
|
||||||
oral_weighting = DecimalField(
|
oral_weighting = weighting_field("Oral weighting", 0.5)
|
||||||
"Oral weighting",
|
protocol_weighting = weighting_field("Protocol weighting", 0.5)
|
||||||
validators=[DataRequired(), NumberRange(0, 1)],
|
final_weighting = weighting_field("Final weighting", 1.0)
|
||||||
default=0.5,
|
|
||||||
description="Between 0 and 1.",
|
|
||||||
places=2,
|
|
||||||
widget=NumberInput(step=0.01),
|
|
||||||
)
|
|
||||||
protocol_weighting = DecimalField(
|
|
||||||
"Protocol weighting",
|
|
||||||
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,
|
|
||||||
widget=NumberInput(step=0.01),
|
|
||||||
)
|
|
||||||
final_weighting = DecimalField(
|
|
||||||
"Final weighting",
|
|
||||||
validators=[DataRequired(), NumberRange(0, 1)],
|
|
||||||
default=1.0,
|
|
||||||
description="Between 0 and 1.",
|
|
||||||
places=2,
|
|
||||||
widget=NumberInput(step=0.01),
|
|
||||||
)
|
|
||||||
|
|
||||||
assistants = QuerySelectMultipleField(
|
assistants = QuerySelectMultipleField(
|
||||||
"Assistants",
|
"Assistants",
|
||||||
|
@ -880,9 +870,6 @@ class AdminView(SecureAdminModelView):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
assistantBlankText = "Auto assign if experiment has only one assistant"
|
|
||||||
|
|
||||||
|
|
||||||
class ExperimentRowFilter(FilterEqual):
|
class ExperimentRowFilter(FilterEqual):
|
||||||
def get_options(self, view):
|
def get_options(self, view):
|
||||||
if not has_request_context():
|
if not has_request_context():
|
||||||
|
@ -913,6 +900,41 @@ def group_experiment_note_field():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def appointment_fields(number=None):
|
||||||
|
if number is None:
|
||||||
|
# Used in AppointmentView
|
||||||
|
label_addition = ""
|
||||||
|
date_validator = DataRequired()
|
||||||
|
date_description = None
|
||||||
|
else:
|
||||||
|
# Used in GroupExperimentView
|
||||||
|
label_addition = f"Appointment-{number} "
|
||||||
|
date_validator = Optional()
|
||||||
|
|
||||||
|
if number == 1:
|
||||||
|
date_description = "Set if you already want to add an appointment. Otherwise, leave it blank and you can do it later under the Appointment tab."
|
||||||
|
else:
|
||||||
|
date_description = "Add another appointment (see above)."
|
||||||
|
|
||||||
|
date = DateField(
|
||||||
|
label_addition + "Date",
|
||||||
|
validators=[date_validator],
|
||||||
|
description=date_description,
|
||||||
|
)
|
||||||
|
special = BooleanField(
|
||||||
|
label_addition + "Special",
|
||||||
|
default=False,
|
||||||
|
description="A special appointment should take place in the semester break.",
|
||||||
|
)
|
||||||
|
assistant = QuerySelectField(
|
||||||
|
label_addition + "Assistant",
|
||||||
|
query_factory=assistantQueryFactory,
|
||||||
|
allow_blank=True,
|
||||||
|
blank_text="Auto assign if experiment has only one assistant",
|
||||||
|
)
|
||||||
|
return date, special, assistant
|
||||||
|
|
||||||
|
|
||||||
class GroupExperimentView(SecureAdminModelView):
|
class GroupExperimentView(SecureAdminModelView):
|
||||||
class ExperimentFilter(ExperimentRowFilter):
|
class ExperimentFilter(ExperimentRowFilter):
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
|
@ -951,37 +973,9 @@ class GroupExperimentView(SecureAdminModelView):
|
||||||
blank_text="-",
|
blank_text="-",
|
||||||
)
|
)
|
||||||
|
|
||||||
appointment1_date = DateField(
|
appointment1_date, appointment1_special, appointment1_assistant = appointment_fields(1)
|
||||||
"Appointment-1 Date",
|
appointment2_date, appointment2_special, appointment2_assistant = appointment_fields(2)
|
||||||
validators=[Optional()],
|
|
||||||
description="Set if you already want to add an appointment. Otherwise, leave it blank and you can do it later under the Appointment tab.",
|
|
||||||
)
|
|
||||||
appointment1_special = BooleanField(
|
|
||||||
"Appointment-1 Special",
|
|
||||||
default=False,
|
|
||||||
)
|
|
||||||
appointment1_assistant = QuerySelectField(
|
|
||||||
"Appointment-1 Assistant",
|
|
||||||
query_factory=assistantQueryFactory,
|
|
||||||
allow_blank=True,
|
|
||||||
blank_text=assistantBlankText,
|
|
||||||
)
|
|
||||||
|
|
||||||
appointment2_date = DateField(
|
|
||||||
"Appointment-2 Date",
|
|
||||||
validators=[Optional()],
|
|
||||||
description="Add a second appointment (see above).",
|
|
||||||
)
|
|
||||||
appointment2_special = BooleanField(
|
|
||||||
"Appointment-2 Special",
|
|
||||||
default=False,
|
|
||||||
)
|
|
||||||
appointment2_assistant = QuerySelectField(
|
|
||||||
"Appointment-2 Assistant",
|
|
||||||
query_factory=assistantQueryFactory,
|
|
||||||
allow_blank=True,
|
|
||||||
blank_text=assistantBlankText,
|
|
||||||
)
|
|
||||||
note = group_experiment_note_field()
|
note = group_experiment_note_field()
|
||||||
|
|
||||||
column_display_all_relations = True
|
column_display_all_relations = True
|
||||||
|
@ -1077,21 +1071,7 @@ class AppointmentView(SecureAdminModelView):
|
||||||
allow_blank=True,
|
allow_blank=True,
|
||||||
blank_text="-",
|
blank_text="-",
|
||||||
)
|
)
|
||||||
date = DateField(
|
date, special, assistant = appointment_fields()
|
||||||
"Date",
|
|
||||||
validators=[DataRequired()],
|
|
||||||
)
|
|
||||||
special = BooleanField(
|
|
||||||
"Special",
|
|
||||||
default=False,
|
|
||||||
description="A special appointment should take place in the semester break.",
|
|
||||||
)
|
|
||||||
assistant = QuerySelectField(
|
|
||||||
"Assistant",
|
|
||||||
query_factory=assistantQueryFactory,
|
|
||||||
allow_blank=True,
|
|
||||||
blank_text=assistantBlankText,
|
|
||||||
)
|
|
||||||
|
|
||||||
column_descriptions = {
|
column_descriptions = {
|
||||||
"special": "A special appointment should take place in the semester break",
|
"special": "A special appointment should take place in the semester break",
|
||||||
|
|
Loading…
Reference in a new issue