From 8c34cb71f7047bcc8379b6fa76a074027a32943a Mon Sep 17 00:00:00 2001 From: Mo8it Date: Fri, 17 Jun 2022 19:15:38 +0200 Subject: [PATCH] Add GroupExperiment.note to adminSpace --- advlabdb/adminModelViews.py | 28 ++++++++++++++++++++-------- advlabdb/models.py | 1 + 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/advlabdb/adminModelViews.py b/advlabdb/adminModelViews.py index b7f6c82..dfedb17 100644 --- a/advlabdb/adminModelViews.py +++ b/advlabdb/adminModelViews.py @@ -25,6 +25,7 @@ from wtforms.fields import ( RadioField, StringField, SubmitField, + TextAreaField, ) from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional from wtforms.widgets import NumberInput @@ -132,7 +133,7 @@ class UserView(SecureAdminModelView): query_factory=semesterExperimentQueryFactory, allow_blank=True, blank_text="-", - description="Only needed if the user has the assistant role", + description="Only needed if the user has the assistant role.", ) active = BooleanField( @@ -283,7 +284,7 @@ class SemesterView(SecureAdminModelView): "Year", validators=[DataRequired(), NumberRange(MIN_YEAR, MAX_YEAR)], default=defaultFormYear, - description=f"Between {MIN_YEAR} and {MAX_YEAR}", + description=f"Between {MIN_YEAR} and {MAX_YEAR}.", ) transfer_parts = BooleanField( "Transfer parts", @@ -690,7 +691,7 @@ class SemesterExperimentView(SecureAdminModelView): "Oral weighting", validators=[DataRequired(), NumberRange(0, 1)], default=0.5, - description="Between 0 and 1", + description="Between 0 and 1.", places=2, widget=NumberInput(step=0.01), ) @@ -706,7 +707,7 @@ class SemesterExperimentView(SecureAdminModelView): "Final weighting", validators=[DataRequired(), NumberRange(0, 1)], default=1.0, - description="Between 0 and 1", + description="Between 0 and 1.", places=2, widget=NumberInput(step=0.01), ) @@ -904,6 +905,14 @@ class ExperimentRowFilter(FilterEqual): return (experimentNumber, programId) +def group_experiment_note_field(): + return TextAreaField( + "Note", + validators=[Optional()], + description="This note can be seen and edited by assistants that are responsible for this semester experiment.", + ) + + class GroupExperimentView(SecureAdminModelView): class ExperimentFilter(ExperimentRowFilter): def apply(self, query, value, alias=None): @@ -923,6 +932,9 @@ class GroupExperimentView(SecureAdminModelView): def customId(self, row): return row.semester_experiment_id + class EditForm(Form): + note = group_experiment_note_field() + class CreateForm(Form): group = QuerySelectField( "Group", @@ -970,8 +982,8 @@ class GroupExperimentView(SecureAdminModelView): allow_blank=True, blank_text=assistantBlankText, ) + note = group_experiment_note_field() - can_edit = False column_display_all_relations = True column_filters = ( @@ -1072,7 +1084,7 @@ class AppointmentView(SecureAdminModelView): special = BooleanField( "Special", default=False, - description="A special appointment should take place in the semester break", + description="A special appointment should take place in the semester break.", ) assistant = QuerySelectField( "Assistant", @@ -1226,12 +1238,12 @@ class ExperimentMarkView(SecureAdminModelView): oral_mark = IntegerField( "Oral Mark", validators=[Optional(), NumberRange(MIN_MARK, MAX_MARK)], - description=f"Between {MIN_MARK} and {MAX_MARK}", + description=f"Between {MIN_MARK} and {MAX_MARK}.", ) protocol_mark = IntegerField( "Protocol Mark", validators=[Optional(), NumberRange(MIN_MARK, MAX_MARK)], - description=f"Between {MIN_MARK} and {MAX_MARK}", + description=f"Between {MIN_MARK} and {MAX_MARK}.", ) column_descriptions = { diff --git a/advlabdb/models.py b/advlabdb/models.py index fae6207..c45966b 100644 --- a/advlabdb/models.py +++ b/advlabdb/models.py @@ -202,6 +202,7 @@ class Group(db.Model): class GroupExperiment(db.Model): # An experiment specified to a group id = db.Column(db.Integer, primary_key=True) + note = db.Column(db.Text, nullable=True) semester_experiment_id = db.Column(db.Integer, db.ForeignKey("semester_experiment.id"), nullable=False) semester_experiment = db.relationship("SemesterExperiment", back_populates="group_experiments")