daiquiri.core.schema.validators
Any
EmptyField
NoneValidator
Validator that requires the field is None
Source code in daiquiri/core/schema/validators.py
SanitizedHTML
A Sanitised HTML string
bleach.cleaned HTML string field
Source code in daiquiri/core/schema/validators.py
OneOf(choices, **kwargs)
Single enum type validator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
choices |
list |
List of choices |
required |
RequireEmpty(**kwargs)
A RequireEmpty field
Requires that this particular field is empty by combining NoneValidator and EmptyField
ValidatedRegexp(pattern, **kwargs)
A regexp validated fields.Str
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pattern |
the pattern to use from the above dictionary |
required |
Kwargs
passed to the field
Source code in daiquiri/core/schema/validators.py
def ValidatedRegexp(pattern, **kwargs):
"""A regexp validated fields.Str
Args:
pattern: the pattern to use from the above dictionary
Kwargs:
passed to the `field`
"""
expressions = {
"word": "^[A-z0-9]+$",
"word-dash": "^[A-z0-9-]+$",
"word-dash-space": r"^[\w\s-]+$",
"word-special": r"^(\w|\s|-|%|\(|\)|,|\.)+$",
"saving": "^({(sample|component|subsampletype|subsampleid)}|[A-z0-9/-])+$",
"smiles": r"^([^J][A-Za-z0-9@+\-\[\]\(\)\\\/%=#$]+)$",
"path": "^/[A-z0-9-/]+$",
}
if pattern in expressions:
validates = kwargs.pop("validate", None)
if validates and not isinstance(validates, list):
validates = [validates]
metadata = kwargs.pop("metadata", {})
metadata["pattern"] = expressions[pattern]
return fields.Str(
validate=[
validate.Regexp(
expressions[pattern],
flags=0,
error="Input {input} does not match {regex}",
)
]
+ (validates if validates else []),
metadata=metadata,
**kwargs
)
else:
raise Exception("Cant find regular expression for {pat}".format(pat=pattern))