本文整理汇总了Python中django_countries.data.COUNTRIES.iteritems方法的典型用法代码示例。如果您正苦于以下问题:Python COUNTRIES.iteritems方法的具体用法?Python COUNTRIES.iteritems怎么用?Python COUNTRIES.iteritems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_countries.data.COUNTRIES
的用法示例。
在下文中一共展示了COUNTRIES.iteritems方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from django_countries.data import COUNTRIES [as 别名]
# 或者: from django_countries.data.COUNTRIES import iteritems [as 别名]
def handle(self, *args, **options):
print "Migrating Domain countries"
country_lookup = {v.lower(): k for k, v in COUNTRIES.iteritems()}
#Special cases
country_lookup["USA"] = country_lookup["united states"]
country_lookup["California"] = country_lookup["united states"]
country_lookup["Wales"] = country_lookup["united kingdom"]
for domain in Domain.get_all():
if domain.deployment._doc.get('countries', None):
continue
try:
country = None
if domain.deployment._doc.get('country', None):
country = domain.deployment._doc['country']
elif domain._doc.get('country', None):
country = domain._doc['country']
if country:
if ',' in country:
countries = country.split(',')
elif ' and ' in country:
countries = country.split(' and ')
else:
countries = [country]
abbr = []
for country in countries:
country = country.strip().lower()
if country in country_lookup.keys():
abbr.append(country_lookup[country])
domain.deployment.countries = abbr
domain.save()
except Exception as e:
print "There was an error migrating the domain named %s." % domain.name
print "Error: %s" % e