Example #1
0
def get_phone_prefix(country_code):
    """
    Return international phone country prefix.
    """
    # noinspection PyCompatibility
    for prefix, countries in _COUNTRY_CODE_TO_REGION_CODE.iteritems():
        if country_code in countries:
            return '+%d' % prefix

    return ''
Example #2
0
 def __init__(self, initial=None):
     choices = [('', '---------')]
     locale = Locale(translation.get_language())
     for prefix, values in _COUNTRY_CODE_TO_REGION_CODE.iteritems():
         prefix = '+%d' % prefix
         if initial and initial in values:
             self.initial = prefix
         for country_code in values:
             country_name = locale.territories.get(country_code)
             if country_name:
                 choices.append((prefix, u'%s %s' % (country_name, prefix)))
     return super(PhonePrefixSelect, self).__init__(choices=sorted(choices, key=lambda item: item[1]))
Example #3
0
 def __init__(self, initial=None):
     choices = [('', '---------')]
     locale = Locale(translation.get_language())
     for prefix, values in _COUNTRY_CODE_TO_REGION_CODE.iteritems():
         prefix = '+%d' % prefix
         if initial and initial in values:
             self.initial = prefix
         for country_code in values:
             country_name = locale.territories.get(country_code)
             if country_name:
                 choices.append((prefix, u'%s %s' % (country_name, prefix)))
     return super(PhonePrefixSelect, self).__init__(choices=sorted(choices, key=lambda item: item[1]))
Example #4
0
 def __init__(self, initial):
     choices = [('', '---------')]
     locale = Locale(to_locale(translation.get_language()))
     for prefix, values in _COUNTRY_CODE_TO_REGION_CODE.iteritems():
         prefix = '+%d' % prefix
         if initial and initial in values:
             self.initial = prefix
         for country_code in values:
             country_name = locale.territories.get(country_code)
             if country_name:
                 # noinspection PyTypeChecker
                 choices.append(
                     (prefix, (
                         u'%s' % prefix,
                         {
                             u'data-image': u'/static/country-dropdown/images/msdropdown/icons/blank.gif',
                             u'data-imagecss': u'flag {0}'.format(country_code.lower()),
                             u'data-title': force_unicode(country_name),
                         }
                     )))
     super(PhonePrefixSelect, self).__init__(choices=sorted(choices, key=lambda item: item[1]))