diff options
author | Andrew Godwin | 2022-11-06 13:48:04 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-06 13:48:04 -0700 |
commit | dbe57075d386d7474bafc208b654507d9a2d769e (patch) | |
tree | 96b779d17753669f42b7569ec4ec66834b0673f4 /users/shortcuts.py | |
parent | 8aec395331a1e9ec4ef1ea38aa20b8517131133b (diff) | |
download | takahe-dbe57075d386d7474bafc208b654507d9a2d769e.tar.gz takahe-dbe57075d386d7474bafc208b654507d9a2d769e.tar.bz2 takahe-dbe57075d386d7474bafc208b654507d9a2d769e.zip |
Rework to a domains model for better vhosting
Diffstat (limited to 'users/shortcuts.py')
-rw-r--r-- | users/shortcuts.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/users/shortcuts.py b/users/shortcuts.py index 0e00404..167f178 100644 --- a/users/shortcuts.py +++ b/users/shortcuts.py @@ -1,7 +1,7 @@ -from django.conf import settings +from django.http import Http404 from django.shortcuts import get_object_or_404 -from users.models import Identity +from users.models import Domain, Identity def by_handle_or_404(request, handle, local=True): @@ -9,10 +9,25 @@ 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 "HTTP_HOST" not in request.META: + raise Http404("No hostname available") + username = handle + domain_instance = Domain.get_local_domain(request.META["HTTP_HOST"]) + if domain_instance is None: + raise Http404("No matching domains found") + domain = domain_instance.domain + else: + username, domain = handle.split("@", 1) if local: - return get_object_or_404(Identity.objects.filter(local=True), handle=handle) + return get_object_or_404( + Identity.objects.filter(local=True), + username=username, + domain_id=domain, + ) else: - return get_object_or_404(Identity, handle=handle) + return get_object_or_404( + Identity, + username=username, + domain_id=domain, + ) |