Skip to content

Commit

Permalink
Only save the absolute path
Browse files Browse the repository at this point in the history
  • Loading branch information
charludo committed Jan 11, 2025
1 parent fbc9834 commit 901fc45
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 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
8 changes: 3 additions & 5 deletions integreat_cms/cms/views/utils/contact_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
from django.views.decorators.http import require_POST

from ...decorators import permission_required
Expand Down Expand Up @@ -38,6 +37,8 @@ def search_contact_ajax(
:raises ~django.core.exceptions.PermissionDenied: If the user has no permission to the object type
:return: Json object containing all matching elements, of shape {title: str, url: str, type: str}
"""
# pylint: disable=unused-argument

body = json.loads(request.body.decode("utf-8"))
if (query := body["query_string"]) is None:
return JsonResponse({"data": []})
Expand All @@ -53,10 +54,7 @@ def search_contact_ajax(
{
"data": [
{
"url": reverse(
"get_contact",
kwargs={"contact_id": result.id, "region_slug": region_slug},
),
"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 901fc45

Please sign in to comment.