From 0578d557509870c143cfd08f5d38e2759e26809e Mon Sep 17 00:00:00 2001 From: MizukiTemma Date: Wed, 26 Aug 2026 16:28:09 +0200 Subject: [PATCH] Fix merge conflicts --- .../cms/forms/linkcheck/edit_url_form.py | 46 ++++++------ .../templates/linkcheck/link_list_row.html | 21 ++++-- .../templates/linkcheck/links_by_filter.html | 30 +++++--- integreat_cms/cms/templatetags/url_tags.py | 13 ++++ .../views/linkcheck/linkcheck_list_view.py | 23 +++++- integreat_cms/locale/de/LC_MESSAGES/django.po | 74 +++++++++++++++---- 6 files changed, 147 insertions(+), 60 deletions(-) diff --git a/integreat_cms/cms/forms/linkcheck/edit_url_form.py b/integreat_cms/cms/forms/linkcheck/edit_url_form.py index 1d92154385..6fcbc1a0ac 100644 --- a/integreat_cms/cms/forms/linkcheck/edit_url_form.py +++ b/integreat_cms/cms/forms/linkcheck/edit_url_form.py @@ -1,39 +1,24 @@ from __future__ import annotations import logging +import re from django import forms from django.core.validators import EmailValidator, URLValidator from django.utils.translation import gettext_lazy as _ +from ...utils.link_utils import format_phone_number + logger = logging.getLogger(__name__) -class LinkField(forms.URLField): +class LinkField(forms.CharField): """ A field for links that might be URLs but could also be mailto: or tel: links """ #: Disable the default URL validator default_validators: list[URLValidator | EmailValidator] = [] - #: Whether to skip the validation URL fragments in URLField.to_python() - skip_url_fragment_validation: bool = True - - def to_python(self, value: str) -> str: - """ - Convert the string value to the appropriate Python data structure for this field - - :param value: The value that was input into the form - :returns: The Python value - """ - if self.skip_url_fragment_validation: - # Skip the URL field to_python for email and phone links - logger.debug( - "Value %r is a mailto or tel link, skipping to_python() of URLField.", - value, - ) - return super(forms.URLField, self).to_python(value) - return super().to_python(value) def clean(self, value: str) -> str: """ @@ -43,8 +28,11 @@ def clean(self, value: str) -> str: :param value: The value that was input into the form :returns: The cleaned value """ - if value.startswith("mailto:"): - email = value[7:] + if "@" in value: + email = value + if value.startswith("mailto:"): + email = value[7:] + logger.debug( "Value %r is an email link, enforcing EmailValidator on %r", value, @@ -53,10 +41,18 @@ def clean(self, value: str) -> str: self.validators.append(EmailValidator()) self.error_messages["invalid"] = _("Enter a valid email address.") return f"mailto:{super().clean(email)}" - if not value.startswith("tel:"): - logger.debug("Value %r is a normal link, enforcing URLValidator", value) - self.validators.append(URLValidator(schemes=["http", "https"])) - self.skip_url_fragment_validation = False + + if not value.startswith("tel:") and re.fullmatch(r"[+\d][\d ]*", value): + formatted_phone_number = format_phone_number(value) + logger.debug( + "Value %r looks like an phone link, formatting to %r", + value, + formatted_phone_number, + ) + return f"tel:{formatted_phone_number}" + + logger.debug("Value %r is a normal link, enforcing URLValidator", value) + self.validators.append(URLValidator(schemes=["http", "https"])) return super().clean(value) diff --git a/integreat_cms/cms/templates/linkcheck/link_list_row.html b/integreat_cms/cms/templates/linkcheck/link_list_row.html index 7dbcec45f2..1b5a471c04 100644 --- a/integreat_cms/cms/templates/linkcheck/link_list_row.html +++ b/integreat_cms/cms/templates/linkcheck/link_list_row.html @@ -19,7 +19,8 @@ rel="noopener noreferrer" class="text-blue-500 hover:underline" title="{{ url.url }}"> - {{ url.url }} + {% remove_url_prefix url as plain_url %} + {{ plain_url }} {% if url.redirect_to %}
@@ -39,9 +40,11 @@ - - {% translate url.get_message %} - + {% if view.kwargs.url_filter == 'valid' or view.kwargs.url_filter == 'invalid' %} + + {% translate url.get_message %} + + {% endif %} {% with link_text=url.regions_links.0.text %} @@ -79,7 +82,13 @@ - {% translate "Change links on all pages" %} + {% if view.kwargs.url_filter == 'invalid' or view.kwargs.url_filter == 'valid' %} + {% translate "Change links on all pages" %} + {% elif LINKCHECK_EMAIL_ENABLED and view.kwargs.url_filter == 'email' %} + {% translate "Adjust email on all pages" %} + {% elif LINKCHECK_PHONE_ENABLED and view.kwargs.url_filter == 'phone' %} + {% translate "Adjust phone number on all pages" %} + {% endif %} {% if view.kwargs.url_filter == 'invalid' %} @@ -101,7 +110,7 @@
- {% render_field edit_url_form.url|add_error_class:"border-red-500" type="url" form="edit-url-form" %} + {% render_field edit_url_form.url|add_error_class:"border-red-500" form="edit-url-form" %} {% translate "Cancel" %}