Source code for app.view.forms.upload_step5_form
from wtforms import (
BooleanField,
FieldList,
FormField,
HiddenField,
IntegerField,
SelectField,
SelectMultipleField,
StringField,
TextAreaField,
URLField,
)
from wtforms.validators import DataRequired, ValidationError, Length
from app.view.forms.base_form import BaseForm
[docs]
class UploadStep5Form(BaseForm):
[docs]
class ExperimentForm(BaseForm):
[docs]
class PerturbationForm(BaseForm):
# Note: converted to seconds when creating perturbation
[docs]
removedCompartmentName = SelectField('removedCompartmentName', choices=[], validate_choice=False)
[docs]
addedCompartmentName = SelectField('addedCompartmentName', choices=[], validate_choice=False)
[docs]
cultivationMode = SelectField('cultivationMode', choices=[
('batch', "Batch"),
('fed-batch', "Fed-batch"),
('chemostat', "Chemostat"),
('other', "Other"),
])
[docs]
communityName = SelectField(
'communityName',
validators=[DataRequired()],
choices=[],
validate_choice=False,
)
[docs]
compartmentNames = SelectMultipleField(
'compartmentNames',
validators=[DataRequired()],
choices=[],
validate_choice=False,
)
[docs]
def validate_bioreplicates(self, field):
names = [b['name'] for b in field.data]
self._validate_uniqueness("name", "names are not unique", names)
if len(names) == 0:
raise ValidationError("at least one is required")
[docs]
timeUnits = SelectField('timeUnits', choices=[
('d', 'Days (d)'),
('h', 'Hours (h)'),
('m', 'Minutes (m)'),
('s', 'Seconds (s)'),
])
[docs]
def validate_experiments(self, field):
# Local validation:
names = [e['name'] for e in field.data]
try:
self._validate_uniqueness("experiment_names", "names are not unique", names)
except ValidationError as e:
for field in self.experiments:
if field.data['name'] in self._duplicated_attributes['experiment_names']:
field.form_errors.append('name: not unique')
raise e
# Global bioreplicate validation:
names = [
bioreplicate['name']
for experiment in field.data
for bioreplicate in experiment['bioreplicates']
]
self._validate_uniqueness("bioreplicate_names", "bioreplicate names are not globally unique", names)