From 5ab3a33413e3fc1d46c12a776a1a5c9e5f6df3a4 Mon Sep 17 00:00:00 2001 From: David Venhoff Date: Sat, 11 Jan 2025 09:16:11 +0100 Subject: [PATCH] Fix contact insertion (#3305) * Fix contact insertion On the testserver, we have multiple possible backend urls. So instead of using full urls, we can just use relative urls (For some reason called absolute urls in our codebase) * Just use `reverse` instead of manually coding url * Only save the absolute path --------- Co-authored-by: charludo --- integreat_cms/cms/models/contact/contact.py | 15 ++++++++------- .../cms/templates/contacts/contact_card.html | 4 ++-- integreat_cms/cms/views/utils/contact_utils.py | 2 +- integreat_cms/static/src/js/forms/tinymce-init.ts | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/integreat_cms/cms/models/contact/contact.py b/integreat_cms/cms/models/contact/contact.py index 0e3217c271..6053d529c6 100644 --- a/integreat_cms/cms/models/contact/contact.py +++ b/integreat_cms/cms/models/contact/contact.py @@ -182,7 +182,7 @@ def referring_page_translations(self) -> QuerySet[PageTranslation]: return PageTranslation.objects.filter( id__in=( Link.objects.filter( - url__url=self.full_url, + url__url=self.absolute_url, content_type=PageTranslationLinklist.content_type(), ).values("object_id") ), @@ -200,7 +200,7 @@ def referring_poi_translations(self) -> QuerySet[POITranslation]: return POITranslation.objects.filter( id__in=( Link.objects.filter( - url__url=self.full_url, + url__url=self.absolute_url, content_type=POITranslationLinklist.content_type(), ).values("object_id") ), @@ -218,7 +218,7 @@ def referring_event_translations(self) -> QuerySet[EventTranslation]: return EventTranslation.objects.filter( id__in=( Link.objects.filter( - url__url=self.full_url, + url__url=self.absolute_url, content_type=EventTranslationLinklist.content_type(), ).values("object_id") ), @@ -232,7 +232,8 @@ def referring_objects(self) -> Generator[AbstractContentTranslation]: :return: all objects referring to this contact """ return ( - link.content_object for link in Link.objects.filter(url__url=self.full_url) + link.content_object + for link in Link.objects.filter(url__url=self.absolute_url) ) def archive(self) -> None: @@ -258,13 +259,13 @@ def copy(self) -> None: self.save() @cached_property - def full_url(self) -> str: + def absolute_url(self) -> str: """ - This property returns the full url of this contact + This property returns the absolute url of this contact :return: The full url """ - return f"{settings.BASE_URL}/{self.location.region.slug}/contact/{self.id}/" + return f"/{self.location.region.slug}/contact/{self.id}/" class Meta: verbose_name = _("contact") diff --git a/integreat_cms/cms/templates/contacts/contact_card.html b/integreat_cms/cms/templates/contacts/contact_card.html index 630ddb576e..191bce298f 100644 --- a/integreat_cms/cms/templates/contacts/contact_card.html +++ b/integreat_cms/cms/templates/contacts/contact_card.html @@ -3,12 +3,12 @@ {% spaceless %}
{# djlint:off H021 #} - Contact + Contact {# djlint:on #} {% if contact %} {% if contact.name or contact.point_of_contact_for %} diff --git a/integreat_cms/cms/views/utils/contact_utils.py b/integreat_cms/cms/views/utils/contact_utils.py index 847e742fc5..b35ac315a0 100644 --- a/integreat_cms/cms/views/utils/contact_utils.py +++ b/integreat_cms/cms/views/utils/contact_utils.py @@ -54,7 +54,7 @@ def search_contact_ajax( { "data": [ { - "url": result.full_url, + "url": result.absolute_url, "name": result.get_repr_short, } for result in results diff --git a/integreat_cms/static/src/js/forms/tinymce-init.ts b/integreat_cms/static/src/js/forms/tinymce-init.ts index 0042e14031..dd387d2f39 100644 --- a/integreat_cms/static/src/js/forms/tinymce-init.ts +++ b/integreat_cms/static/src/js/forms/tinymce-init.ts @@ -106,7 +106,7 @@ window.addEventListener("load", () => { link_target_list: false, link_default_target: "", document_base_url: tinymceConfig.getAttribute("data-webapp-url"), - relative_urls: false, + convert_urls: false, remove_script_host: false, branding: false, paste_as_text: true,