- Timestamp:
- 15 Jan 2010, 11:37:03 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-importers/src/waeup/utils/converters.py
r4810 r4814 8 8 except ImportError: 9 9 from zope.browser.interfaces import ITerms 10 from zope.schema.interfaces import I Text, IInt, IChoice10 from zope.schema.interfaces import IBool, IText, IInt, IChoice 11 11 from waeup.interfaces import ISchemaTypeConverter 12 12 … … 42 42 self.context.validate(result) 43 43 return result 44 45 def _convertValueToString(self, value): 46 return str(value) 47 48 def toString(self, value, strict=True): 49 if strict: 50 self.context.validate(value) 51 if value == self.context.missing_value: 52 return None 53 return self._convertValueToString(value) 54 55 class BoolConverter(Converter): 56 grok.context(IBool) 57 grok.provides(ISchemaTypeConverter) 58 59 def _convertValueFromString(self, string): 60 if string is None: 61 return None 62 if string.lower() in ['1', 'true', 'yes']: 63 return True 64 return False 65 66 def _convertValueToString(self, value): 67 if value is None: 68 return None 69 if value: 70 return '1' 71 return '0' 44 72 45 73 class TextConverter(Converter): … … 67 95 (self.context.source, TestRequest()), ITerms) 68 96 except: 69 pass97 self.terms = None 70 98 71 99 def _convertValueFromString(self, string): 72 try: 73 return self.context.source.getTermByToken(string).value 74 except AttributeError: 75 self.terms = getMultiAdapter( 76 (self.context.source, TestRequest()), ITerms) 100 if self.terms is not None: 77 101 return self.terms.getValue(string) 102 return self.context.source.getTermByToken(string).value 78 103 104 def _convertValueToString(self, value): 105 if self.terms is not None: 106 return self.terms.getTerm(value).token 107 return str(value)
Note: See TracChangeset for help on using the changeset viewer.