def validate(self, code): try: i18n.get_locale().territories[code] except KeyError: raise ValueError( 'Could not convert string to country code: {0}'.format(code) )
def get_name(self, width='wide', context='format'): names = i18n.get_day_names( width, context, i18n.get_locale() ) return names[self.index]
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))
def get_current_locale(obj): from sqlalchemy_utils import i18n locale = i18n.get_locale() if locale: return str(locale) return obj.locale
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))
def position(self): return ( self.index - i18n.get_locale().first_week_day ) % self.NUM_WEEK_DAYS
def name(self): return i18n.get_locale().territories[self.code]
def name(self): return i18n.get_locale().currencies[self.code]
def symbol(self): return i18n.babel.numbers.get_currency_symbol( self.code, i18n.get_locale() )
def get_name(self, width='wide', context='format'): names = i18n.get_day_names(width, context, i18n.get_locale()) return names[self.index]
def validate(self, code): try: i18n.get_locale().territories[code] except KeyError: raise ValueError( 'Could not convert string to country code: {0}'.format(code))
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())))
def validate(self, code): try: i18n.get_locale().currencies[code] except KeyError: raise ValueError("{0}' is not valid currency code.")