Commit e004ba95 authored by Bartek Górny's avatar Bartek Górny

a little improvement in parsing telephone number given as text, and in returning number as text

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14672 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3912c64e
......@@ -63,7 +63,11 @@ class Telephone(Coordinate, Base):
# The standard parser is used to read phone numbers
# written in a standard syntax
standard_parser = re.compile('\+(.*)\((.*)\)(.*)\-(.*)')
# +[country]([area])[number]/[extension]
# or in syntax retured by asText
# +[country](0)[area]-[number]/[extension]
standard_parser = re.compile('\+(?P<country>\d{,2})\(0\)(?P<area>\d+)-(?P<number>[^/]+)(\/(?P<ext>\d+))?')
input_parser = re.compile('(\+(?P<country>\d*))?(\((?P<area>\d*)\))?(?P<number>[^/]*)(\/(?P<ext>\d+))?')
# Declarative properties
property_sheets = ( PropertySheet.Base
......@@ -81,15 +85,19 @@ class Telephone(Coordinate, Base):
if coordinate_text is None:
coordinate_text = ''
if self.standard_parser.match(coordinate_text):
(country, temp, area, number) = \
self.standard_parser.match(coordinate_text).groups()
else:
country = area = ''
number = 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('-', ' ')
extension = (number_dict.get('ext', '') or '').strip()
self.edit(telephone_country = country,
telephone_area = area,
telephone_number = number, )
telephone_number = number,
telephone_extension = extension)
security.declareProtected(Permissions.ModifyPortalContent, '_setText')
_setText = fromText
......@@ -115,9 +123,13 @@ class Telephone(Coordinate, Base):
text += '-'
telephone_number = self.getTelephoneNumber()
if self.telephone_number is not None:
if telephone_number is not None:
text += telephone_number
telephone_extension = self.getTelephoneExtension()
if telephone_extension is not None:
text += '/' + telephone_extension
if text == '+(0)-':
text = ''
return text
......
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