from wtforms.validators import StopValidation

from ..schemata import experiment
import wtforms
from wtforms import validators


class UserForm(wtforms.Form):
    usernames = [(p, p) for p in experiment.Person().fetch('username')]
    user = wtforms.SelectField('User', [validators.InputRequired()], choices=usernames)


class RestrictionForm(wtforms.Form):
    restriction = wtforms.StringField('Restriction', [validators.InputRequired()])


class AutoProcessing(wtforms.Form):
    animal_id = wtforms.IntegerField('Animal Id', [validators.InputRequired()])
    session = wtforms.IntegerField('Session', [validators.InputRequired()])
    scan_idx = wtforms.IntegerField('Scan Idx', [validators.InputRequired()])
    priority = wtforms.IntegerField('Priority [0-100]', [validators.NumberRange(-128, 127)],
                                    default=50)

class QualityForm(wtforms.Form):
    animal_id = wtforms.IntegerField('Animal Id', [validators.InputRequired()])
    session = wtforms.IntegerField('Session', [validators.InputRequired()])
    scan_idx = wtforms.IntegerField('Scan Idx', [validators.InputRequired()])


class TrackingForm(wtforms.Form):
    exclude = wtforms.BooleanField('Not trackable', [validators.InputRequired()],
                                   default=False)
    relative_area_threshold = wtforms.DecimalField('Threshold for relative area',
                                                   [validators.InputRequired()], default=0.01)
    ratio_threshold = wtforms.DecimalField('Threshold for major/minor radius ratio threshold',
                                           [validators.InputRequired()], default=1.5)
    error_threshold = wtforms.DecimalField('Threshold for fitting error',
                                           [validators.InputRequired()], default=0.1)
    min_countour_len = wtforms.IntegerField('Minimal contour length',
                                            [validators.InputRequired()], default=5)
    margin = wtforms.DecimalField('Minimal side margin', [validators.InputRequired()],
                                  default=0.02)
    contrast_threshold = wtforms.DecimalField('Minimal contrast threshold',
                                              [validators.InputRequired()], default=5)
    speed_threshold = wtforms.DecimalField('Maximal allowed speed threshold',
                                           [validators.InputRequired()], default=0.1)
    dr_threshold = wtforms.DecimalField('Maximal allowed relative radius change threshold',
                                        [validators.InputRequired()], default=0.1)
    gaussian_blur = wtforms.DecimalField('Gaussian blurring filter size',
                                         [validators.InputRequired()], default=5)

def IsScan(form, field):
    dict(animal_id=form['animal_id'].data,
         session=form['session'].data,
         scan_idx=form['scan_idx'].data)

    if not form.some_checkbox_field.data:
        # clear out processing errors
        field.errors[:] = []
        # Stop further validators running
        raise StopValidation()
@@ -2752,336 +2752,4 @@
 t=5)
-%0A%0Adef IsScan(form, field):%0A    dict(animal_id=form%5B'animal_id'%5D.data,%0A         session=form%5B'session'%5D.data,%0A         scan_idx=form%5B'scan_idx'%5D.data)%0A%0A    if not form.some_checkbox_field.data:%0A        # clear out processing errors%0A        field.errors%5B:%5D = %5B%5D%0A        # Stop further validators running%0A        raise StopValidation()

delete IsScan from forms.py, unused