本文整理汇总了Python中django_countries.data.COUNTRIES.items方法的典型用法代码示例。如果您正苦于以下问题:Python COUNTRIES.items方法的具体用法?Python COUNTRIES.items怎么用?Python COUNTRIES.items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_countries.data.COUNTRIES
的用法示例。
在下文中一共展示了COUNTRIES.items方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: country_response
# 需要导入模块: from django_countries.data import COUNTRIES [as 别名]
# 或者: from django_countries.data.COUNTRIES import items [as 别名]
def country_response(self):
from django_countries.data import COUNTRIES
countries = sorted(list(COUNTRIES.items()), key=lambda x: x[1].encode('utf-8'))
if self.search_string:
search_string = self.search_string.lower()
return [x for x in countries if x[1].lower().startswith(search_string)]
return countries
示例2: scoreboard
# 需要导入模块: from django_countries.data import COUNTRIES [as 别名]
# 或者: from django_countries.data.COUNTRIES import items [as 别名]
def scoreboard(request):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('login'))
categories = QuestionCategory.objects.all()
countries = COUNTRIES.items()
country = request.POST['country'] if request.POST.has_key('country') else None
category = request.POST['cat_id'] if request.POST.has_key('cat_id') else None
selected_country = country.split('\'')[1] if country else None
quizs = Quiz.objects.all()
if category:
quizs = quizs.filter(category__id=category)
scores = {}
for q in quizs:
if q.competitor1.user.first_name in scores:
scores[q.competitor1.user.first_name] = scores[q.competitor1.user.first_name]+(q.score1 or 0)
else:
if q.competitor1.nationality.code == selected_country or not selected_country:
scores[q.competitor1.user.first_name] = (q.score1 or 0)
if q.competitor2.user.first_name in scores:
scores[q.competitor2.user.first_name] = scores[q.competitor2.user.first_name]+(q.score2 or 0)
else:
if q.competitor2.nationality.code == selected_country or not selected_country:
scores[q.competitor2.user.first_name] = (q.score2 or 0)
scores = sorted(scores.items(), key=operator.itemgetter(1), reverse=True)[:5]
return render_to_response('quiz/scoreboard.html', {'cats':categories, 'category':int(category) if category else category, 'countries':countries, 'selected_country':selected_country, 'scores':scores}, context_instance=RequestContext(request))
示例3: countries
# 需要导入模块: from django_countries.data import COUNTRIES [as 别名]
# 或者: from django_countries.data.COUNTRIES import items [as 别名]
def countries(self):
"""
Return the countries list, modified by any overriding settings.
The result is cached so future lookups are less work intensive.
"""
# Local import so that countries aren't loaded into memory until first
# used.
from django_countries.data import COUNTRIES
if not hasattr(self, '_countries'):
self._countries = []
overrides = settings.COUNTRIES_OVERRIDE
for code, name in COUNTRIES.items():
if code in overrides:
name = overrides['code']
if name:
self.countries.append((code, name))
return self._countries
示例4: __init__
# 需要导入模块: from django_countries.data import COUNTRIES [as 别名]
# 或者: from django_countries.data.COUNTRIES import items [as 别名]
def __init__(self, *args, **kwargs):
super(PublicSMSRateCalculatorForm, self).__init__(*args, **kwargs)
isd_codes = []
countries = sorted(COUNTRIES.items(), key=lambda x: x[1].encode('utf-8'))
for country_shortcode, country_name in countries:
country_isd_code = country_code_for_region(country_shortcode)
isd_codes.append((country_isd_code, country_name))
self.fields['country_code'].choices = isd_codes
self.helper = FormHelper()
self.helper.form_class = "form-horizontal"
self.helper.layout = crispy.Layout(
crispy.Field(
'country_code',
css_class="input-xxlarge",
data_bind="value: country_code",
placeholder=_("Please Select a Country Code"),
),
)
示例5: forwards
# 需要导入模块: from django_countries.data import COUNTRIES [as 别名]
# 或者: from django_countries.data.COUNTRIES import items [as 别名]
def forwards(self, orm):
reverse_map = dict((v.upper(), k) for k, v in COUNTRIES.items())
# add a few special cases to the list that we know might exist
reverse_map['GREAT BRITAIN'] = 'GB'
reverse_map['KOREA'] = 'KR'
reverse_map['MACEDONIA'] = 'MK'
reverse_map['RUSSIA'] = 'RU'
reverse_map['SOUTH KOREA'] = 'KR'
reverse_map['TAIWAN'] = 'TW'
reverse_map['VIETNAM'] = 'VN'
for country_name in orm.Mirror.objects.values_list(
'country_old', flat=True).order_by().distinct():
code = reverse_map.get(country_name.upper(), '')
orm.Mirror.objects.filter(
country_old=country_name).update(country=code)
for country_name in orm.MirrorUrl.objects.filter(
country_old__isnull=False).values_list(
'country_old', flat=True).order_by().distinct():
code = reverse_map.get(country_name.upper(), '')
orm.MirrorUrl.objects.filter(
country_old=country_name).update(country=code)
示例6: construct_address_form
# 需要导入模块: from django_countries.data import COUNTRIES [as 别名]
# 或者: from django_countries.data.COUNTRIES import items [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)
示例7: country_response
# 需要导入模块: from django_countries.data import COUNTRIES [as 别名]
# 或者: from django_countries.data.COUNTRIES import items [as 别名]
def country_response(self):
from django_countries.data import COUNTRIES
countries = sorted(COUNTRIES.items(), key=lambda x: x[1].encode('utf-8'))
if self.search_string:
return filter(lambda x: x[1].lower().startswith(self.search_string.lower()), countries)
return countries