summaryrefslogtreecommitdiffstats
path: root/users/shortcuts.py
diff options
context:
space:
mode:
Diffstat (limited to 'users/shortcuts.py')
-rw-r--r--users/shortcuts.py18
1 files changed, 18 insertions, 0 deletions
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)