Skip to content

Commit

Permalink
Fix: urls in v3
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Sep 29, 2024
1 parent 197a12e commit 59fdb97
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions djangocms_text/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@

try:
from cms.models import PageContent
_version = 4
except ImportError:
from cms.models import Title as PageContent
_version = 3

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
Expand Down Expand Up @@ -513,7 +515,7 @@ def get_available_urls(self, request):
app, model = model.split(".")
model = apps.get_model(app, model)
obj = model.objects.get(pk=pk)
if isinstance(obj, Page):
if isinstance(obj, Page) and _version >= 4:
obj = obj.pagecontent_set(manager="admin_manager").current_content().first()
return JsonResponse({"text": obj.title, "url": obj.get_absolute_url()})
return JsonResponse({"text": str(obj), "url": obj.get_absolute_url()})
Expand All @@ -522,14 +524,17 @@ def get_available_urls(self, request):

search = request.GET.get("q", "").strip("  ").lower()
language = get_language_from_request(request)
try:
qs = list(PageContent.admin_manager.filter(language=language, title__icontains=search)
.current_content()
.order_by("page__path"))
except FieldError:
qs = list(PageContent.admin_manager.filter(language=language, title__icontains=search)
.current_content()
.order_by("page__node__path"))
if _version >= 4:
try:
qs = list(PageContent.admin_manager.filter(language=language, title__icontains=search)
.current_content()
.order_by("page__path"))
except FieldError:
qs = list(PageContent.admin_manager.filter(language=language, title__icontains=search)
.current_content()
.order_by("page__node__path"))
else:
qs = list(PageContent.objects.filter(language=language, title__icontains=search).order_by("page__node__path"))

urls = {
"results": [
Expand Down

0 comments on commit 59fdb97

Please sign in to comment.