Commit b22ed36e authored by Jérome Perrin's avatar Jérome Perrin

ERP5: implement Telephone.asURL for non-detailed coordinates

Telephone.asUrl (which is used in erp5_short_message) properly supported
detailed coordinates, but had no support for coordinate text.

In that case, we don't try to be to clever and just use the coordinate
(almost) as is, just using the tel: prefix and removing spaces which are
not legal.
parent e845c27f
...@@ -356,6 +356,11 @@ class Telephone(Coordinate): ...@@ -356,6 +356,11 @@ class Telephone(Coordinate):
"""Returns a text representation of the Url if defined """Returns a text representation of the Url if defined
or None else. or None else.
""" """
if not self.isDetailed():
coordinate_text = self.getCoordinateText()
if coordinate_text:
return 'tel:%s' % coordinate_text.replace(' ', '')
telephone_country = self.getTelephoneCountry() telephone_country = self.getTelephoneCountry()
if telephone_country is not None: if telephone_country is not None:
url_string = '+%s' % telephone_country url_string = '+%s' % telephone_country
......
...@@ -333,10 +333,21 @@ class TestERP5Coordinate(ERP5TypeTestCase): ...@@ -333,10 +333,21 @@ class TestERP5Coordinate(ERP5TypeTestCase):
tel.setTelephoneNumber(123456789) tel.setTelephoneNumber(123456789)
self.assertEqual('tel:+33123456789', tel.asURL()) self.assertEqual('tel:+33123456789', tel.asURL())
tel.setTelephoneCountry(None) tel = pers.newContent(portal_type='Telephone')
tel.setTelephoneNumber(123456789) tel.setTelephoneNumber(123456789)
self.assertEqual('tel:0123456789', tel.asURL()) self.assertEqual('tel:0123456789', tel.asURL())
tel = pers.newContent(portal_type='Telephone')
tel.setCoordinateText('+33123456789')
self.assertEqual('tel:+33123456789', tel.asURL())
# from rfc3966
# """ "tel" URIs MUST NOT use spaces in visual separators to avoid
# excessive escaping."""
tel = pers.newContent(portal_type='Telephone')
tel.setCoordinateText('01 23 45 67 89')
self.assertEqual('tel:0123456789', tel.asURL())
def test_EmptyTelephoneAsText(self): def test_EmptyTelephoneAsText(self):
# asText method returns an empty string for empty telephones # asText method returns an empty string for empty telephones
pers = self.getPersonModule().newContent(portal_type='Person') pers = self.getPersonModule().newContent(portal_type='Person')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment