This repository has been archived on 2023-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
takahe/users/shortcuts.py
2022-11-05 14:17:27 -06:00

19 lines
591 B
Python

from django.conf import settings
from django.shortcuts import get_object_or_404
from users.models import Identity
def by_handle_or_404(request, handle, local=True):
"""
Retrieves an Identity by its long or short handle.
Domain-sensitive, so it will understand short handles on alternate domains.
"""
# TODO: Domain sensitivity
if "@" not in handle:
handle += "@" + settings.DEFAULT_DOMAIN
if local:
return get_object_or_404(Identity.objects.filter(local=True), handle=handle)
else:
return get_object_or_404(Identity, handle=handle)