Commit ec45ad2d authored by Rafael Monnerat's avatar Rafael Monnerat

More changes made by lucas to improve code style



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21176 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 54bb06c4
...@@ -67,27 +67,36 @@ class Telephone(Coordinate, Base): ...@@ -67,27 +67,36 @@ class Telephone(Coordinate, Base):
, PropertySheet.Telephone , PropertySheet.Telephone
) )
#The notation always need to have: # The country_dict is used by getRegexDict mapping
#<country> or <area> or <number> or <ext> # the country number to country name
#If uses a different tag it will be ignored. country_dict = {
standard_dict={ '33' : 'france',
'default':{ '55' : 'brazil',
'221' : 'dakar',
'64' : 'tokio'
}
# The notation always need to have:
# <country> or <area> or <number> or <ext>
# If uses a different tag it will be ignored.
standard_dict = {
'default' : {
"input" : "((\+|)(?P<country>[\d]*))(0)?(( |)(\(0\)|)(\(|)(?P<area>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*))", "input" : "((\+|)(?P<country>[\d]*))(0)?(( |)(\(0\)|)(\(|)(?P<area>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*))",
"notation" : "+<country>(0)<area>-<number>/<ext>" "notation" : "+<country>(0)<area>-<number>/<ext>"
}, },
'france':{ 'france' : {
"input" : "((\+|)(?P<country>[\d]*))(0)?(( |)(\(0\)|)(\(|)(?P<area>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*))", "input" : "((\+|)(?P<country>[\d]*))(0)?(( |)(\(0\)|)(\(|)(?P<area>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*))",
"notation" : "+<country>(0)<area>-<number>/<ext>" "notation" : "+<country>(0)<area>-<number>/<ext>"
}, },
'brazil':{ 'brazil' : {
"input" : "((\+|)(?P<country>[\d]*))(0)?(( |)(\(0\)|)(\(|)(?P<area>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*))", "input" : "((\+|)(?P<country>[\d]*))(0)?(( |)(\(0\)|)(\(|)(?P<area>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*))",
"notation" : "+<country>(<area>)<number>/<ext>", "notation" : "+<country>(<area>)<number>/<ext>",
}, },
'dakar':{ 'dakar' : {
"input" : "((\+|)(\(|)(?P<country>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*)", "input" : "((\+|)(\(|)(?P<country>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*)",
"notation" : "+<country> <number>/<ext>", "notation" : "+<country> <number>/<ext>",
}, },
'tokio':{ 'tokio' : {
"input" : "((\+|)(?P<country>[\d]*))(0)?(( |)(\(0\)|)(\(|)(?P<area>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*))", "input" : "((\+|)(?P<country>[\d]*))(0)?(( |)(\(0\)|)(\(|)(?P<area>[\d]*))?((\)|)(-|)(?P<number>[\d^ ^-]*))((\/|)(?P<ext>[\d]*))",
"notation" : "+<country>(<area>)<number>/<ext>", "notation" : "+<country>(<area>)<number>/<ext>",
} }
...@@ -109,16 +118,16 @@ class Telephone(Coordinate, Base): ...@@ -109,16 +118,16 @@ class Telephone(Coordinate, Base):
#Test if coordinate_text has or not markups. #Test if coordinate_text has or not markups.
if len(coordinate_text) > len(onlynumber): if len(coordinate_text) > len(onlynumber):
#trying to get a possible contry number to be used by script #trying to get a possible contry number to be used by script
country=re.match('((\+|)(?P<country>\d*))', \ country = re.match('((\+|)(?P<country>\d*))', \
coordinate_text).groupdict().get('country','') coordinate_text).groupdict().get('country','')
regexdict = self.getRegexDict(index=country) regexdict = self.getRegexDict(index=country)
input_parser = regexdict['input'] input_parser = regexdict.get('input')
number_match = re.match(input_parser, coordinate_text) number_match = re.match(input_parser, coordinate_text)
if not number_match: if not number_match:
return return
number_dict = number_match.groupdict() number_dict = number_match.groupdict()
else: else:
number_dict={'number':coordinate_text} number_dict = {'number' : coordinate_text}
country=number_dict.get('country','') country=number_dict.get('country','')
area=number_dict.get('area','') area=number_dict.get('area','')
...@@ -131,8 +140,8 @@ class Telephone(Coordinate, Base): ...@@ -131,8 +140,8 @@ class Telephone(Coordinate, Base):
(ext in ['', None])): (ext in ['', None])):
country = area = number = extension='' country = area = number = extension=''
else: else:
#The country and area is trying to get from dict, # The country and area is trying to get from dict,
#but if it fails must be get from preference # but if it fails must be get from preference
country = (number_dict.get('country') or \ country = (number_dict.get('country') or \
self.portal_preferences.getPreferredTelephoneDefaultCountryNumber() or \ self.portal_preferences.getPreferredTelephoneDefaultCountryNumber() or \
'').strip() '').strip()
...@@ -164,8 +173,8 @@ class Telephone(Coordinate, Base): ...@@ -164,8 +173,8 @@ class Telephone(Coordinate, Base):
telephone_number = self.getTelephoneNumber() or '' telephone_number = self.getTelephoneNumber() or ''
telephone_extension = self.getTelephoneExtension() or '' telephone_extension = self.getTelephoneExtension() or ''
# If country, area, number, extension are blank the method # If country, area, number, extension are blank
# should to return blank. # the method should to return blank.
if ((telephone_country == '') and \ if ((telephone_country == '') and \
(telephone_area == '') and \ (telephone_area == '') and \
(telephone_number == '') and \ (telephone_number == '') and \
...@@ -173,7 +182,7 @@ class Telephone(Coordinate, Base): ...@@ -173,7 +182,7 @@ class Telephone(Coordinate, Base):
return '' return ''
regexdict = self.getRegexDict(index=telephone_country) regexdict = self.getRegexDict(index=telephone_country)
notation = regexdict['notation'] notation = regexdict.get('notation')
if notation not in [None, '']: if notation not in [None, '']:
notation=notation.replace('<country>',telephone_country) notation=notation.replace('<country>',telephone_country)
...@@ -225,34 +234,29 @@ class Telephone(Coordinate, Base): ...@@ -225,34 +234,29 @@ class Telephone(Coordinate, Base):
# In case of index is a number # In case of index is a number
# should return a region from dict or from form field # should return a region from dict or from form field
if index not in [None,'']: if index not in [None,'']:
countrydict = { # If index is not in country_dict
'33':'france', # the possible country can be found at region field
'55':'brazil', # in context or in preferences
'221':'dakar', if index not in self.country_dict.keys():
'64':'tokio'
}
#If index is not in country list
#the possible country can be found at region field
if index not in countrydict.keys():
region = self.getRegion() or \ region = self.getRegion() or \
self.portal_preferences.getPreferredTelephoneDefaultRegion() self.portal_preferences.getPreferredTelephoneDefaultRegion()
else: else:
region = countrydict.get(index,'') region = self.country_dict.get(index,'')
else: else:
region = self.getRegion() or \ region = self.getRegion() or \
self.portal_preferences.getPreferredTelephoneDefaultRegion() self.portal_preferences.getPreferredTelephoneDefaultRegion()
# Find the region in regexdict # Find the region in standard_dict
if region is not None: if region is not None:
regionlist=region.split('/') region_list=region.split('/')
for i in regionlist: for i in region_list:
if self.standard_dict.get(i) is not None: if self.standard_dict.get(i) is not None:
region = i region = i
# If region doesn't exist the script should to return a default regex. # If region doesn't exist this method
# should to return a default regex.
if region not in self.standard_dict.keys() or region is None: if region not in self.standard_dict.keys() or region is None:
region = 'default' region = 'default'
dict = self.standard_dict.get(region) dict = self.standard_dict.get(region)
return dict return dict
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