Changeset 7352 for main/waeup.sirp/trunk/src
- Timestamp:
- 15 Dec 2011, 12:19:43 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/widgets/phonewidget.py
r7342 r7352 16 16 zope.formlib or newer form libs). Therefore some modifications were 17 17 neccessary and it might look a bit overloaded. 18 19 If you use the PhoneWidget for rendering regular TextLine attributes 20 (preferably in edit forms or add forms), the phone number is displayed 21 by three input fields representing the international code, the area 22 code and the extension line. All three fields require pure numbers as 23 input and do not accept other chars. 24 25 When the entered input is stored with a context object, it is stored 26 as a single unicode string with the numbers divided by single hyphen. 27 28 So, input <12>, <111>, <444> becomes the string ``'12-111-444'`` for 29 the context object. 30 18 31 """ 19 32 import re … … 62 75 63 76 def __init__(self, context, number=None): 77 """Set countrycode, areacode, and extension line from number. 78 """ 64 79 self.context = context 65 if number is not None: 66 # XXX: We have to provide something more tolerant 67 self.country, self.area, self.extension = number.split('-') 80 if number is None: 68 81 return 69 try: 70 self.country, self.area, self.extension = number.split('-') 71 except ValueError: 72 replacement = '1-1-%s' % (number.replace('-', ''),) 73 self.country, self.area, self.extension = replacement.split( 74 '-', 2) 82 # handle other types than strings. 83 if not isinstance(number, basestring): 84 number = str(number) 85 parts = number.split('-', 2) 86 if len(parts) == 2: 87 parts = [None,] + parts 88 elif len(parts) == 0: 89 return 90 elif len(parts) == 1: 91 parts = [None, None] + parts 92 self.country, self.area, self.extension = parts 93 return 75 94 76 95 @property 77 96 def number(self): 78 return u'-'.join((self.country, self.area, self.extension)) 97 """Return a valid phone number string of format ``<IC>-<AC>-<EL>``. 98 99 where <IC> is the country code (digits only), <AC> is the area 100 code and <EL> is the extension line. 101 """ 102 return u'-'.join( 103 (self.country or '', self.area or '', self.extension)) 79 104 80 105
Note: See TracChangeset for help on using the changeset viewer.