From d77dcf62b4005a0f36ef2fa7ba6d3651d2ef38d7 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sat, 5 Nov 2022 14:17:27 -0600 Subject: Initial commit (users and statuses) --- users/shortcuts.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 users/shortcuts.py (limited to 'users/shortcuts.py') diff --git a/users/shortcuts.py b/users/shortcuts.py new file mode 100644 index 0000000..0e00404 --- /dev/null +++ b/users/shortcuts.py @@ -0,0 +1,18 @@ +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) -- cgit v1.2.3