Open delrius-euphoria opened 2 years ago
A possible way is something like:
import requests
def validate_github_profile(value):
"""validate github profile"""
pattern = r"^github.com\/[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*\/?$"
if re.search(pattern, value) is None:
raise ValidationError(
_("%(value)s is not a valid GitHub profile."),
params={"value": value},
)
status_code = requests.get(value).status_code
if status_code == 404:
raise ValidationError(
_("%(value)s is not a valid GitHub profile."),
params={"value": value},
)
Or something along the lines
https://github.com/Coders-HQ/CodersHQ/blob/40400f7c866bbb16ed0064e2ee180a5241f86d84/codershq/users/validators.py#L15
Why not just use an additional step that uses
request
to check if the userprofile exists or not? Like: