-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms.py
27 lines (20 loc) · 1.08 KB
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from flask_wtf import FlaskForm
from wtforms import StringField, MultipleFileField, SubmitField, RadioField
class LigysisForm(FlaskForm):
uniprot_id = StringField('Enter UniProt ID')
files = MultipleFileField('and upload mmCIF files')
format = RadioField('Select format', choices=[('mmcif', 'mmCIF'), ('pdb', 'PDB (Legacy)')], default='mmcif')
submit = SubmitField('Submit')
# Custom validator
def validate(self, extra_validators=None):
# Use the default validate method first
initial_validation = super(LigysisForm, self).validate(extra_validators=extra_validators)
# If the initial validation passes and both parts have data, return True
if initial_validation and (self.uniprot_id.data and self.files.data):
return True
# If either field is missing, add a form-wide error
if not (self.uniprot_id.data and self.files.data):
self.uniprot_id.errors.append('Please enter UniProt ID and upload mmCIF files.')
return False
return False
# TODO: Implement extendable form with optional fields