1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-12 21:40:41 +00:00
AdvLabDB/advlabdb/forms.py

53 lines
1.7 KiB
Python
Raw Normal View History

2022-06-20 01:08:57 +00:00
from flask_wtf import FlaskForm
from wtforms.fields import DateField, SubmitField, TextAreaField
from wtforms.validators import DataRequired, Optional
2022-06-26 22:20:15 +00:00
from .model_dependent_funs import selection_mark_field
2022-06-20 01:08:57 +00:00
class AssistantGroupExperimentFormBase(FlaskForm):
2022-09-24 14:17:03 +00:00
submit = SubmitField(label="Save")
2022-06-20 01:08:57 +00:00
def assistant_group_experiment_form_factory(current_user, group_experiment):
class AssistantGroupExperimentForm(AssistantGroupExperimentFormBase):
note = TextAreaField(
"Note",
default=group_experiment.note,
validators=[Optional()],
)
appointments = group_experiment.appointments
appointment_num = 1
for appointment in appointments:
2023-11-02 18:38:09 +00:00
description = "Yes" if appointment.special else "No"
2022-06-20 01:08:57 +00:00
setattr(
AssistantGroupExperimentForm,
"appointment_" + str(appointment_num),
DateField(
str(appointment_num),
default=appointment.date,
validators=[DataRequired()],
description=description,
),
)
appointment_num += 1
experiment_marks = group_experiment.experiment_marks
experiment_mark_num = 1
for experiment_mark in experiment_marks:
setattr(
AssistantGroupExperimentForm,
"oral_experiment_mark_" + str(experiment_mark_num),
2022-06-26 22:20:15 +00:00
selection_mark_field("Oral", experiment_mark.oral_mark),
2022-06-20 01:08:57 +00:00
)
setattr(
AssistantGroupExperimentForm,
"protocol_experiment_mark_" + str(experiment_mark_num),
2022-06-26 22:20:15 +00:00
selection_mark_field("Protocol", experiment_mark.protocol_mark),
2022-06-20 01:08:57 +00:00
)
experiment_mark_num += 1
return (AssistantGroupExperimentForm(), appointments, experiment_marks)