[Erp5-report] r15969 - in /erp5/trunk/products/ERP5: Document/Telephone.py tests/testERP5HR.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Aug 30 20:22:39 CEST 2007
Author: jerome
Date: Thu Aug 30 20:22:39 2007
New Revision: 15969
URL: http://svn.erp5.org?rev=15969&view=rev
Log:
Add asURL method on telephones like in rfc3966. From Thierry
Modified:
erp5/trunk/products/ERP5/Document/Telephone.py
erp5/trunk/products/ERP5/tests/testERP5HR.py
Modified: erp5/trunk/products/ERP5/Document/Telephone.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Telephone.py?rev=15969&r1=15968&r2=15969&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Telephone.py (original)
+++ erp5/trunk/products/ERP5/Document/Telephone.py Thu Aug 30 20:22:39 2007
@@ -85,11 +85,11 @@
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 @@
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
Modified: erp5/trunk/products/ERP5/tests/testERP5HR.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testERP5HR.py?rev=15969&r1=15968&r2=15969&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testERP5HR.py (original)
+++ erp5/trunk/products/ERP5/tests/testERP5HR.py Thu Aug 30 20:22:39 2007
@@ -842,16 +842,19 @@
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
More information about the Erp5-report
mailing list