3 from django
.core
.exceptions
import ValidationError
4 from django
.core
.validators
import validate_email
5 from django
.utils
.translation
import gettext_lazy
as _
8 def validate_uuid_or_email(input_value
):
9 """Check if the value is a valid email or UUID.
11 This is useful to determine if a given input is a user identifier in
12 Mailman 3 API 3.1+, where, user identifiers are either UUID or email.
14 :param input_value: The value to validate.
15 :type input_value: str
18 :raises ValidationError: If the value is either a UUID, not an email.
22 validate_email(input_value
)
23 except ValidationError
:
31 uuid
.UUID(input_value
)
37 if not any([is_email
, is_uuid
]):
38 raise ValidationError(
39 _('Invalid: "{0}" should be either email or UUID').format(
41 params
={'value': input_value
},