From 61c207aa0490ffb07f8e435ed430939fb831531e Mon Sep 17 00:00:00 2001 From: odkhang Date: Tue, 17 Sep 2024 16:28:21 +0700 Subject: [PATCH] Update base path using force_script_name (#199) * update base_path using force_script_name * fix black style, using url template --- src/pretalx/common/context_processors.py | 1 + src/pretalx/common/middleware/domains.py | 8 +++++--- src/pretalx/event/models/event.py | 11 +++++++---- src/pretalx/event/models/organiser.py | 4 +++- src/pretalx/orga/context_processors.py | 1 + src/pretalx/orga/templates/orga/admin.html | 18 +++--------------- src/pretalx/orga/templates/orga/base.html | 8 ++++---- src/pretalx/orga/urls.py | 2 +- src/pretalx/orga/views/admin.py | 1 + src/pretalx/orga/views/event.py | 6 +++--- src/pretalx/orga/views/organiser.py | 4 +++- src/pretalx/orga/views/typeahead.py | 4 +++- src/pretalx/settings.py | 13 +++++++------ 13 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/pretalx/common/context_processors.py b/src/pretalx/common/context_processors.py index fdf1dba1b..4f71a6f50 100644 --- a/src/pretalx/common/context_processors.py +++ b/src/pretalx/common/context_processors.py @@ -85,6 +85,7 @@ def system_information(request): context["warning_update_available"] = False context["warning_update_check_active"] = False + context["base_path"] = settings.BASE_PATH if ( not request.user.is_anonymous and request.user.is_administrator diff --git a/src/pretalx/common/middleware/domains.py b/src/pretalx/common/middleware/domains.py index d914452f2..78da44b7d 100644 --- a/src/pretalx/common/middleware/domains.py +++ b/src/pretalx/common/middleware/domains.py @@ -51,8 +51,10 @@ def process_request(self, request): request.port = int(port) if port else None request.uses_custom_domain = False - resolved = resolve(request.path) - if resolved.url_name in ANY_DOMAIN_ALLOWED or request.path.startswith("/api/"): + resolved = resolve(request.path_info) + if resolved.url_name in ANY_DOMAIN_ALLOWED or request.path_info.startswith( + "/api/" + ): return None event_slug = resolved.kwargs.get("event") if event_slug: @@ -76,7 +78,7 @@ def process_request(self, request): if settings.DEBUG or domain in LOCAL_HOST_NAMES: return None - if request.path.startswith("/orga"): # pragma: no cover + if request.path_info.startswith("/orga"): # pragma: no cover if default_port not in (80, 443): default_domain = f"{default_domain}:{default_port}" return redirect(urljoin(default_domain, request.get_full_path())) diff --git a/src/pretalx/event/models/event.py b/src/pretalx/event/models/event.py index e8a27b3fc..29e352557 100644 --- a/src/pretalx/event/models/event.py +++ b/src/pretalx/event/models/event.py @@ -321,7 +321,8 @@ class Event(PretalxModel): objects = models.Manager() class urls(EventUrls): - base = "/{self.slug}/" + base_path = settings.BASE_PATH + base = "{base_path}/{self.slug}/" login = "{base}login/" logout = "{base}logout" auth = "{base}auth/" @@ -349,8 +350,9 @@ class urls(EventUrls): schedule_widget_script = "{base}widgets/schedule.js" class orga_urls(EventUrls): - create = "/orga/event/new" - base = "/orga/event/{self.slug}/" + base_path = settings.BASE_PATH + create = "{base_path}/orga/event/new" + base = "{base_path}/orga/event/{self.slug}/" login = "{base}login/" live = "{base}live" delete = "{base}delete" @@ -402,7 +404,8 @@ class orga_urls(EventUrls): new_information = "{base}info/new" class api_urls(EventUrls): - base = "/api/events/{self.slug}/" + base_path = settings.BASE_PATH + base = "{base_path}/api/events/{self.slug}/" submissions = "{base}submissions/" talks = "{base}talks/" schedules = "{base}schedules/" diff --git a/src/pretalx/event/models/organiser.py b/src/pretalx/event/models/organiser.py index 796323bfb..80ab2a737 100644 --- a/src/pretalx/event/models/organiser.py +++ b/src/pretalx/event/models/organiser.py @@ -1,6 +1,7 @@ import json import string +from django.conf import settings from django.core.validators import RegexValidator from django.db import models, transaction from django.utils.crypto import get_random_string @@ -48,7 +49,8 @@ def __str__(self) -> str: return str(self.name) class orga_urls(EventUrls): - base = "/orga/organiser/{self.slug}/" + base_path = settings.BASE_PATH + base = "{base_path}/orga/organiser/{self.slug}/" delete = "{base}delete" teams = "{base}teams/" new_team = "{teams}new" diff --git a/src/pretalx/orga/context_processors.py b/src/pretalx/orga/context_processors.py index 4514b456b..afb7e4cae 100644 --- a/src/pretalx/orga/context_processors.py +++ b/src/pretalx/orga/context_processors.py @@ -25,6 +25,7 @@ def orga_events(request): # rather than using the settings object directly in the template site_config = dict(settings.CONFIG.items("site")) context["site_config"] = site_config + context["base_path"] = settings.BASE_PATH if not request.path.startswith("/orga/"): return {} diff --git a/src/pretalx/orga/templates/orga/admin.html b/src/pretalx/orga/templates/orga/admin.html index 4d970619c..ea431ce03 100644 --- a/src/pretalx/orga/templates/orga/admin.html +++ b/src/pretalx/orga/templates/orga/admin.html @@ -27,8 +27,9 @@

{% translate "Administrator information" %}

{% translate "Your pretalx version is:" %} {{ pretalx_version|copyable }}. - {% blocktranslate trimmed with url="/orga/admin/update/" %} - You can check for updates here. + {% url 'orga:admin.update' as update_url %} + {% blocktranslate trimmed %} + You can check for updates here. {% endblocktranslate %}

@@ -97,17 +98,4 @@

Celery

{% endif %} -

{% translate "Links" %}

- {% endblock %} diff --git a/src/pretalx/orga/templates/orga/base.html b/src/pretalx/orga/templates/orga/base.html index 3b64ab6c2..f597d0316 100644 --- a/src/pretalx/orga/templates/orga/base.html +++ b/src/pretalx/orga/templates/orga/base.html @@ -53,7 +53,7 @@ - + {% translate {{ site_config.name }}