Exemplo n.º 1
0
 def validate(self, code):
     try:
         i18n.get_locale().territories[code]
     except KeyError:
         raise ValueError(
             'Could not convert string to country code: {0}'.format(code)
         )
Exemplo n.º 2
0
 def get_name(self, width='wide', context='format'):
     names = i18n.get_day_names(
         width,
         context,
         i18n.get_locale()
     )
     return names[self.index]
Exemplo n.º 3
0
def get_all_countries():
    territories = [
        (code, name)
        for code, name in i18n.get_locale().territories.items()
        if len(code) == 2 and code not in ('QO', 'QU', 'ZZ')
    ]
    return sorted(territories, key=operator.itemgetter(1))
Exemplo n.º 4
0
def get_current_locale(obj):
    from sqlalchemy_utils import i18n

    locale = i18n.get_locale()
    if locale:
        return str(locale)
    return obj.locale
Exemplo n.º 5
0
 def _get_choices(self):
     # Get all territories and filter out continents (3-digit code)
     # and some odd territories such as "Unknown or Invalid Region"
     # ("ZZ"), "European Union" ("QU") and "Outlying Oceania" ("QO").
     territories = [
         (code, name)
         for code, name in i18n.get_locale().territories.iteritems()
         if len(code) == 2 and code not in ('QO', 'QU', 'ZZ')
     ]
     return sorted(territories, key=operator.itemgetter(1))
Exemplo n.º 6
0
 def position(self):
     return (
         self.index -
         i18n.get_locale().first_week_day
     ) % self.NUM_WEEK_DAYS
Exemplo n.º 7
0
 def name(self):
     return i18n.get_locale().territories[self.code]
Exemplo n.º 8
0
 def name(self):
     return i18n.get_locale().currencies[self.code]
Exemplo n.º 9
0
 def symbol(self):
     return i18n.babel.numbers.get_currency_symbol(
         self.code,
         i18n.get_locale()
     )
Exemplo n.º 10
0
 def get_name(self, width='wide', context='format'):
     names = i18n.get_day_names(width, context, i18n.get_locale())
     return names[self.index]
Exemplo n.º 11
0
 def validate(self, code):
     try:
         i18n.get_locale().territories[code]
     except KeyError:
         raise ValueError(
             'Could not convert string to country code: {0}'.format(code))
Exemplo n.º 12
0
 def name(self):
     return i18n.get_locale().territories[self.code]
Exemplo n.º 13
0
def compile_current_locale(element, compiler, **kw):
    # Lazy import get_locale so that it can be overridden
    from sqlalchemy_utils.i18n import get_locale

    return '%s' % compiler.process(
        sa.bindparam('current_locale', str(get_locale())))
Exemplo n.º 14
0
 def position(self):
     return (
         self.index -
         i18n.get_locale().first_week_day
     ) % self.NUM_WEEK_DAYS
Exemplo n.º 15
0
 def validate(self, code):
     try:
         i18n.get_locale().currencies[code]
     except KeyError:
         raise ValueError("{0}' is not valid currency code.")