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" %}
diff --git a/integreat_cms/cms/templates/linkcheck/links_by_filter.html b/integreat_cms/cms/templates/linkcheck/links_by_filter.html
index f07dc84931..bbff346950 100644
--- a/integreat_cms/cms/templates/linkcheck/links_by_filter.html
+++ b/integreat_cms/cms/templates/linkcheck/links_by_filter.html
@@ -62,12 +62,16 @@
{% endif %}
{% endif %}
-
+
{% if view.kwargs.url_filter == 'invalid' %}
{% translate "The following links are reported by the system as potentially faulty." %}
{% translate "Click the links to check them and adjust them if necessary." %}
+ {% elif LINKCHECK_EMAIL_ENABLED and view.kwargs.url_filter == 'email' %}
+ {% translate "The following email addresses are used and linked in the system." %}
+ {% elif LINKCHECK_PHONE_ENABLED and view.kwargs.url_filter == 'phone' %}
+ {% translate "The following telephone numbers are used and linked in the system." %}
{% endif %}
class="table-listing"
data-js-bulk-actions>
{% csrf_token %}
-
+
@@ -99,17 +103,23 @@
{% if view.kwargs.url_filter == 'invalid' %}
{% translate "Link to be checked" %}
+ {% elif LINKCHECK_EMAIL_ENABLED and view.kwargs.url_filter == 'email' %}
+ {% translate "Email linking" %}
+ {% elif LINKCHECK_PHONE_ENABLED and view.kwargs.url_filter == 'phone' %}
+ {% translate "Phone linking" %}
{% else %}
{% translate "URL" %}
{% endif %}
-
- {% if view.kwargs.url_filter == 'invalid' %}
- {% translate "Error message" %}
- {% else %}
- {% translate "Status" %}
- {% endif %}
-
+ {% if view.kwargs.url_filter == 'valid' or view.kwargs.url_filter == 'invalid' %}
+
+ {% if view.kwargs.url_filter == 'invalid' %}
+ {% translate "Error message" %}
+ {% elif view.kwargs.url_filter == 'valid' %}
+ {% translate "Status" %}
+ {% endif %}
+
+ {% endif %}
{% translate "Link text" %}
@@ -118,7 +128,7 @@
title="{% translate "The source translation of the first usage" %}">
{% translate "Source" %}
-
+
{% translate "Options" %}
diff --git a/integreat_cms/cms/templatetags/url_tags.py b/integreat_cms/cms/templatetags/url_tags.py
index 3074dad92d..ada77c66db 100644
--- a/integreat_cms/cms/templatetags/url_tags.py
+++ b/integreat_cms/cms/templatetags/url_tags.py
@@ -11,11 +11,14 @@
from django.urls import reverse
from django.utils.safestring import mark_safe
+from ..views.contacts.contact_from_existing_data import clean_url
+
if TYPE_CHECKING:
from typing import Any
from urllib.parse import ParseResult
from django.http import HttpRequest
+ from linkcheck import Url
register = template.Library()
@@ -52,3 +55,13 @@ def url_for_current_region(target: str, request: HttpRequest, **kwargs: Any) ->
if request.region:
kwargs["region_slug"] = request.region.slug
return reverse(target, kwargs=kwargs)
+
+
+@register.simple_tag
+def remove_url_prefix(url: Url) -> str:
+ """
+ Return the url without prefix "mailto:" and "tel:"
+
+ :param target: Target url
+ """
+ return clean_url(url)
diff --git a/integreat_cms/cms/views/linkcheck/linkcheck_list_view.py b/integreat_cms/cms/views/linkcheck/linkcheck_list_view.py
index 1bdf0ceca2..4a079aeefb 100644
--- a/integreat_cms/cms/views/linkcheck/linkcheck_list_view.py
+++ b/integreat_cms/cms/views/linkcheck/linkcheck_list_view.py
@@ -116,8 +116,17 @@ def dispatch(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpRespo
if request.POST:
form_kwargs = {"data": request.POST}
else:
- form_kwargs = {"initial": {"url": self.instance}}
+ form_kwargs = {"initial": {"url": None}}
self.form = EditUrlForm(**form_kwargs)
+
+ # Potential conflicts with #4458
+ placeholder_text = _("Enter new link here")
+ if self.instance.type == "mailto":
+ placeholder_text = _("Enter new E-mail here")
+ elif self.instance.type == "phone":
+ placeholder_text = _("Enter new phone number here")
+
+ self.form.fields["url"].widget.attrs["placeholder"] = placeholder_text
return super().dispatch(request, *args, **kwargs)
def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> TemplateResponse:
@@ -190,12 +199,20 @@ def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
).format(len(failed_replacements)),
)
+ # Messages for E-mail and phone number links are adjusted in #4518. Do not overwrite or throw away in other PRs of #2837's children.
if new_url.startswith("mailto:"):
- messages.success(request, _("Email link was successfully replaced"))
+ messages.success(
+ request,
+ _(
+ "The email link has been successfully updated on all pages and in all translations."
+ ),
+ )
elif new_url.startswith("tel:"):
messages.success(
request,
- _("Phone number link was successfully replaced"),
+ _(
+ "The telephone link has been successfully updated on all pages and in all translations."
+ ),
)
else:
messages.success(request, _("URL was successfully replaced"))
diff --git a/integreat_cms/locale/de/LC_MESSAGES/django.po b/integreat_cms/locale/de/LC_MESSAGES/django.po
index 064933764a..4fc590d2f1 100644
--- a/integreat_cms/locale/de/LC_MESSAGES/django.po
+++ b/integreat_cms/locale/de/LC_MESSAGES/django.po
@@ -7193,6 +7193,14 @@ msgstr "URL global in allen Regionen ersetzen"
msgid "Change links on all pages"
msgstr "Links auf allen Seiten anpassen"
+#: cms/templates/linkcheck/link_list_row.html
+msgid "Adjust email on all pages"
+msgstr "E-Mail auf allen Seiten anpassen"
+
+#: cms/templates/linkcheck/link_list_row.html
+msgid "Adjust phone number on all pages"
+msgstr "Telefonnummer auf allen Seiten anpassen"
+
#: cms/templates/linkcheck/link_list_row.html
msgid "Mark link as valid"
msgstr "Link als gültig markieren"
@@ -7222,6 +7230,14 @@ msgstr ""
msgid "Click the links to check them and adjust them if necessary."
msgstr "Klicken zum Überprüfen auf die Links und passe diese bei Bedarf an."
+#: cms/templates/linkcheck/links_by_filter.html
+msgid "The following email addresses are used and linked in the system."
+msgstr "Folgende E-Mail-Adressen werden im System verwendet und verlinkt."
+
+#: cms/templates/linkcheck/links_by_filter.html
+msgid "The following telephone numbers are used and linked in the system."
+msgstr "Folgende Telefonnummern werden im System verwendet und verlinkt."
+
#: cms/templates/linkcheck/links_by_filter.html
msgid "Link-Check Help"
msgstr "Link-Überprüfung Hilfe"
@@ -7230,6 +7246,14 @@ msgstr "Link-Überprüfung Hilfe"
msgid "Link to be checked"
msgstr "Zu überprüfender Link"
+#: cms/templates/linkcheck/links_by_filter.html
+msgid "Email linking"
+msgstr "Email Verlinkung"
+
+#: cms/templates/linkcheck/links_by_filter.html
+msgid "Phone linking"
+msgstr "Telefonnummer Verlinkung"
+
#: cms/templates/linkcheck/links_by_filter.html
msgid "Error message"
msgstr "Fehlermeldung"
@@ -8993,9 +9017,9 @@ msgid ""
"right\">"
msgstr ""
"deshalb sind Unterschiede gegeben und zu erwarten. Mehr "
-"Details dazu in der Dokumentation "
-"a>"
+"Details dazu in der Dokumentation "
+"span> "
#: cms/templates/statistics/statistics_sidebar.html
msgid "Adjust shown data"
@@ -10341,6 +10365,18 @@ msgstr ""
msgid "Links were replaced successfully."
msgstr "Links wurden erfolgreich ersetzt."
+#: cms/views/linkcheck/linkcheck_list_view.py
+msgid "Enter new link here"
+msgstr "Hier neuen Link einfügen"
+
+#: cms/views/linkcheck/linkcheck_list_view.py
+msgid "Enter new E-mail here"
+msgstr "Hier neue E-Mail einfügen"
+
+#: cms/views/linkcheck/linkcheck_list_view.py
+msgid "Enter new phone number here"
+msgstr "Hier neue Telefonnummer einfügen"
+
#: cms/views/linkcheck/linkcheck_list_view.py
msgid ""
"{} translation(s) could not be updated due to a database conflict. Please "
@@ -10350,12 +10386,20 @@ msgstr ""
"werden. Bitte erneut versuchen."
#: cms/views/linkcheck/linkcheck_list_view.py
-msgid "Email link was successfully replaced"
-msgstr "E-Mail-Link wurde erfolgreich ersetzt"
+msgid ""
+"The email link has been successfully updated on all pages and in all "
+"translations."
+msgstr ""
+"Der Email-Link wurde auf allen Seiten und in allen Übersetzungen erfolgreich "
+"angepasst."
#: cms/views/linkcheck/linkcheck_list_view.py
-msgid "Phone number link was successfully replaced"
-msgstr "Telefonnummern-Link wurde erfolgreich ersetzt"
+msgid ""
+"The telephone link has been successfully updated on all pages and in all "
+"translations."
+msgstr ""
+"Der Telefon-Link wurde auf allen Seiten und in allen Übersetzungen "
+"erfolgreich angepasst."
#: cms/views/linkcheck/linkcheck_list_view.py
msgid "URL was successfully replaced"
@@ -11998,15 +12042,18 @@ msgstr ""
"Diese Seite konnte nicht importiert werden, da sie zu einer anderen Region "
"gehört ({})."
+#~ msgid "Valid links"
+#~ msgstr "Gültige Links"
+
+#~ msgid "ERROR MESSAGE"
+#~ msgstr "FEHLERMELDUNG"
+
#~ msgid "linked in Integreat"
#~ msgstr "in Integreat verlinkt"
#~ msgid "Broken Links"
#~ msgstr "Fehlerhafte Links"
-#~ msgid "Valid links"
-#~ msgstr "Gültige Links"
-
#~ msgid "Unchecked links"
#~ msgstr "Nicht geprüfte Links"
@@ -12051,6 +12098,7 @@ msgstr ""
#~ 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"
@@ -14101,9 +14149,6 @@ msgstr ""
#~ msgid "Push Notification was successfully sent"
#~ msgstr "Push-Benachrichtigung wurde erfolgreich gesendet"
-#~ msgid "This e-mail address may not be available in the system."
-#~ msgstr "Womöglich ist diese E-Mail-Adresse nicht im System vorhanden."
-
#~ msgid "Superuser"
#~ msgstr "Administrator:in"
@@ -14232,9 +14277,6 @@ msgstr ""
#~ msgid "Offer \"%(offer_name)s\" was successfully deactivated"
#~ msgstr "Angebot \"%(offer_name)s\" wurde erfolgreich deaktiviert"
-#~ msgid "Enter the role's name here"
-#~ msgstr "Name der Rolle hier eingeben"
-
#~ msgid ""
#~ "The url you have entered is invalid. Please check the corresponding "
#~ "settings."