Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Switch to using django-countries

Patryk Zawadzki99a86b00ea50
diff --git a/requirements.in b/requirements.in
index e346c98d28..e88fc309e5 100644
--- a/requirements.in
+++ b/requirements.in
@@ -4,6 +4,7 @@ Django>=1.8,!=1.8.6
dj_database_url>=0.3.0
dj_email_url>=0.0.4
django-cache-url>=1.0.0
+django-countries>=3.4
django-emailit>=0.2.2
django-materializecss-form>=0.1
django-model-utils>=2.3
diff --git a/requirements.txt b/requirements.txt
index 9108d069d6..423e9b0bdc 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -16,6 +16,7 @@ dj-database-url==0.3.0
dj-email-url==0.0.4
django-absolute==0.3 # via django-emailit
django-cache-url==1.0.0
+django-countries==3.4.1
django-emailit==0.2.2
django-materializecss-form==0.1
django-model-utils==2.4
@@ -40,7 +41,7 @@ markdown==2.6.5
mock==1.3.0
pbr==1.8.1 # via mock
pillow==3.1.0 # via django-versatileimagefield
-premailer==2.9.6 # via django-emailit
+premailer==2.9.7 # via django-emailit
prices==0.5.5
psycopg2==2.6.1
purl==1.1
diff --git a/saleor/core/countries.py b/saleor/core/countries.py
deleted file mode 100644
index cb0e8afce9..0000000000
--- a/saleor/core/countries.py
+++ /dev/null
@@ -1,259 +0,0 @@
-# coding: utf-8
-
-from __future__ import unicode_literals
-
-from django.utils.translation import pgettext_lazy
-
-COUNTRY_CHOICES = [
- ('AF', pgettext_lazy('Country', 'Afghanistan')),
- ('AX', pgettext_lazy('Country', 'Åland Islands')),
- ('AL', pgettext_lazy('Country', 'Albania')),
- ('DZ', pgettext_lazy('Country', 'Algeria')),
- ('AS', pgettext_lazy('Country', 'American Samoa')),
- ('AD', pgettext_lazy('Country', 'Andorra')),
- ('AO', pgettext_lazy('Country', 'Angola')),
- ('AI', pgettext_lazy('Country', 'Anguilla')),
- ('AQ', pgettext_lazy('Country', 'Antarctica')),
- ('AG', pgettext_lazy('Country', 'Antigua And Barbuda')),
- ('AR', pgettext_lazy('Country', 'Argentina')),
- ('AM', pgettext_lazy('Country', 'Armenia')),
- ('AW', pgettext_lazy('Country', 'Aruba')),
- ('AU', pgettext_lazy('Country', 'Australia')),
- ('AT', pgettext_lazy('Country', 'Austria')),
- ('AZ', pgettext_lazy('Country', 'Azerbaijan')),
- ('BS', pgettext_lazy('Country', 'Bahamas')),
- ('BH', pgettext_lazy('Country', 'Bahrain')),
- ('BD', pgettext_lazy('Country', 'Bangladesh')),
- ('BB', pgettext_lazy('Country', 'Barbados')),
- ('BY', pgettext_lazy('Country', 'Belarus')),
- ('BE', pgettext_lazy('Country', 'Belgium')),
- ('BZ', pgettext_lazy('Country', 'Belize')),
- ('BJ', pgettext_lazy('Country', 'Benin')),
- ('BM', pgettext_lazy('Country', 'Bermuda')),
- ('BT', pgettext_lazy('Country', 'Bhutan')),
- ('BO', pgettext_lazy('Country', 'Bolivia')),
- ('BQ', pgettext_lazy('Country', 'Bonaire, Saint Eustatius And Saba')),
- ('BA', pgettext_lazy('Country', 'Bosnia And Herzegovina')),
- ('BW', pgettext_lazy('Country', 'Botswana')),
- ('BV', pgettext_lazy('Country', 'Bouvet Island')),
- ('BR', pgettext_lazy('Country', 'Brazil')),
- ('IO', pgettext_lazy('Country', 'British Indian Ocean Territory')),
- ('BN', pgettext_lazy('Country', 'Brunei Darussalam')),
- ('BG', pgettext_lazy('Country', 'Bulgaria')),
- ('BF', pgettext_lazy('Country', 'Burkina Faso')),
- ('BI', pgettext_lazy('Country', 'Burundi')),
- ('KH', pgettext_lazy('Country', 'Cambodia')),
- ('CM', pgettext_lazy('Country', 'Cameroon')),
- ('CA', pgettext_lazy('Country', 'Canada')),
- ('CV', pgettext_lazy('Country', 'Cape Verde')),
- ('KY', pgettext_lazy('Country', 'Cayman Islands')),
- ('CF', pgettext_lazy('Country', 'Central African Republic')),
- ('TD', pgettext_lazy('Country', 'Chad')),
- ('CL', pgettext_lazy('Country', 'Chile')),
- ('CN', pgettext_lazy('Country', 'China')),
- ('CX', pgettext_lazy('Country', 'Christmas Island')),
- ('CC', pgettext_lazy('Country', 'Cocos (Keeling) Islands')),
- ('CO', pgettext_lazy('Country', 'Colombia')),
- ('KM', pgettext_lazy('Country', 'Comoros')),
- ('CG', pgettext_lazy('Country', 'Congo')),
- ('CD', pgettext_lazy('Country', 'Congo, The Democratic Republic of the')),
- ('CK', pgettext_lazy('Country', 'Cook Islands')),
- ('CR', pgettext_lazy('Country', 'Costa Rica')),
- ('CI', pgettext_lazy('Country', 'Côte D\'Ivoire')),
- ('HR', pgettext_lazy('Country', 'Croatia')),
- ('CU', pgettext_lazy('Country', 'Cuba')),
- ('CW', pgettext_lazy('Country', 'Curaço')),
- ('CY', pgettext_lazy('Country', 'Cyprus')),
- ('CZ', pgettext_lazy('Country', 'Czech Republic')),
- ('DK', pgettext_lazy('Country', 'Denmark')),
- ('DJ', pgettext_lazy('Country', 'Djibouti')),
- ('DM', pgettext_lazy('Country', 'Dominica')),
- ('DO', pgettext_lazy('Country', 'Dominican Republic')),
- ('EC', pgettext_lazy('Country', 'Ecuador')),
- ('EG', pgettext_lazy('Country', 'Egypt')),
- ('SV', pgettext_lazy('Country', 'El Salvador')),
- ('GQ', pgettext_lazy('Country', 'Equatorial Guinea')),
- ('ER', pgettext_lazy('Country', 'Eritrea')),
- ('EE', pgettext_lazy('Country', 'Estonia')),
- ('ET', pgettext_lazy('Country', 'Ethiopia')),
- ('FK', pgettext_lazy('Country', 'Falkland Islands (Malvinas)')),
- ('FO', pgettext_lazy('Country', 'Faroe Islands')),
- ('FJ', pgettext_lazy('Country', 'Fiji')),
- ('FI', pgettext_lazy('Country', 'Finland')),
- ('FR', pgettext_lazy('Country', 'France')),
- ('GF', pgettext_lazy('Country', 'French Guiana')),
- ('PF', pgettext_lazy('Country', 'French Polynesia')),
- ('TF', pgettext_lazy('Country', 'French Southern Territories')),
- ('GA', pgettext_lazy('Country', 'Gabon')),
- ('GM', pgettext_lazy('Country', 'Gambia')),
- ('GE', pgettext_lazy('Country', 'Georgia')),
- ('DE', pgettext_lazy('Country', 'Germany')),
- ('GH', pgettext_lazy('Country', 'Ghana')),
- ('GI', pgettext_lazy('Country', 'Gibraltar')),
- ('GR', pgettext_lazy('Country', 'Greece')),
- ('GL', pgettext_lazy('Country', 'Greenland')),
- ('GD', pgettext_lazy('Country', 'Grenada')),
- ('GP', pgettext_lazy('Country', 'Guadeloupe')),
- ('GU', pgettext_lazy('Country', 'Guam')),
- ('GT', pgettext_lazy('Country', 'Guatemala')),
- ('GG', pgettext_lazy('Country', 'Guernsey')),
- ('GN', pgettext_lazy('Country', 'Guinea')),
- ('GW', pgettext_lazy('Country', 'Guinea-Bissau')),
- ('GY', pgettext_lazy('Country', 'Guyana')),
- ('HT', pgettext_lazy('Country', 'Haiti')),
- ('HM', pgettext_lazy('Country', 'Heard Island And Mcdonald Islands')),
- ('VA', pgettext_lazy('Country', 'Holy See (Vatican City State)')),
- ('HN', pgettext_lazy('Country', 'Honduras')),
- ('HK', pgettext_lazy('Country', 'Hong Kong')),
- ('HU', pgettext_lazy('Country', 'Hungary')),
- ('IS', pgettext_lazy('Country', 'Iceland')),
- ('IN', pgettext_lazy('Country', 'India')),
- ('ID', pgettext_lazy('Country', 'Indonesia')),
- ('IR', pgettext_lazy('Country', 'Iran, Islamic Republic of')),
- ('IQ', pgettext_lazy('Country', 'Iraq')),
- ('IE', pgettext_lazy('Country', 'Ireland')),
- ('IM', pgettext_lazy('Country', 'Isle of Man')),
- ('IL', pgettext_lazy('Country', 'Israel')),
- ('IT', pgettext_lazy('Country', 'Italy')),
- ('JM', pgettext_lazy('Country', 'Jamaica')),
- ('JP', pgettext_lazy('Country', 'Japan')),
- ('JE', pgettext_lazy('Country', 'Jersey')),
- ('JO', pgettext_lazy('Country', 'Jordan')),
- ('KZ', pgettext_lazy('Country', 'Kazakhstan')),
- ('KE', pgettext_lazy('Country', 'Kenya')),
- ('KI', pgettext_lazy('Country', 'Kiribati')),
- ('KP', pgettext_lazy('Country',
- 'Korea, Democratic People\'s Republic of')),
- ('KR', pgettext_lazy('Country', 'Korea, Republic of')),
- ('KW', pgettext_lazy('Country', 'Kuwait')),
- ('KG', pgettext_lazy('Country', 'Kyrgyzstan')),
- ('LA', pgettext_lazy('Country', 'Lao People\'s Democratic Republic')),
- ('LV', pgettext_lazy('Country', 'Latvia')),
- ('LB', pgettext_lazy('Country', 'Lebanon')),
- ('LS', pgettext_lazy('Country', 'Lesotho')),
- ('LR', pgettext_lazy('Country', 'Liberia')),
- ('LY', pgettext_lazy('Country', 'Libya')),
- ('LI', pgettext_lazy('Country', 'Liechtenstein')),
- ('LT', pgettext_lazy('Country', 'Lithuania')),
- ('LU', pgettext_lazy('Country', 'Luxembourg')),
- ('MO', pgettext_lazy('Country', 'Macao')),
- ('MK', pgettext_lazy('Country',
- 'Macedonia, The Former Yugoslav Republic of')),
- ('MG', pgettext_lazy('Country', 'Madagascar')),
- ('MW', pgettext_lazy('Country', 'Malawi')),
- ('MY', pgettext_lazy('Country', 'Malaysia')),
- ('MV', pgettext_lazy('Country', 'Maldives')),
- ('ML', pgettext_lazy('Country', 'Mali')),
- ('MT', pgettext_lazy('Country', 'Malta')),
- ('MH', pgettext_lazy('Country', 'Marshall Islands')),
- ('MQ', pgettext_lazy('Country', 'Martinique')),
- ('MR', pgettext_lazy('Country', 'Mauritania')),
- ('MU', pgettext_lazy('Country', 'Mauritius')),
- ('YT', pgettext_lazy('Country', 'Mayotte')),
- ('MX', pgettext_lazy('Country', 'Mexico')),
- ('FM', pgettext_lazy('Country', 'Micronesia, Federated States of')),
- ('MD', pgettext_lazy('Country', 'Moldova, Republic of')),
- ('MC', pgettext_lazy('Country', 'Monaco')),
- ('MN', pgettext_lazy('Country', 'Mongolia')),
- ('ME', pgettext_lazy('Country', 'Montenegro')),
- ('MS', pgettext_lazy('Country', 'Montserrat')),
- ('MA', pgettext_lazy('Country', 'Morocco')),
- ('MZ', pgettext_lazy('Country', 'Mozambique')),
- ('MM', pgettext_lazy('Country', 'Myanmar')),
- ('NA', pgettext_lazy('Country', 'Namibia')),
- ('NR', pgettext_lazy('Country', 'Nauru')),
- ('NP', pgettext_lazy('Country', 'Nepal')),
- ('NL', pgettext_lazy('Country', 'Netherlands')),
- ('NC', pgettext_lazy('Country', 'New Caledonia')),
- ('NZ', pgettext_lazy('Country', 'New Zealand')),
- ('NI', pgettext_lazy('Country', 'Nicaragua')),
- ('NE', pgettext_lazy('Country', 'Niger')),
- ('NG', pgettext_lazy('Country', 'Nigeria')),
- ('NU', pgettext_lazy('Country', 'Niue')),
- ('NF', pgettext_lazy('Country', 'Norfolk Island')),
- ('MP', pgettext_lazy('Country', 'Northern Mariana Islands')),
- ('NO', pgettext_lazy('Country', 'Norway')),
- ('OM', pgettext_lazy('Country', 'Oman')),
- ('PK', pgettext_lazy('Country', 'Pakistan')),
- ('PW', pgettext_lazy('Country', 'Palau')),
- ('PS', pgettext_lazy('Country', 'Palestinian Territory, Occupied')),
- ('PA', pgettext_lazy('Country', 'Panama')),
- ('PG', pgettext_lazy('Country', 'Papua New Guinea')),
- ('PY', pgettext_lazy('Country', 'Paraguay')),
- ('PE', pgettext_lazy('Country', 'Peru')),
- ('PH', pgettext_lazy('Country', 'Philippines')),
- ('PN', pgettext_lazy('Country', 'Pitcairn')),
- ('PL', pgettext_lazy('Country', 'Poland')),
- ('PT', pgettext_lazy('Country', 'Portugal')),
- ('PR', pgettext_lazy('Country', 'Puerto Rico')),
- ('QA', pgettext_lazy('Country', 'Qatar')),
- ('RE', pgettext_lazy('Country', 'Réunion')),
- ('RO', pgettext_lazy('Country', 'Romania')),
- ('RU', pgettext_lazy('Country', 'Russian Federation')),
- ('RW', pgettext_lazy('Country', 'Rwanda')),
- ('BL', pgettext_lazy('Country', 'Saint Barthélemy')),
- ('SH', pgettext_lazy('Country',
- 'Saint Helena, Ascension And Tristan Da Cunha')),
- ('KN', pgettext_lazy('Country', 'Saint Kitts And Nevis')),
- ('LC', pgettext_lazy('Country', 'Saint Lucia')),
- ('MF', pgettext_lazy('Country', 'Saint Martin (French Part)')),
- ('PM', pgettext_lazy('Country', 'Saint Pierre And Miquelon')),
- ('VC', pgettext_lazy('Country', 'Saint Vincent And the Grenadines')),
- ('WS', pgettext_lazy('Country', 'Samoa')),
- ('SM', pgettext_lazy('Country', 'San Marino')),
- ('ST', pgettext_lazy('Country', 'Sao Tome And Principe')),
- ('SA', pgettext_lazy('Country', 'Saudi Arabia')),
- ('SN', pgettext_lazy('Country', 'Senegal')),
- ('RS', pgettext_lazy('Country', 'Serbia')),
- ('SC', pgettext_lazy('Country', 'Seychelles')),
- ('SL', pgettext_lazy('Country', 'Sierra Leone')),
- ('SG', pgettext_lazy('Country', 'Singapore')),
- ('SX', pgettext_lazy('Country', 'Sint Maarten (Dutch Part)')),
- ('SK', pgettext_lazy('Country', 'Slovakia')),
- ('SI', pgettext_lazy('Country', 'Slovenia')),
- ('SB', pgettext_lazy('Country', 'Solomon Islands')),
- ('SO', pgettext_lazy('Country', 'Somalia')),
- ('ZA', pgettext_lazy('Country', 'South Africa')),
- ('GS', pgettext_lazy('Country',
- 'South Georgia and the South Sandwich Islands')),
- ('ES', pgettext_lazy('Country', 'Spain')),
- ('LK', pgettext_lazy('Country', 'Sri Lanka')),
- ('SD', pgettext_lazy('Country', 'Sudan')),
- ('SR', pgettext_lazy('Country', 'Suriname')),
- ('SJ', pgettext_lazy('Country', 'Svalbard and Jan Mayen')),
- ('SZ', pgettext_lazy('Country', 'Swaziland')),
- ('SE', pgettext_lazy('Country', 'Sweden')),
- ('CH', pgettext_lazy('Country', 'Switzerland')),
- ('SY', pgettext_lazy('Country', 'Syria')),
- ('TW', pgettext_lazy('Country', 'Taiwan')),
- ('TJ', pgettext_lazy('Country', 'Tajikistan')),
- ('TZ', pgettext_lazy('Country', 'Tanzania')),
- ('TH', pgettext_lazy('Country', 'Thailand')),
- ('TL', pgettext_lazy('Country', 'Timor-Leste')),
- ('TG', pgettext_lazy('Country', 'Togo')),
- ('TK', pgettext_lazy('Country', 'Tokelau')),
- ('TO', pgettext_lazy('Country', 'Tonga')),
- ('TT', pgettext_lazy('Country', 'Trinidad And Tobago')),
- ('TN', pgettext_lazy('Country', 'Tunisia')),
- ('TR', pgettext_lazy('Country', 'Turkey')),
- ('TM', pgettext_lazy('Country', 'Turkmenistan')),
- ('TC', pgettext_lazy('Country', 'Turks And Caicos Islands')),
- ('TV', pgettext_lazy('Country', 'Tuvalu')),
- ('UG', pgettext_lazy('Country', 'Uganda')),
- ('UA', pgettext_lazy('Country', 'Ukraine')),
- ('AE', pgettext_lazy('Country', 'United Arab Emirates')),
- ('GB', pgettext_lazy('Country', 'United Kingdom')),
- ('US', pgettext_lazy('Country', 'United States')),
- ('UM', pgettext_lazy('Country', 'United States Minor Outlying Islands')),
- ('UY', pgettext_lazy('Country', 'Uruguay')),
- ('UZ', pgettext_lazy('Country', 'Uzbekistan')),
- ('VU', pgettext_lazy('Country', 'Vanuatu')),
- ('VE', pgettext_lazy('Country', 'Venezuela')),
- ('VN', pgettext_lazy('Country', 'Viet Nam')),
- ('VG', pgettext_lazy('Country', 'Virgin Islands, British')),
- ('VI', pgettext_lazy('Country', 'Virgin Islands, U.S.')),
- ('WF', pgettext_lazy('Country', 'Wallis And Futuna')),
- ('EH', pgettext_lazy('Country', 'Western Sahara')),
- ('YE', pgettext_lazy('Country', 'Yemen')),
- ('ZM', pgettext_lazy('Country', 'Zambia')),
- ('ZW', pgettext_lazy('Country', 'Zimbabwe'))]
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index ba73d6b794..78a4ca9253 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -1,9 +1,9 @@
from __future__ import unicode_literals
from django.contrib import messages
-from django.core.context_processors import csrf
from django.db import transaction
from django.shortcuts import get_object_or_404, redirect
+from django.template.context_processors import csrf
from django.template.response import TemplateResponse
from django.utils.translation import ugettext_lazy as _
from django.views.generic import ListView
diff --git a/saleor/userprofile/migrations/0004_auto_20160114_0419.py b/saleor/userprofile/migrations/0004_auto_20160114_0419.py
new file mode 100644
index 0000000000..f0f9c3cb93
--- /dev/null
+++ b/saleor/userprofile/migrations/0004_auto_20160114_0419.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.1 on 2016-01-14 10:19
+from __future__ import unicode_literals
+
+from django.db import migrations
+import django_countries.fields
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('userprofile', '0003_auto_20151104_1102'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='address',
+ name='country',
+ field=django_countries.fields.CountryField(max_length=2, verbose_name='country'),
+ ),
+ ]
diff --git a/saleor/userprofile/models.py b/saleor/userprofile/models.py
index e04a12a2ad..d6a01baa81 100644
--- a/saleor/userprofile/models.py
+++ b/saleor/userprofile/models.py
@@ -8,8 +8,7 @@ from django.forms.models import model_to_dict
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import pgettext_lazy
-
-from ..core.countries import COUNTRY_CHOICES
+from django_countries.fields import CountryField
class AddressManager(models.Manager):
@@ -54,9 +53,8 @@ class Address(models.Model):
postal_code = models.CharField(
pgettext_lazy('Address field', 'postal code'),
max_length=20, blank=True)
- country = models.CharField(
- pgettext_lazy('Address field', 'country'),
- choices=COUNTRY_CHOICES, max_length=2)
+ country = CountryField(
+ pgettext_lazy('Address field', 'country'))
country_area = models.CharField(
pgettext_lazy('Address field', 'state or province'),
max_length=128, blank=True)