Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions integreat_cms/cms/templates/linkcheck/link_list_row.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Comment thread
hannaseithe marked this conversation as resolved.
<tr class="text-gray-800 hover:bg-gray-100"
{% if url.id == view.kwargs.url_id %}id="replace-url"{% endif %}>
<td class="py-3 pl-4 align-top border-t border-solid border-gray-200">
Expand Down Expand Up @@ -45,37 +44,34 @@
{% translate url.get_message %}
</td>
{% endif %}
{% with link_text=url.regions_links.0.text %}
<td class="py-3 pr-2 align-top border-t border-solid border-gray-200 max-w-[75px] sm:max-w-[100px] md:max-w-[100px] lg:max-w-[100px] xl:max-w-[150px] 2xl:max-w-[200px] 3xl:max-w-[260px] 4xl:max-w-[400px]"
title="{{ link_text }}">
<div class="table-cell-truncate">
<span class="table-cell-content">{{ link_text }}</span>
<a class="toggle-table-cell">
<i icon-name="chevron-down" class="more"></i>
<i icon-name="chevron-up" class="less"></i>
</a>
</div>
</td>
{% endwith %}
<td class="py-3 pr-2 align-top border-t border-solid border-gray-200 max-w-[75px] sm:max-w-[100px] md:max-w-[100px] lg:max-w-[100px] xl:max-w-[150px] 2xl:max-w-[200px] 3xl:max-w-[260px] 4xl:max-w-[400px]">
<div class="table-cell-truncate">
<div>
{% spaceless %}
<span class="table-cell-content">
{% if show_source_link %}
<a href="{{ content_object.backend_edit_link }}"
title="{% translate "Go to source" %}"
class="hover:underline">
<span>{{ content_object.title }}</span>
{% if not link_info.text and not perms.cms.view_organization %}
<span class="table-cell-content">
<span>{{ link_info.title }}</span>
</span>
{% else %}
<span class="table-cell-content">
<a href="{{ link_info.link }}"
target="_blank"
class="underline"
rel="noopener noreferrer">
<span>{{ link_info.title }}</span><i icon-name="external-link" class="ml-2"></i>
</a>
{% else %}
<span>{{ content_object.title }}</span>
{% endif %}
</span>
<br>
{% if link_info.translated_title %}
<span class="text-gray-600 text-sm">({{ link_info.translated_title }})</span>
{% endif %}
</span>
{% endif %}
{% endspaceless %}
<a class="toggle-table-cell">
<i icon-name="chevron-down" class="more"></i>
<i icon-name="chevron-up" class="less"></i>
</a>
</div>
</td>
<td class="py-3 pr-2 align-top border-t border-solid border-gray-200 break-words max-w-[75px] sm:max-w-[100px] md:max-w-[100px] lg:max-w-[100px] xl:max-w-[150px] 2xl:max-w-[200px] 3xl:max-w-[260px] 4xl:max-w-[400px]"
title="{{ link_info.text }}">
<div>
<span class="table-cell-content">{{ link_info.text }}</span>
</div>
</td>
<td class="py-3 pr-4 align-top border-t border-solid border-gray-200">
Expand Down
14 changes: 7 additions & 7 deletions integreat_cms/cms/templates/linkcheck/links_by_filter.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% load i18n %}
{% load static %}
{% load url_tags %}
{% load link_checker %}
{% block content %}
<div class="flex flex-wrap justify-between gap-4 my-2">
<h1 class="heading">
Expand Down Expand Up @@ -120,13 +121,11 @@ <h1 class="heading">
{% endif %}
</th>
{% endif %}
<th class="text-sm text-left uppercase py-3 pr-2"
title="{% translate "The link text of the first usage" %}">
{% translate "Link text" %}
<th class="text-sm text-left uppercase py-3 pr-2">
{% translate "Where is the link?" %}
</th>
<th class="text-sm text-left uppercase py-3 pr-2"
title="{% translate "The source translation of the first usage" %}">
{% translate "Source" %}
<th class="text-sm text-left uppercase py-3 pr-2">
{% translate "Link text" %}
</th>
<th class="text-sm text-right uppercase py-3 pr-4">
{% translate "Options" %}
Expand All @@ -135,7 +134,8 @@ <h1 class="heading">
</thead>
<tbody>
{% 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 %}
<tr>
<td colspan="6" class="px-4 py-3">
Expand Down
37 changes: 1 addition & 36 deletions integreat_cms/cms/templatetags/content_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@

from ..constants import translation_status, weekdays
from ..models import (
EventTranslation,
ImprintPageTranslation,
Language,
Organization,
PageTranslation,
POITranslation,
)

if TYPE_CHECKING:
Expand All @@ -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
Expand Down Expand Up @@ -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]],
Expand Down
55 changes: 55 additions & 0 deletions integreat_cms/cms/templatetags/link_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
MizukiTemma marked this conversation as resolved.

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()
Expand All @@ -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,
}
34 changes: 17 additions & 17 deletions integreat_cms/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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 "
Expand Down