diff --git a/integreat_cms/cms/templates/linkcheck/link_list_row.html b/integreat_cms/cms/templates/linkcheck/link_list_row.html
index 1b5a471c04..0262630c04 100644
--- a/integreat_cms/cms/templates/linkcheck/link_list_row.html
+++ b/integreat_cms/cms/templates/linkcheck/link_list_row.html
@@ -4,7 +4,6 @@
{% load model_tags %}
{% load widget_tweaks %}
{% load url_tags %}
-{% object_translation_has_view_perm request.user content_object as show_source_link %}
|
@@ -45,37 +44,34 @@
{% translate url.get_message %}
|
{% endif %}
- {% with link_text=url.regions_links.0.text %}
-
-
- {{ link_text }}
-
-
-
-
-
- |
- {% endwith %}
- |
+
+
+ {{ link_info.text }}
|
diff --git a/integreat_cms/cms/templates/linkcheck/links_by_filter.html b/integreat_cms/cms/templates/linkcheck/links_by_filter.html
index bbff346950..1f201aab1e 100644
--- a/integreat_cms/cms/templates/linkcheck/links_by_filter.html
+++ b/integreat_cms/cms/templates/linkcheck/links_by_filter.html
@@ -2,6 +2,7 @@
{% load i18n %}
{% load static %}
{% load url_tags %}
+{% load link_checker %}
{% block content %}
@@ -120,13 +121,11 @@
{% endif %}
{% endif %}
- |
- {% translate "Link text" %}
+ |
+ {% translate "Where is the link?" %}
|
-
- {% translate "Source" %}
+ |
+ {% translate "Link text" %}
|
{% translate "Options" %}
@@ -135,7 +134,8 @@
{% for url in filtered_urls %}
- {% include "linkcheck/link_list_row.html" with content_object=url.regions_links.0.content_object %}
+ {% link_display_info url.regions_links request.region as link_info %}
+ {% include "linkcheck/link_list_row.html" with link_info=link_info %}
{% empty %}
|
diff --git a/integreat_cms/cms/templatetags/content_filters.py b/integreat_cms/cms/templatetags/content_filters.py
index b298153e2d..b6b40144e9 100644
--- a/integreat_cms/cms/templatetags/content_filters.py
+++ b/integreat_cms/cms/templatetags/content_filters.py
@@ -15,12 +15,7 @@
from ..constants import translation_status, weekdays
from ..models import (
- EventTranslation,
- ImprintPageTranslation,
Language,
- Organization,
- PageTranslation,
- POITranslation,
)
if TYPE_CHECKING:
@@ -29,7 +24,7 @@
from django.http import QueryDict
from django.utils.datastructures import MultiValueDict
- from django.utils.functional import Promise, SimpleLazyObject
+ from django.utils.functional import Promise
from django.utils.safestring import SafeString
from ..forms.custom_content_model_form import CustomContentModelForm
@@ -243,36 +238,6 @@ def is_empty(iterable: MultiValueDict) -> bool:
return not bool(iterable)
-@register.simple_tag
-def object_translation_has_view_perm(
- user: SimpleLazyObject,
- obj: AbstractContentTranslation,
-) -> bool:
- """
- This filter accepts any translation of Event, Page or Poi and returns
- whether this account has the permission to view this object
-
- :param user: The requested user
- :param obj: The requested object
- ~integreat_cms.cms.models.events.event_translation.EventTranslation, or ~integreat_cms.cms.models.pois.poi_translation.POITranslation
-
- :raises ValueError: if the object is not a translation of Event, Page or Poi
-
- :return: Whether this account is allowed to view this object
- """
- if isinstance(obj, EventTranslation):
- return user.has_perm("cms.view_event")
- if isinstance(obj, PageTranslation):
- return user.has_perm("cms.view_page")
- if isinstance(obj, POITranslation):
- return user.has_perm("cms.view_poi")
- if isinstance(obj, ImprintPageTranslation):
- return user.has_perm("cms.view_imprint")
- if isinstance(obj, Organization):
- return user.has_perm("cms.view:organization")
- raise ValueError(f"Invalid model: {type(obj)}")
-
-
@register.filter
def as_weekday_iterator(
opening_hours: list[dict[str, Any]],
diff --git a/integreat_cms/cms/templatetags/link_checker.py b/integreat_cms/cms/templatetags/link_checker.py
index ef96b41e1f..55509d9a12 100644
--- a/integreat_cms/cms/templatetags/link_checker.py
+++ b/integreat_cms/cms/templatetags/link_checker.py
@@ -7,10 +7,18 @@
from typing import TYPE_CHECKING
from django import template
+from django.utils.translation import get_language
if TYPE_CHECKING:
+ from typing import Any
+
+ from linkcheck.models import Link
+
from integreat_cms.cms.models import Region
+from integreat_cms.cms.models.abstract_content_translation import (
+ AbstractContentTranslation,
+)
from integreat_cms.cms.utils.linkcheck_utils import filter_urls
register = template.Library()
@@ -20,3 +28,50 @@
def get_broken_links(region: Region) -> int:
_, count_dict = filter_urls(region_slug=region.slug)
return count_dict["number_invalid_urls"]
+
+
+@register.simple_tag
+def link_display_info(links: list[Link], region: Region | None) -> dict[str, Any]:
+ # Fall back to user language if user is in the global link list or the region's `default_language` returns `None`
+ preferred_language_slug = (
+ region.default_language.slug
+ if region and region.default_language
+ else get_language()
+ )
+
+ first_content, link_text = links[0].content_object, links[0].text
+ best_content, link_text = next(
+ (
+ (link.content_object, link.text)
+ for link in links
+ if isinstance(link.content_object, AbstractContentTranslation)
+ and link.content_object.language.slug == preferred_language_slug
+ ),
+ (first_content, link_text),
+ )
+
+ best_content_translation = (
+ best_content.foreign_object.get_translation(preferred_language_slug)
+ if isinstance(best_content, AbstractContentTranslation)
+ else None
+ )
+
+ title_in_readable_language = (
+ best_content_translation.title
+ if best_content_translation
+ and best_content.language.slug != preferred_language_slug
+ else None
+ )
+
+ link = (
+ f"{best_content.base_link}{best_content.slug}"
+ if isinstance(best_content, AbstractContentTranslation)
+ else best_content.backend_edit_link
+ )
+
+ return {
+ "title": best_content.title,
+ "link": link,
+ "text": link_text,
+ "translated_title": title_in_readable_language,
+ }
diff --git a/integreat_cms/locale/de/LC_MESSAGES/django.po b/integreat_cms/locale/de/LC_MESSAGES/django.po
index 4fc590d2f1..89c612f0c7 100644
--- a/integreat_cms/locale/de/LC_MESSAGES/django.po
+++ b/integreat_cms/locale/de/LC_MESSAGES/django.po
@@ -7177,10 +7177,6 @@ msgstr "Leitet weiter zu"
msgid "linked in %(BRANDING_TITLE)s"
msgstr "in %(BRANDING_TITLE)s verlinkt"
-#: cms/templates/linkcheck/link_list_row.html
-msgid "Go to source"
-msgstr "Inhalt aufrufen"
-
#: cms/templates/linkcheck/link_list_row.html
msgid "Replace URL centrally in the current region"
msgstr "URL zentral in der aktuellen Region ersetzen"
@@ -7259,21 +7255,13 @@ msgid "Error message"
msgstr "Fehlermeldung"
#: cms/templates/linkcheck/links_by_filter.html
-msgid "The link text of the first usage"
-msgstr "Der Linktext der ersten Verwendung"
+msgid "Where is the link?"
+msgstr "Wo steht der Link?"
#: cms/templates/linkcheck/links_by_filter.html
msgid "Link text"
msgstr "Linktext"
-#: cms/templates/linkcheck/links_by_filter.html
-msgid "The source translation of the first usage"
-msgstr "Die Quell-Übersetzung der ersten Verwendung"
-
-#: cms/templates/linkcheck/links_by_filter.html
-msgid "Source"
-msgstr "Quelle"
-
#: cms/templates/linkcheck/links_by_filter.html
msgid "No valid links could be found."
msgstr "Es konnten keine gültigen Links gefunden werden."
@@ -12042,6 +12030,18 @@ msgstr ""
"Diese Seite konnte nicht importiert werden, da sie zu einer anderen Region "
"gehört ({})."
+#~ msgid "Go to source"
+#~ msgstr "Inhalt aufrufen"
+
+#~ msgid "The source translation of the first usage"
+#~ msgstr "Die Quell-Übersetzung der ersten Verwendung"
+
+#~ msgid "Source"
+#~ msgstr "Quelle"
+
+#~ msgid "The number of times this URL is used in the content"
+#~ msgstr "Die Anzahl, wie oft diese URL im Inhalt verwendet wird"
+
#~ msgid "Valid links"
#~ msgstr "Gültige Links"
@@ -12096,9 +12096,6 @@ msgstr ""
#~ msgid "Code"
#~ msgstr "Code"
-#~ msgid "The number of times this URL is used in the content"
-#~ msgstr "Die Anzahl, wie oft diese URL im Inhalt verwendet wird"
-
#~ msgid "Budget year start differs from the renewal date"
#~ msgstr "Unterjähriger Start des Abrechnungszeitraums"
@@ -12126,6 +12123,9 @@ msgstr ""
#~ msgid "Month from which the add-on package was booked"
#~ msgstr "Monat ab welchem das Add-On Paket gebucht wurde"
+#~ msgid "The link text of the first usage"
+#~ msgstr "Der Linktext der ersten Verwendung"
+
#~ msgid "Enable to set starting date differing from the renewal date."
#~ msgstr ""
#~ "Aktivieren, um ein Startdatum anzugeben, welches sich vom "
| | |