mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Fix reversed phone numbers in rtl languages
This commit is contained in:
@@ -285,7 +285,7 @@ DEFAULT_VARIABLES = OrderedDict((
|
||||
("telephone", {
|
||||
"label": _("Phone number"),
|
||||
"editor_sample": "+01 1234 567890",
|
||||
"evaluate": lambda op, order, ev: phone_format(order.phone)
|
||||
"evaluate": lambda op, order, ev: phone_format(order.phone, html=False)
|
||||
}),
|
||||
("email", {
|
||||
"label": _("Email"),
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
from django import template
|
||||
from django.utils.html import escape
|
||||
from django.utils.safestring import mark_safe
|
||||
from phonenumber_field.phonenumber import PhoneNumber
|
||||
from phonenumbers import NumberParseException
|
||||
|
||||
@@ -27,17 +29,20 @@ register = template.Library()
|
||||
|
||||
|
||||
@register.filter("phone_format")
|
||||
def phone_format(value: str):
|
||||
def phone_format(value: str, html=True):
|
||||
if not value:
|
||||
return ""
|
||||
|
||||
if isinstance(value, str):
|
||||
v = ""
|
||||
elif isinstance(value, str):
|
||||
try:
|
||||
return PhoneNumber.from_string(value).as_international
|
||||
v = PhoneNumber.from_string(value).as_international
|
||||
except NumberParseException:
|
||||
return value
|
||||
v = value
|
||||
elif isinstance(value, PhoneNumber) and value.national_number:
|
||||
v = value.as_international
|
||||
else:
|
||||
v = str(value)
|
||||
|
||||
if isinstance(value, PhoneNumber) and value.national_number:
|
||||
return value.as_international
|
||||
if html:
|
||||
v = mark_safe('<span class="force-ltr">' + escape(v) + '</span>')
|
||||
|
||||
return str(value)
|
||||
return v
|
||||
|
||||
Reference in New Issue
Block a user