def validate_target_cardname(form, field): cardname = field.data.strip() if form.sno.data and not cardname: raise ValidationError("Specify target Indent.") if form.orig_cardname.data and not cardname: raise ValidationError("Specify target Indent.") if not cardname: return if cardname not in cards.keys(): raise ValidationError("Ident not recognized.") if form.orig_cardname.data.strip() == cardname: raise ValidationError("No change?")
def validate_orig_cardname(form, field): cardname = field.data.strip() if form.sno.data and not cardname: raise ValidationError("Specify original Indent.") if form.target_cardname.data and not cardname: raise ValidationError("Specify original Indent.") if not cardname: return if cardname: if cardname not in cards.keys(): raise ValidationError("Ident not recognized.") try: efield = serialnos.get_serialno_efield(sno=form.sno.data.strip()) if cardname != efield: raise ValidationError("S.No. seems to be {0}.".format(efield)) except SerialNoNotFound: pass
class ModuleQtyForm(Form): # TODO add customization field ident = StringField(label='Module', validators=[ Optional(), AnyOf(cards.keys(), message="Module not recognized.") ]) qty = StringField(label='Qty', validators=[]) def validate_qty(form, field): if form.ident.data: try: qty = int(field.data.strip()) if qty <= 0: raise ValidationError("Invalid Qty.") except: raise ValidationError("Invalid Qty.") else: if field.data: raise ValidationError("Detached Qty.")