Skip to content

Commit

Permalink
Fix contact insertion (#3305)
Browse files Browse the repository at this point in the history
* 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 <github@charlotteharludo.com>
  • Loading branch information
david-venhoff and charludo authored Jan 11, 2025
1 parent b439037 commit 5ab3a33
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions integreat_cms/cms/models/contact/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
),
Expand All @@ -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")
),
Expand All @@ -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")
),
Expand All @@ -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:
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions integreat_cms/cms/templates/contacts/contact_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
{% spaceless %}
<div contenteditable="false"
data-contact-id="{{ contact.pk }}"
data-contact-url="{{ contact.full_url }}"
data-contact-url="{{ contact.absolute_url }}"
class="contact-card notranslate"
dir="ltr"
translate="no">
{# djlint:off H021 #}
<a href="{{ contact.full_url }}" style="display: none">Contact</a>
<a href="{{ contact.absolute_url }}" style="display: none">Contact</a>
{# djlint:on #}
{% if contact %}
{% if contact.name or contact.point_of_contact_for %}
Expand Down
2 changes: 1 addition & 1 deletion integreat_cms/cms/views/utils/contact_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion integreat_cms/static/src/js/forms/tinymce-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5ab3a33

Please sign in to comment.