Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom function to build paths #36

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions server/apikeys/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
from cryptography.hazmat.primitives.serialization import load_pem_private_key
from django.conf import settings
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
Expand Down Expand Up @@ -84,6 +85,12 @@ def public_key(priv_pem: str, id: int) -> Optional[Ed25519PublicKey]:
return None


def _build_url_with_script_name(request, path):
if (forced_script_name := settings.FORCE_SCRIPT_NAME) is not None:
path = forced_script_name + path
return request.build_absolute_uri(path)


def request_new_key(request):
"""Handle a (POST) request for a new API key."""
if request.method == "POST":
Expand All @@ -101,10 +108,10 @@ def request_new_key(request):
else:
form = RequestForm()

docs_url = request.build_absolute_uri("/docs/")
docs_url = _build_url_with_script_name(request, "/docs/")
return render(request, "apikeys/form.html", {"form": form, "docs_url": docs_url})


def documentation(request):
form_url = request.build_absolute_uri("/register/")
form_url =_build_url_with_script_name(request, "/register/")
return render(request, "apikeys/docs.html", {"form_url": form_url})