Validators

class megforms.validators.OptionalValidatorMixin

Base validator for validators where validation is optional depending

class megforms.validators.MinimumLengthOptionalValidator(min_length=8)
class megforms.validators.NumericPasswordOptionalValidator
class megforms.validators.CommonPasswordOptionalValidator(password_list_path=<django.utils.functional.cached_property object>)
class megforms.validators.UserAttributeSimilarityOptionalValidator(user_attributes=('username', 'first_name', 'last_name', 'email'), max_similarity=0.7)
class megforms.validators.CustomFileExtensionValidator(allowed_extensions: Iterable[str] | None = None)

Custom File CustomField file type validator. used to validate filetype of a file custom-field value using either predefined default extensions or using custom field value from allowed_extensions value

class megforms.validators.GreaterThanValidator(*args, **kwargs)

Similar to MinValueValidator, but does not allow values equal to specified value

class megforms.validators.RichTextValidator(*args, **kwargs)

Validates if rich text contains disallowed tags or attributes.

deconstruct()

Return a 3-tuple of class import path, positional arguments, and keyword arguments.

class megforms.validators.RichTextParser(*, disallowed_tags: Tuple[str] = ('script', 'object', 'embed', 'link', 'iframe', 'svg'), allowed_attributes: Tuple[str] | None = ('col', 'style', 'wrap', 'abbr', 'accept', 'accept-charset', 'accesskey', 'action', 'align', 'alt', 'axis', 'border', 'cellpadding', 'cellspacing', 'char', 'charoff', 'charset', 'checked', 'cite', 'class', 'clear', 'cols', 'colspan', 'color', 'compact', 'coords', 'datetime', 'dir', 'disabled', 'enctype', 'for', 'frame', 'headers', 'height', 'href', 'hreflang', 'hspace', 'id', 'ismap', 'label', 'lang', 'longdesc', 'maxlength', 'media', 'method', 'multiple', 'name', 'nohref', 'noshade', 'nowrap', 'prompt', 'readonly', 'rel', 'rev', 'rows', 'rowspan', 'rules', 'scope', 'selected', 'shape', 'size', 'span', 'src', 'srcset', 'start', 'summary', 'tabindex', 'target', 'title', 'type', 'usemap', 'valign', 'value', 'vspace', 'width', 'seamless'), **kwargs)

Initialize and reset this instance.

If convert_charrefs is True (the default), all character references are automatically converted to the corresponding Unicode characters.

class megforms.validators.TemplateValidator(*args, **kwargs)

Validates that given string is a correct Django template

deconstruct()

Return a 3-tuple of class import path, positional arguments, and keyword arguments.

class megforms.validators.TimezoneValidator(*args, **kwargs)

Validates timezone name based on current database supported tz set

deconstruct()

Return a 3-tuple of class import path, positional arguments, and keyword arguments.

megforms.validators.validate_email_for_institution(email: str, institution: Institution) str

Verifies that an email is valid for an institution.

Parameters:
  • email – The email address.

  • institution – The institution.

class megforms.validators.LanguageCodeValidator(*args, **kwargs)

Validates that given language code is listed in the project’s LANGUAGES setting

deconstruct()

Return a 3-tuple of class import path, positional arguments, and keyword arguments.

megforms.validators.validate_string_array_or_empty(value: Any)

Validates array of strings, allows empty arrays

Parameters:

value – The value to validate

Raises:

ValidationError

class megforms.validators.TypedDictValidator(*args, **kwargs)

A Django validator for JSONField that validates the data structure against a given TypedDict.

If TypedDict’s total parameter is True, the validation will fail:

  • for fields not contained in the TypedDict

  • for fields in the TypedDict not present in data, unless the field has NotRequired.

Parameters:
  • typed_dict – the TypedDict to validate against

  • kwargs – any additional keyword arguments for validate_dict()

deconstruct()

Return a 3-tuple of class import path, positional arguments, and keyword arguments.

typed_dict_ref: str

Store the import path for deconstruction or the class itself.

Custom forms

class audit_builder.validators.AnswerGetter(_source: forms.Form | Serializer | Callable[[], forms.Form | Serializer], field_name: str)

A callable that extracts answer from another field in the form to use as the validation target value

answers

Dictionary of other answers in this submission mapped by field name

class audit_builder.validators.IssueFieldFieldNameCollisionValidator(*args, **kwargs)

Validates that field name does not collide with any pre-existing fields (For Issue)

deconstruct()

Return a 3-tuple of class import path, positional arguments, and keyword arguments.

class audit_builder.validators.FieldNameCollisionValidator(*args, **kwargs)

Validates that field name does not collide with any pre-existing field

deconstruct()

Return a 3-tuple of class import path, positional arguments, and keyword arguments.

class audit_builder.validators.FutureDateValidator(*args, **kwargs)

Future date relative to another date field, or current date

class audit_builder.validators.MaxAgeValidator(*args, **kwargs)

Validates that (DOB) date field is at most x years in the past.

Accounts

API

E-mails

emails.validators.validate_inbound_mail_domain(value: str)

Validate that the e-mail address’s domain will work for receiving e-mail.

Validates that e-mail address matches INBOUND_MAIL_DOMAIN (if set). If the inbound mail is not set, the validator does nothing.

class emails.validators.EmailDomainMXValidator(*args, **kwargs)

Validates that selected e-mail address’s domain pointing at sendgrid so that it can be used for inbound parse.

https://docs.sendgrid.com/for-developers/parsing-email/setting-up-the-inbound-parse-webhook#set-up-an-mx-record

deconstruct()

Return a 3-tuple of class import path, positional arguments, and keyword arguments.

class emails.validators.EmailDomainSPFValidator(*args, **kwargs)

Validate that the e-mail address’s domain will work for sending e-mail by checking SPF record.

The domain name should contain SPF record pointed at Sendgrid so that we can use it to send outgoing e-mail. IMPORTANT: besides SPF, the domain also needs to have correct DKIM and DMARC, which is not checked by this validator.

required_entry = 'include:sendgrid.net'

Value required in the SPF record

deconstruct()

Return a 3-tuple of class import path, positional arguments, and keyword arguments.

MEG Docs

megdocs.validators.unique_document_code(code: str, institutions: Iterable[Institution], document: Document | None = None) None
Raises:

ValidationError if the code has been used already in another document in the institution.

HL7 integration

Regions

Web forms

web_forms.validators.custom_form_validator(pk: int)

Validates that form selected in a FK field is a form with custom observation model

web_forms.validators.form_without_subforms_validator(pk: int)

Validates that selected audit form does not have subforms (is a flat form)