Skip to content

Commit

Permalink
Just use reverse instead of manually coding url
Browse files Browse the repository at this point in the history
  • Loading branch information
david-venhoff committed Dec 19, 2024
1 parent 4bfe408 commit fbc9834
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
15 changes: 1 addition & 14 deletions integreat_cms/cms/models/contact/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,27 +257,14 @@ def copy(self) -> None:
self.point_of_contact_for = self.point_of_contact_for + " " + _("(Copy)")
self.save()

def get_absolute_url(self) -> str:
"""
Returns the absolute url to this contact:
For example::
/region_slug/contact/1
:return: The absolute url to this contact
"""
return f"/{self.location.region.slug}/contact/{self.id}/"

@cached_property
def full_url(self) -> str:
"""
This property returns the full url of this contact
:return: The full url
"""
absolute_url = self.get_absolute_url()
return f"{settings.BASE_URL}{absolute_url}"
return f"{settings.BASE_URL}/{self.location.region.slug}/contact/{self.id}/"

class Meta:
verbose_name = _("contact")
Expand Down
8 changes: 5 additions & 3 deletions integreat_cms/cms/views/utils/contact_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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 @@ -37,8 +38,6 @@ 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 @@ -54,7 +53,10 @@ def search_contact_ajax(
{
"data": [
{
"url": result.get_absolute_url(),
"url": reverse(
"get_contact",
kwargs={"contact_id": result.id, "region_slug": region_slug},
),
"name": result.get_repr_short,
}
for result in results
Expand Down

0 comments on commit fbc9834

Please sign in to comment.