Changeset 7874 for main/waeup.kofa/trunk/src/waeup/kofa/widgets
- Timestamp:
- 14 Mar 2012, 03:19:19 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/widgets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/widgets/phonewidget.py
r7871 r7874 21 21 import grok 22 22 import re 23 from zope.component import getUtility23 from zope.component import queryUtility 24 24 from zope.formlib.interfaces import MissingInputError, InputErrors 25 25 from zope.interface import Interface 26 26 from zope.formlib.textwidgets import ( 27 27 TextWidget, renderElement, ConversionError) 28 from waeup.kofa.interfaces import IKofaUtils 28 29 from waeup.kofa.interfaces import MessageFactory as _ 29 30 class IInternationalPhonePrefixes(Interface): 31 """A dict of international phone number prefixes. 32 """ 33 34 class PhonePrefixes(grok.GlobalUtility): 35 grok.implements(IInternationalPhonePrefixes) 36 37 def title_value_list(self): 38 try: 39 from waeup.kofa.interfaces import IKofaUtils 40 prefixes = getUtility(IKofaUtils).INT_PHONE_PREFIXES 41 data = sorted(prefixes.items(), key=lambda value: value[1][0]) 42 except: 43 data = [('Country of Nowhere',(1, '234'))] 44 return [('%s (+%s)' % (x,y[1]), '+%s' % y[1]) for x,y in data] 30 from waeup.kofa.utils.utils import KofaUtils 45 31 46 32 RE_INT_PREFIX = re.compile('^\+\d+') … … 53 39 54 40 def _renderPrefixWidget(self, value): 55 prefixes = getUtility( 56 IInternationalPhonePrefixes).title_value_list() 41 prefix_func = getattr( 42 queryUtility(IKofaUtils), 'sorted_phone_prefixes', 43 KofaUtils.sorted_phone_prefixes) 57 44 options = [] 58 for ptitle, pval in prefix es:45 for ptitle, pval in prefix_func(request=self.request): 59 46 selected = '' 60 47 if value == pval: -
main/waeup.kofa/trunk/src/waeup/kofa/widgets/tests/test_phonewidget.py
r7855 r7874 30 30 from zope.publisher.browser import TestRequest 31 31 from zope.schema.interfaces import ITextLine 32 from waeup.kofa.widgets.phonewidget import PhoneWidget , PhonePrefixes32 from waeup.kofa.widgets.phonewidget import PhoneWidget 33 33 34 34 # Dummy content … … 74 74 (ITextLine, TextWidget), 75 75 ] 76 77 def setUp(self):78 super(PhoneWidgetTests, self).setUp()79 # register the phone prefixes utility80 self.gsm = getGlobalSiteManager()81 self.reg_prefixes = PhonePrefixes()82 self.gsm.registerUtility(self.reg_prefixes)83 return84 85 def tearDown(self):86 self.gsm.unregisterUtility(self.reg_prefixes)87 return88 76 89 77 def test_display_editform(self):
Note: See TracChangeset for help on using the changeset viewer.