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 Meta:
[docs] csrf_time_limit = None
[docs] class ExperimentForm(BaseForm):
[docs] class Meta:
[docs] csrf = False
[docs] class BioreplicateForm(BaseForm):
[docs] class Meta:
[docs] csrf = False
[docs] name = StringField('name', validators=[DataRequired(), Length(max=100)])
[docs] position = StringField('position', validators=[Length(max=100)])
[docs] biosampleUrl = URLField('biosampleUrl')
[docs] class PerturbationForm(BaseForm):
[docs] class Meta:
[docs] csrf = False
# Note: converted to seconds when creating perturbation
[docs] startTime = IntegerField('startTime', validators=[DataRequired()])
[docs] endTime = IntegerField('endTime', validators=[DataRequired()])
[docs] description = TextAreaField('description', validators=[DataRequired()])
[docs] removedCompartmentName = SelectField('removedCompartmentName', choices=[], validate_choice=False)
[docs] addedCompartmentName = SelectField('addedCompartmentName', choices=[], validate_choice=False)
[docs] oldCommunityName = SelectField('oldCommunityName', choices=[], validate_choice=False)
[docs] newCommunityName = SelectField('newCommunityName', choices=[], validate_choice=False)
[docs] publicId = HiddenField('publicId')
[docs] name = StringField('name', validators=[DataRequired(), Length(max=100)])
[docs] description = TextAreaField('description', validators=[DataRequired()])
[docs] timepointCount = IntegerField('timepointCount', validators=[DataRequired()])
[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] bioreplicates = FieldList(FormField(BioreplicateForm))
[docs] perturbations = FieldList(FormField(PerturbationForm))
[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] experiments = FieldList(FormField(ExperimentForm))
[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)