本文整理汇总了Python中django_countries.data.COUNTRIES.keys方法的典型用法代码示例。如果您正苦于以下问题:Python COUNTRIES.keys方法的具体用法?Python COUNTRIES.keys怎么用?Python COUNTRIES.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_countries.data.COUNTRIES
的用法示例。
在下文中一共展示了COUNTRIES.keys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dict
# 需要导入模块: from django_countries.data import COUNTRIES [as 别名]
# 或者: from django_countries.data.COUNTRIES import keys [as 别名]
from .image_generator import generate_image
DEFAULT_IDENTIFIER = "default"
DEFAULT_NAME = "Default"
DEFAULT_ADDRESS_DATA = dict(
prefix="Sir",
name=u"Dog Hello",
suffix=", Esq.",
postal_code="K9N",
street="Woof Ave.",
city="Dog Fort",
country="GB"
)
COUNTRY_CODES = sorted(COUNTRIES.keys())
class FuzzyBoolean(fuzzy.BaseFuzzyAttribute):
def __init__(self, probability, **kwargs):
self.probability = probability
super(FuzzyBoolean, self).__init__()
def fuzz(self):
return (random.random() < self.probability)
class UserFactory(DjangoModelFactory):
class Meta:
model = settings.AUTH_USER_MODEL
示例2: construct_address_form
# 需要导入模块: from django_countries.data import COUNTRIES [as 别名]
# 或者: from django_countries.data.COUNTRIES import keys [as 别名]
def construct_address_form(country_code, i18n_rules):
class_name = 'AddressForm%s' % country_code
base_class = CountryAwareAddressForm
form_kwargs = {
'Meta': type(str('Meta'), (base_class.Meta, object), {}),
'formfield_callback': None}
class_ = type(base_class)(str(class_name), (base_class, ), form_kwargs)
update_base_fields(class_, i18n_rules)
class_.i18n_country_code = country_code
class_.i18n_fields_order = property(get_form_i18n_lines)
return class_
for country in COUNTRIES.keys():
try:
country_rules = i18naddress.get_validation_rules(
{'country_code': country})
except ValueError:
country_rules = i18naddress.get_validation_rules({})
UNKNOWN_COUNTRIES.add(country)
COUNTRY_CHOICES = [(code, label) for code, label in COUNTRIES.items()
if code not in UNKNOWN_COUNTRIES]
# Sort choices list by country name
COUNTRY_CHOICES = sorted(COUNTRY_CHOICES, key=lambda choice: choice[1])
for country, label in COUNTRY_CHOICES:
country_rules = i18naddress.get_validation_rules({'country_code': country})
COUNTRY_FORMS[country] = construct_address_form(country, country_rules)