Commit 5898f5f8 authored by Jérome Perrin's avatar Jérome Perrin

Add asURL method on telephones like in rfc3966. From Thierry



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15969 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ee4a06c8
......@@ -85,11 +85,11 @@ class Telephone(Coordinate, Base):
if coordinate_text is None:
coordinate_text = ''
number_match = self.standard_parser.match(coordinate_text) or self.input_parser.match(coordinate_text)
number_match = self.standard_parser.match(coordinate_text)\
or self.input_parser.match(coordinate_text)
if not number_match:
return
number_dict = number_match.groupdict()
self.log(number_dict)
country = (number_dict.get('country', '') or '').strip()
area = (number_dict.get('area', '') or '').strip()
number = (number_dict.get('number', '') or '').strip().replace('-', ' ')
......@@ -134,6 +134,30 @@ class Telephone(Coordinate, Base):
text = ''
return text
security.declareProtected(Permissions.AccessContentsInformation,
'asURL')
def asURL(self):
"""Returns a text representation of the Url if defined
or None else.
"""
telephone_country = self.getTelephoneCountry()
if telephone_country is not None:
url_string = '+%s' % telephone_country
else :
url_string = '0'
telephone_area = self.getTelephoneArea()
if telephone_area is not None:
url_string += telephone_area
telephone_number = self.getTelephoneNumber()
if telephone_number is not None:
url_string += telephone_number
if url_string == '0':
return None
return 'tel:%s' % (url_string.replace(' ',''))
security.declareProtected(Permissions.View, 'getText')
getText = asText
......
......@@ -842,16 +842,19 @@ class TestHR(ERP5TypeTestCase):
tel.setTelephoneNumber(123456789)
self.assertEquals('+33(0)-123456789', tel.asText())
## TODO: Telephone must be a subclass of Url
##
## def test_TelephoneUrl(self):
## # http://www.rfc-editor.org/rfc/rfc3966.txt
## pers = self.getPersonModule().newContent(portal_type='Person')
## tel = pers.newContent(portal_type='Telephone')
## tel.setTelephoneCountry(33)
## tel.setTelephoneNumber(123456789)
## self.assertEquals('tel:+33-123456789', tel.asURL())
##
def test_TelephoneUrl(self):
# http://www.rfc-editor.org/rfc/rfc3966.txt
pers = self.getPersonModule().newContent(portal_type='Person')
tel = pers.newContent(portal_type='Telephone')
tel.setTelephoneCountry(33)
tel.setTelephoneNumber(123456789)
self.assertEquals('tel:+33123456789', tel.asURL())
tel.setTelephoneCountry(None)
tel.setTelephoneNumber(123456789)
self.assertEquals('tel:0123456789', tel.asURL())
def test_EmptyTelephoneAsText(self):
# asText method returns an empty string for empty telephones
......
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