Skip to content
Snippets Groups Projects

Feat: adding new non-mandatory fields.

Merged Andrea Callia D'Iddio requested to merge adding-new-fields into master
7 files
+ 125
23
Compare changes
  • Side-by-side
  • Inline
Files
7
+ 37
19
@@ -14,20 +14,54 @@ from wtforms.validators import DataRequired, ValidationError
class ProjectForm(FlaskForm):
title = StringField("Title", validators=[DataRequired()])
description = TextAreaField("Description", validators=[DataRequired()])
background_skills = TextAreaField("Background skills")
is_student_proposal = BooleanField("Student Proposal", default=False)
on_behalf = StringField("from", default=None)
category = SelectField("Category", coerce=str)
meeting_modes = [("", "N/A"), ("remote", "Remote"), ("in-person", "In person")]
meeting_mode = SelectField(
"Meeting type",
choices=[("", "N/A"), ("remote", "Remote"), ("in-person", "In person")],
choices=meeting_modes,
coerce=str,
validators=[validators.Optional()],
validators=[
validators.Optional(),
validators.AnyOf([c[0] for c in meeting_modes]),
],
)
proposed_start_date = DateField(
"Proposed start date", validators=[validators.Optional()]
)
duration_in_weeks = IntegerField(
"Duration (in weeks)", validators=[validators.Optional()]
"Duration (in weeks)",
validators=[validators.Optional(), validators.NumberRange(min=0)],
)
time_commitments = [
("", "N/A"),
("full-time", "Full-time"),
("part-time", "Part-time"),
]
time_commitment = SelectField(
"Time Commitment",
choices=time_commitments,
coerce=str,
validators=[
validators.Optional(),
validators.AnyOf([c[0] for c in time_commitments]),
],
)
lab_usages = [
("", "N/A"),
("lab-based", "Lab-based project"),
("non-lab-based", "Not lab-based"),
]
lab_usage = SelectField(
"Lab usage",
choices=lab_usages,
coerce=str,
validators=[
validators.Optional(),
validators.AnyOf([c[0] for c in lab_usages]),
],
)
def validate_on_behalf(self, field):
@@ -40,19 +74,3 @@ class ProjectForm(FlaskForm):
if field == self.category and field.data == "":
self.category.errors += "Please choose a category for the project."
raise ValidationError("Please choose a category for the project.")
def validate_meeting_mode(self, field):
if field == self.category and field.data not in ["", "remote", "in-person"]:
self.meeting_mode.errors += "Invalid meeting mode."
raise ValidationError(
"The meeting mode for the project is invalid. Choose a valid value or leave it blank."
)
def validate_duration(self, field):
if all(
(field == self.duration_in_weeks, field.data is not None, field.data < 0)
):
self.meeting_mode.errors += "Invalid duration."
raise ValidationError(
"The duration for the project is invalid. Choose a valid value or leave it blank."
)
Loading