1. Monwara LLC
  2. Untitled project
  3. django-international

Commits

Branko Vukelic  committed a2b4aff

Initial import of international app

  • Participants
  • Branches master

Comments (0)

Files changed (11)

File .gitignore

View file
+*.swp
+*.swo
+*.pyo
+*.pyc
+*.db
+lib
+share
+include
+bin

File international/__init__.py

View file
+"""Injection code originally taken from:
+
+http://passingcuriosity.com/2010/default-settings-for-django-applications/
+
+"""
+
+
+def inject_app_defaults(application):
+    """Inject an application's default settings"""
+    try:
+        __import__('%s.settings' % application)
+        import sys
+
+        # Import our defaults, project defaults, and project settings
+        _app_settings = sys.modules['%s.settings' % application]
+        _def_settings = sys.modules['django.conf.global_settings']
+        _settings = sys.modules['django.conf'].settings
+
+        # Add the values from the application.settings module
+        for _k in dir(_app_settings):
+            if _k.isupper():
+                # Add the value to the default settings module
+                setattr(_def_settings, _k, getattr(_app_settings, _k))
+
+                # Add the value to the settings, if not already present
+                if not hasattr(_settings, _k):
+                    setattr(_settings, _k, getattr(_app_settings, _k))
+    except ImportError:
+        # Silently skip failing settings modules
+        pass
+
+def _update_settings():
+    """Used during testing"""
+    inject_app_defaults(__name__)
+
+inject_app_defaults(__name__)
+
+

File international/fixtures/countries_fixture.json

View file
+[{"pk": 1, "model": "international.country", "fields": {"code": "AF", "continent": "AS"}}, {"pk": 2, "model": "international.country", "fields": {"code": "AL", "continent": "EU"}}, {"pk": 3, "model": "international.country", "fields": {"code": "AQ", "continent": "AN"}}, {"pk": 4, "model": "international.country", "fields": {"code": "DZ", "continent": "AF"}}, {"pk": 5, "model": "international.country", "fields": {"code": "AS", "continent": "OC"}}, {"pk": 6, "model": "international.country", "fields": {"code": "AD", "continent": "EU"}}, {"pk": 7, "model": "international.country", "fields": {"code": "AO", "continent": "AF"}}, {"pk": 8, "model": "international.country", "fields": {"code": "AG", "continent": "NA"}}, {"pk": 9, "model": "international.country", "fields": {"code": "AZ", "continent": "AS"}}, {"pk": 10, "model": "international.country", "fields": {"code": "AR", "continent": "SA"}}, {"pk": 11, "model": "international.country", "fields": {"code": "AU", "continent": "OC"}}, {"pk": 12, "model": "international.country", "fields": {"code": "AT", "continent": "EU"}}, {"pk": 13, "model": "international.country", "fields": {"code": "BS", "continent": "NA"}}, {"pk": 14, "model": "international.country", "fields": {"code": "BH", "continent": "AS"}}, {"pk": 15, "model": "international.country", "fields": {"code": "BD", "continent": "AS"}}, {"pk": 16, "model": "international.country", "fields": {"code": "AM", "continent": "AS"}}, {"pk": 17, "model": "international.country", "fields": {"code": "BB", "continent": "NA"}}, {"pk": 18, "model": "international.country", "fields": {"code": "BE", "continent": "EU"}}, {"pk": 19, "model": "international.country", "fields": {"code": "BM", "continent": "NA"}}, {"pk": 20, "model": "international.country", "fields": {"code": "BT", "continent": "AS"}}, {"pk": 21, "model": "international.country", "fields": {"code": "BO", "continent": "SA"}}, {"pk": 22, "model": "international.country", "fields": {"code": "BA", "continent": "EU"}}, {"pk": 23, "model": "international.country", "fields": {"code": "BW", "continent": "AF"}}, {"pk": 24, "model": "international.country", "fields": {"code": "BV", "continent": "AN"}}, {"pk": 25, "model": "international.country", "fields": {"code": "BR", "continent": "SA"}}, {"pk": 26, "model": "international.country", "fields": {"code": "BZ", "continent": "NA"}}, {"pk": 27, "model": "international.country", "fields": {"code": "IO", "continent": "AS"}}, {"pk": 28, "model": "international.country", "fields": {"code": "SB", "continent": "OC"}}, {"pk": 29, "model": "international.country", "fields": {"code": "VG", "continent": "NA"}}, {"pk": 30, "model": "international.country", "fields": {"code": "BN", "continent": "AS"}}, {"pk": 31, "model": "international.country", "fields": {"code": "BG", "continent": "EU"}}, {"pk": 32, "model": "international.country", "fields": {"code": "MM", "continent": "AS"}}, {"pk": 33, "model": "international.country", "fields": {"code": "BI", "continent": "AF"}}, {"pk": 34, "model": "international.country", "fields": {"code": "BY", "continent": "EU"}}, {"pk": 35, "model": "international.country", "fields": {"code": "KH", "continent": "AS"}}, {"pk": 36, "model": "international.country", "fields": {"code": "CM", "continent": "AF"}}, {"pk": 37, "model": "international.country", "fields": {"code": "CA", "continent": "NA"}}, {"pk": 38, "model": "international.country", "fields": {"code": "CV", "continent": "AF"}}, {"pk": 39, "model": "international.country", "fields": {"code": "KY", "continent": "NA"}}, {"pk": 40, "model": "international.country", "fields": {"code": "CF", "continent": "AF"}}, {"pk": 41, "model": "international.country", "fields": {"code": "LK", "continent": "AS"}}, {"pk": 42, "model": "international.country", "fields": {"code": "TD", "continent": "AF"}}, {"pk": 43, "model": "international.country", "fields": {"code": "CL", "continent": "SA"}}, {"pk": 44, "model": "international.country", "fields": {"code": "CN", "continent": "AS"}}, {"pk": 45, "model": "international.country", "fields": {"code": "TW", "continent": "AS"}}, {"pk": 46, "model": "international.country", "fields": {"code": "CX", "continent": "AS"}}, {"pk": 47, "model": "international.country", "fields": {"code": "CC", "continent": "AS"}}, {"pk": 48, "model": "international.country", "fields": {"code": "CO", "continent": "SA"}}, {"pk": 49, "model": "international.country", "fields": {"code": "KM", "continent": "AF"}}, {"pk": 50, "model": "international.country", "fields": {"code": "YT", "continent": "AF"}}, {"pk": 51, "model": "international.country", "fields": {"code": "CG", "continent": "AF"}}, {"pk": 52, "model": "international.country", "fields": {"code": "CD", "continent": "AF"}}, {"pk": 53, "model": "international.country", "fields": {"code": "CK", "continent": "OC"}}, {"pk": 54, "model": "international.country", "fields": {"code": "CR", "continent": "NA"}}, {"pk": 55, "model": "international.country", "fields": {"code": "HR", "continent": "EU"}}, {"pk": 56, "model": "international.country", "fields": {"code": "CU", "continent": "NA"}}, {"pk": 57, "model": "international.country", "fields": {"code": "CY", "continent": "EU"}}, {"pk": 58, "model": "international.country", "fields": {"code": "CZ", "continent": "EU"}}, {"pk": 59, "model": "international.country", "fields": {"code": "BJ", "continent": "AF"}}, {"pk": 60, "model": "international.country", "fields": {"code": "DK", "continent": "EU"}}, {"pk": 61, "model": "international.country", "fields": {"code": "DM", "continent": "NA"}}, {"pk": 62, "model": "international.country", "fields": {"code": "DO", "continent": "NA"}}, {"pk": 63, "model": "international.country", "fields": {"code": "EC", "continent": "SA"}}, {"pk": 64, "model": "international.country", "fields": {"code": "SV", "continent": "NA"}}, {"pk": 65, "model": "international.country", "fields": {"code": "GQ", "continent": "AF"}}, {"pk": 66, "model": "international.country", "fields": {"code": "ET", "continent": "AF"}}, {"pk": 67, "model": "international.country", "fields": {"code": "ER", "continent": "AF"}}, {"pk": 68, "model": "international.country", "fields": {"code": "EE", "continent": "EU"}}, {"pk": 69, "model": "international.country", "fields": {"code": "FO", "continent": "EU"}}, {"pk": 70, "model": "international.country", "fields": {"code": "FK", "continent": "SA"}}, {"pk": 71, "model": "international.country", "fields": {"code": "GS", "continent": "AN"}}, {"pk": 72, "model": "international.country", "fields": {"code": "FJ", "continent": "OC"}}, {"pk": 73, "model": "international.country", "fields": {"code": "FI", "continent": "EU"}}, {"pk": 74, "model": "international.country", "fields": {"code": "AX", "continent": "EU"}}, {"pk": 75, "model": "international.country", "fields": {"code": "FR", "continent": "EU"}}, {"pk": 76, "model": "international.country", "fields": {"code": "GF", "continent": "SA"}}, {"pk": 77, "model": "international.country", "fields": {"code": "PF", "continent": "OC"}}, {"pk": 78, "model": "international.country", "fields": {"code": "TF", "continent": "AN"}}, {"pk": 79, "model": "international.country", "fields": {"code": "DJ", "continent": "AF"}}, {"pk": 80, "model": "international.country", "fields": {"code": "GA", "continent": "AF"}}, {"pk": 81, "model": "international.country", "fields": {"code": "GE", "continent": "AS"}}, {"pk": 82, "model": "international.country", "fields": {"code": "GM", "continent": "AF"}}, {"pk": 83, "model": "international.country", "fields": {"code": "PS", "continent": "AS"}}, {"pk": 84, "model": "international.country", "fields": {"code": "DE", "continent": "EU"}}, {"pk": 85, "model": "international.country", "fields": {"code": "GH", "continent": "AF"}}, {"pk": 86, "model": "international.country", "fields": {"code": "GI", "continent": "EU"}}, {"pk": 87, "model": "international.country", "fields": {"code": "KI", "continent": "OC"}}, {"pk": 88, "model": "international.country", "fields": {"code": "GR", "continent": "EU"}}, {"pk": 89, "model": "international.country", "fields": {"code": "GL", "continent": "NA"}}, {"pk": 90, "model": "international.country", "fields": {"code": "GD", "continent": "NA"}}, {"pk": 91, "model": "international.country", "fields": {"code": "GP", "continent": "NA"}}, {"pk": 92, "model": "international.country", "fields": {"code": "GU", "continent": "OC"}}, {"pk": 93, "model": "international.country", "fields": {"code": "GT", "continent": "NA"}}, {"pk": 94, "model": "international.country", "fields": {"code": "GN", "continent": "AF"}}, {"pk": 95, "model": "international.country", "fields": {"code": "GY", "continent": "SA"}}, {"pk": 96, "model": "international.country", "fields": {"code": "HT", "continent": "NA"}}, {"pk": 97, "model": "international.country", "fields": {"code": "HM", "continent": "AN"}}, {"pk": 98, "model": "international.country", "fields": {"code": "VA", "continent": "EU"}}, {"pk": 99, "model": "international.country", "fields": {"code": "HN", "continent": "NA"}}, {"pk": 100, "model": "international.country", "fields": {"code": "HK", "continent": "AS"}}, {"pk": 101, "model": "international.country", "fields": {"code": "HU", "continent": "EU"}}, {"pk": 102, "model": "international.country", "fields": {"code": "IS", "continent": "EU"}}, {"pk": 103, "model": "international.country", "fields": {"code": "IN", "continent": "AS"}}, {"pk": 104, "model": "international.country", "fields": {"code": "ID", "continent": "AS"}}, {"pk": 105, "model": "international.country", "fields": {"code": "IR", "continent": "AS"}}, {"pk": 106, "model": "international.country", "fields": {"code": "IQ", "continent": "AS"}}, {"pk": 107, "model": "international.country", "fields": {"code": "IE", "continent": "EU"}}, {"pk": 108, "model": "international.country", "fields": {"code": "IL", "continent": "AS"}}, {"pk": 109, "model": "international.country", "fields": {"code": "IT", "continent": "EU"}}, {"pk": 110, "model": "international.country", "fields": {"code": "CI", "continent": "AF"}}, {"pk": 111, "model": "international.country", "fields": {"code": "JM", "continent": "NA"}}, {"pk": 112, "model": "international.country", "fields": {"code": "JP", "continent": "AS"}}, {"pk": 113, "model": "international.country", "fields": {"code": "KZ", "continent": "AS"}}, {"pk": 114, "model": "international.country", "fields": {"code": "JO", "continent": "AS"}}, {"pk": 115, "model": "international.country", "fields": {"code": "KE", "continent": "AF"}}, {"pk": 116, "model": "international.country", "fields": {"code": "KP", "continent": "AS"}}, {"pk": 117, "model": "international.country", "fields": {"code": "KR", "continent": "AS"}}, {"pk": 118, "model": "international.country", "fields": {"code": "KW", "continent": "AS"}}, {"pk": 119, "model": "international.country", "fields": {"code": "KG", "continent": "AS"}}, {"pk": 120, "model": "international.country", "fields": {"code": "LA", "continent": "AS"}}, {"pk": 121, "model": "international.country", "fields": {"code": "LB", "continent": "AS"}}, {"pk": 122, "model": "international.country", "fields": {"code": "LS", "continent": "AF"}}, {"pk": 123, "model": "international.country", "fields": {"code": "LV", "continent": "EU"}}, {"pk": 124, "model": "international.country", "fields": {"code": "LR", "continent": "AF"}}, {"pk": 125, "model": "international.country", "fields": {"code": "LY", "continent": "AF"}}, {"pk": 126, "model": "international.country", "fields": {"code": "LI", "continent": "EU"}}, {"pk": 127, "model": "international.country", "fields": {"code": "LT", "continent": "EU"}}, {"pk": 128, "model": "international.country", "fields": {"code": "LU", "continent": "EU"}}, {"pk": 129, "model": "international.country", "fields": {"code": "MO", "continent": "AS"}}, {"pk": 130, "model": "international.country", "fields": {"code": "MG", "continent": "AF"}}, {"pk": 131, "model": "international.country", "fields": {"code": "MW", "continent": "AF"}}, {"pk": 132, "model": "international.country", "fields": {"code": "MY", "continent": "AS"}}, {"pk": 133, "model": "international.country", "fields": {"code": "MV", "continent": "AS"}}, {"pk": 134, "model": "international.country", "fields": {"code": "ML", "continent": "AF"}}, {"pk": 135, "model": "international.country", "fields": {"code": "MT", "continent": "EU"}}, {"pk": 136, "model": "international.country", "fields": {"code": "MQ", "continent": "NA"}}, {"pk": 137, "model": "international.country", "fields": {"code": "MR", "continent": "AF"}}, {"pk": 138, "model": "international.country", "fields": {"code": "MU", "continent": "AF"}}, {"pk": 139, "model": "international.country", "fields": {"code": "MX", "continent": "NA"}}, {"pk": 140, "model": "international.country", "fields": {"code": "MC", "continent": "EU"}}, {"pk": 141, "model": "international.country", "fields": {"code": "MN", "continent": "AS"}}, {"pk": 142, "model": "international.country", "fields": {"code": "MD", "continent": "EU"}}, {"pk": 143, "model": "international.country", "fields": {"code": "ME", "continent": "EU"}}, {"pk": 144, "model": "international.country", "fields": {"code": "MS", "continent": "NA"}}, {"pk": 145, "model": "international.country", "fields": {"code": "MA", "continent": "AF"}}, {"pk": 146, "model": "international.country", "fields": {"code": "MZ", "continent": "AF"}}, {"pk": 147, "model": "international.country", "fields": {"code": "OM", "continent": "AS"}}, {"pk": 148, "model": "international.country", "fields": {"code": "NA", "continent": "AF"}}, {"pk": 149, "model": "international.country", "fields": {"code": "NR", "continent": "OC"}}, {"pk": 150, "model": "international.country", "fields": {"code": "NP", "continent": "AS"}}, {"pk": 151, "model": "international.country", "fields": {"code": "NL", "continent": "EU"}}, {"pk": 152, "model": "international.country", "fields": {"code": "AN", "continent": "NA"}}, {"pk": 153, "model": "international.country", "fields": {"code": "CW", "continent": "NA"}}, {"pk": 154, "model": "international.country", "fields": {"code": "AW", "continent": "NA"}}, {"pk": 155, "model": "international.country", "fields": {"code": "SX", "continent": "NA"}}, {"pk": 156, "model": "international.country", "fields": {"code": "BQ", "continent": "NA"}}, {"pk": 157, "model": "international.country", "fields": {"code": "NC", "continent": "OC"}}, {"pk": 158, "model": "international.country", "fields": {"code": "VU", "continent": "OC"}}, {"pk": 159, "model": "international.country", "fields": {"code": "NZ", "continent": "OC"}}, {"pk": 160, "model": "international.country", "fields": {"code": "NI", "continent": "NA"}}, {"pk": 161, "model": "international.country", "fields": {"code": "NE", "continent": "AF"}}, {"pk": 162, "model": "international.country", "fields": {"code": "NG", "continent": "AF"}}, {"pk": 163, "model": "international.country", "fields": {"code": "NU", "continent": "OC"}}, {"pk": 164, "model": "international.country", "fields": {"code": "NF", "continent": "OC"}}, {"pk": 165, "model": "international.country", "fields": {"code": "NO", "continent": "EU"}}, {"pk": 166, "model": "international.country", "fields": {"code": "MP", "continent": "OC"}}, {"pk": 167, "model": "international.country", "fields": {"code": "UM", "continent": "NA"}}, {"pk": 168, "model": "international.country", "fields": {"code": "FM", "continent": "OC"}}, {"pk": 169, "model": "international.country", "fields": {"code": "MH", "continent": "OC"}}, {"pk": 170, "model": "international.country", "fields": {"code": "PW", "continent": "OC"}}, {"pk": 171, "model": "international.country", "fields": {"code": "PK", "continent": "AS"}}, {"pk": 172, "model": "international.country", "fields": {"code": "PA", "continent": "NA"}}, {"pk": 173, "model": "international.country", "fields": {"code": "PG", "continent": "OC"}}, {"pk": 174, "model": "international.country", "fields": {"code": "PY", "continent": "SA"}}, {"pk": 175, "model": "international.country", "fields": {"code": "PE", "continent": "SA"}}, {"pk": 176, "model": "international.country", "fields": {"code": "PH", "continent": "AS"}}, {"pk": 177, "model": "international.country", "fields": {"code": "PN", "continent": "OC"}}, {"pk": 178, "model": "international.country", "fields": {"code": "PL", "continent": "EU"}}, {"pk": 179, "model": "international.country", "fields": {"code": "PT", "continent": "EU"}}, {"pk": 180, "model": "international.country", "fields": {"code": "GW", "continent": "AF"}}, {"pk": 181, "model": "international.country", "fields": {"code": "TL", "continent": "AS"}}, {"pk": 182, "model": "international.country", "fields": {"code": "PR", "continent": "NA"}}, {"pk": 183, "model": "international.country", "fields": {"code": "QA", "continent": "AS"}}, {"pk": 184, "model": "international.country", "fields": {"code": "RE", "continent": "AF"}}, {"pk": 185, "model": "international.country", "fields": {"code": "RO", "continent": "EU"}}, {"pk": 186, "model": "international.country", "fields": {"code": "RU", "continent": "EU"}}, {"pk": 187, "model": "international.country", "fields": {"code": "RW", "continent": "AF"}}, {"pk": 188, "model": "international.country", "fields": {"code": "BL", "continent": "NA"}}, {"pk": 189, "model": "international.country", "fields": {"code": "SH", "continent": "AF"}}, {"pk": 190, "model": "international.country", "fields": {"code": "KN", "continent": "NA"}}, {"pk": 191, "model": "international.country", "fields": {"code": "AI", "continent": "NA"}}, {"pk": 192, "model": "international.country", "fields": {"code": "LC", "continent": "NA"}}, {"pk": 193, "model": "international.country", "fields": {"code": "MF", "continent": "NA"}}, {"pk": 194, "model": "international.country", "fields": {"code": "PM", "continent": "NA"}}, {"pk": 195, "model": "international.country", "fields": {"code": "VC", "continent": "NA"}}, {"pk": 196, "model": "international.country", "fields": {"code": "SM", "continent": "EU"}}, {"pk": 197, "model": "international.country", "fields": {"code": "ST", "continent": "AF"}}, {"pk": 198, "model": "international.country", "fields": {"code": "SA", "continent": "AS"}}, {"pk": 199, "model": "international.country", "fields": {"code": "SN", "continent": "AF"}}, {"pk": 200, "model": "international.country", "fields": {"code": "RS", "continent": "EU"}}, {"pk": 201, "model": "international.country", "fields": {"code": "SC", "continent": "AF"}}, {"pk": 202, "model": "international.country", "fields": {"code": "SL", "continent": "AF"}}, {"pk": 203, "model": "international.country", "fields": {"code": "SG", "continent": "AS"}}, {"pk": 204, "model": "international.country", "fields": {"code": "SK", "continent": "EU"}}, {"pk": 205, "model": "international.country", "fields": {"code": "VN", "continent": "AS"}}, {"pk": 206, "model": "international.country", "fields": {"code": "SI", "continent": "EU"}}, {"pk": 207, "model": "international.country", "fields": {"code": "SO", "continent": "AF"}}, {"pk": 208, "model": "international.country", "fields": {"code": "ZA", "continent": "AF"}}, {"pk": 209, "model": "international.country", "fields": {"code": "ZW", "continent": "AF"}}, {"pk": 210, "model": "international.country", "fields": {"code": "ES", "continent": "EU"}}, {"pk": 211, "model": "international.country", "fields": {"code": "SS", "continent": "AF"}}, {"pk": 212, "model": "international.country", "fields": {"code": "EH", "continent": "AF"}}, {"pk": 213, "model": "international.country", "fields": {"code": "SD", "continent": "AF"}}, {"pk": 214, "model": "international.country", "fields": {"code": "SR", "continent": "SA"}}, {"pk": 215, "model": "international.country", "fields": {"code": "SJ", "continent": "EU"}}, {"pk": 216, "model": "international.country", "fields": {"code": "SZ", "continent": "AF"}}, {"pk": 217, "model": "international.country", "fields": {"code": "SE", "continent": "EU"}}, {"pk": 218, "model": "international.country", "fields": {"code": "CH", "continent": "EU"}}, {"pk": 219, "model": "international.country", "fields": {"code": "SY", "continent": "AS"}}, {"pk": 220, "model": "international.country", "fields": {"code": "TJ", "continent": "AS"}}, {"pk": 221, "model": "international.country", "fields": {"code": "TH", "continent": "AS"}}, {"pk": 222, "model": "international.country", "fields": {"code": "TG", "continent": "AF"}}, {"pk": 223, "model": "international.country", "fields": {"code": "TK", "continent": "OC"}}, {"pk": 224, "model": "international.country", "fields": {"code": "TO", "continent": "OC"}}, {"pk": 225, "model": "international.country", "fields": {"code": "TT", "continent": "NA"}}, {"pk": 226, "model": "international.country", "fields": {"code": "AE", "continent": "AS"}}, {"pk": 227, "model": "international.country", "fields": {"code": "TN", "continent": "AF"}}, {"pk": 228, "model": "international.country", "fields": {"code": "TR", "continent": "EU"}}, {"pk": 229, "model": "international.country", "fields": {"code": "TM", "continent": "AS"}}, {"pk": 230, "model": "international.country", "fields": {"code": "TC", "continent": "NA"}}, {"pk": 231, "model": "international.country", "fields": {"code": "TV", "continent": "OC"}}, {"pk": 232, "model": "international.country", "fields": {"code": "UG", "continent": "AF"}}, {"pk": 233, "model": "international.country", "fields": {"code": "UA", "continent": "EU"}}, {"pk": 234, "model": "international.country", "fields": {"code": "MK", "continent": "EU"}}, {"pk": 235, "model": "international.country", "fields": {"code": "EG", "continent": "AF"}}, {"pk": 236, "model": "international.country", "fields": {"code": "GB", "continent": "EU"}}, {"pk": 237, "model": "international.country", "fields": {"code": "GG", "continent": "EU"}}, {"pk": 238, "model": "international.country", "fields": {"code": "JE", "continent": "EU"}}, {"pk": 239, "model": "international.country", "fields": {"code": "IM", "continent": "EU"}}, {"pk": 240, "model": "international.country", "fields": {"code": "TZ", "continent": "AF"}}, {"pk": 241, "model": "international.country", "fields": {"code": "US", "continent": "NA"}}, {"pk": 242, "model": "international.country", "fields": {"code": "VI", "continent": "NA"}}, {"pk": 243, "model": "international.country", "fields": {"code": "BF", "continent": "AF"}}, {"pk": 244, "model": "international.country", "fields": {"code": "UY", "continent": "SA"}}, {"pk": 245, "model": "international.country", "fields": {"code": "UZ", "continent": "AS"}}, {"pk": 246, "model": "international.country", "fields": {"code": "VE", "continent": "SA"}}, {"pk": 247, "model": "international.country", "fields": {"code": "WF", "continent": "OC"}}, {"pk": 248, "model": "international.country", "fields": {"code": "WS", "continent": "OC"}}, {"pk": 249, "model": "international.country", "fields": {"code": "YE", "continent": "AS"}}, {"pk": 250, "model": "international.country", "fields": {"code": "ZM", "continent": "AF"}}, {"pk": 251, "model": "international.country", "fields": {"code": "XX", "continent": "OC"}}, {"pk": 252, "model": "international.country", "fields": {"code": "XE", "continent": "AS"}}, {"pk": 253, "model": "international.country", "fields": {"code": "XD", "continent": "AS"}}, {"pk": 254, "model": "international.country", "fields": {"code": "XS", "continent": "AS"}}]

File international/forms.py

View file
+"""Country and currency forms
+
+Settings
+========
+
+There are a few settings you can use to configure the behavior of the forms.
+Note that these settings are for the form mixins, and not the form classes. So
+forms that contain both country and currency form mixins will be affected by
+both sets of
+
+COUNTRY_FORM_LABEL
+------------------
+
+Label for the 'country' field. Defaults to 'country'.
+
+COUNTRY_FORM_INCLUDE_EMPTY
+--------------------------
+
+This settings controls whether country form will include empty value when
+instantiated. You can also use the ``COUNTRY_FORM_EMPTY_VALUE`` to control the
+value of the item that will be treted as empty (no country). Default is
+``False``.
+
+COUNTRY_FORM_EMPTY_VALUE
+------------------------
+
+This setting controls the value that is assigned to empty value (no country) if
+``COUNTRY_FORM_INCLUDE_EMPTY`` is set to ``True``.
+
+COUNTRY_FORM_EMPTY_LABEL
+------------------------
+
+Customizes the label for the empty value (no country). Default is 'All
+countries'.
+
+COUNTRY_FORM_USE_STATIC
+-----------------------
+
+Use hard-coded values instead of reading the database.
+
+CURRENCY_FORM_LABEL
+-------------------
+
+Label for the 'currency' field. Defaults to 'currency'.
+
+CURRENCY_FORM_INCLUDE_EMPTY
+---------------------------
+
+Same as ``COUNTRY_FORM_INCLUDE_EMPTY`` but for currency form.
+
+CURRENCY_FORM_EMPTY_VALUE
+-------------------------
+
+Same as ``COUNTRY_FORM_EMPTY_VALUE`` but for currency form.
+
+CURRENCY_FORM_EMPTY_LABEL
+-------------------------
+
+Same as ``COUNTRY_FORM_EMPTY_LABEL`` but for currency form. Defaults to 'All
+currencies'.
+
+"""
+
+from __future__ import unicode_literals
+
+from django import forms
+from django.conf import settings
+from django.utils.translation import ugettext as _
+
+from models import currencies, countries, Country
+
+
+class CountryForm(forms.Form):
+    def __init__(self, *args, **kwargs):
+        super(CountryForm, self).__init__(*args, **kwargs)
+
+        choices = []
+
+        # Use static data or not
+        if settings.COUNTRY_FORM_USE_STATIC:
+            choices = list(countries)
+        else:
+            # Create choices for country field
+            for country in Country.objects.all():
+                choices.append((country.code, country.get_code_display()))
+
+        # Include empty or not
+        if settings.COUNTRY_FORM_INCLUDE_EMPTY:
+            choices.insert(0, (settings.COUNTRY_FORM_EMPTY_VALUE,
+                               settings.COUNTRY_FORM_EMPTY_LABEL))
+
+        # Assign values
+        self.fields['country'].choices = choices
+        self.fields['country'].label = settings.COUNTRY_FORM_LABEL
+        self.fields['country'].initial = kwargs.get('initial', {}).get(
+            'country', settings.COUNTRY_FORM_INITIAL_VALUE)
+
+    country = forms.ChoiceField(required=False,
+                                choices=())
+
+
+class CurrencyForm(forms.Form):
+    def __init__(self, *args, **kwargs):
+        super(CurrencyForm, self).__init__(*args, **kwargs)
+
+        choices = list(currencies)
+
+        if settings.CURRENCY_FORM_INCLUDE_EMPTY:
+            choices.insert(0, (settings.CURRENCY_FORM_EMPTY_VALUE,
+                               settings.CURRENCY_FORM_EMPTY_LABEL))
+
+        self.fields['currency'].label = settings.CURRENCY_FORM_LABEL
+        self.fields['currency'].choices = choices
+        self.fields['currency'].initial = kwargs.get(
+            'initial', {}
+        ).get('currency', settings.CURRENCY_FORM_INITIAL_VALUE)
+
+    currency = forms.ChoiceField(required=False,
+                                 choices=())
+
+
+class CountryCurrencyForm(CountryForm, CurrencyForm, forms.Form):
+    pass

File international/migrations/0001_initial.py

View file
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding model 'Country'
+        db.create_table(u'international_country', (
+            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('code', self.gf('django.db.models.fields.CharField')(unique=True, max_length=2)),
+            ('continent', self.gf('django.db.models.fields.CharField')(max_length=2)),
+        ))
+        db.send_create_signal(u'international', ['Country'])
+
+
+    def backwards(self, orm):
+        # Deleting model 'Country'
+        db.delete_table(u'international_country')
+
+
+    models = {
+        u'international.country': {
+            'Meta': {'object_name': 'Country'},
+            'code': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '2'}),
+            'continent': ('django.db.models.fields.CharField', [], {'max_length': '2'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+        }
+    }
+
+    complete_apps = ['international']

File international/migrations/__init__.py

Empty file added.

File international/models.py

View file
+# -*- coding: utf-8 -*-
+
+"""Countries and currencies
+
+Country data includes 2- and 3-letter ISO codes, continents, and full country
+names. Currency data includes 3-letter ISO code and full currency name.
+
+Country fixtures are provided but they are not in the form of initial data,
+since we might want to edit the country list at some point, depending on our
+needs.
+
+"""
+
+
+from __future__ import unicode_literals
+
+from django.db import models
+from django.utils.translation import ugettext as _
+
+countries_raw = (
+    ("AS", "AF", "AFG", 4, _("Afghanistan, Islamic Republic of")),
+    ("EU", "AL", "ALB", 8, _("Albania, Republic of")),
+    ("AN", "AQ", "ATA", 10, _("Antarctica (the territory South of 60 deg S)")),
+    ("AF", "DZ", "DZA", 12, _("Algeria, People's Democratic Republic of")),
+    ("OC", "AS", "ASM", 16, _("American Samoa")),
+    ("EU", "AD", "AND", 20, _("Andorra, Principality of")),
+    ("AF", "AO", "AGO", 24, _("Angola, Republic of")),
+    ("NA", "AG", "ATG", 28, _("Antigua and Barbuda")),
+    ("AS", "AZ", "AZE", 31, _("Azerbaijan, Republic of")),
+    ("SA", "AR", "ARG", 32, _("Argentina, Argentine Republic")),
+    ("OC", "AU", "AUS", 36, _("Australia, Commonwealth of")),
+    ("EU", "AT", "AUT", 40, _("Austria, Republic of")),
+    ("NA", "BS", "BHS", 44, _("Bahamas, Commonwealth of the")),
+    ("AS", "BH", "BHR", 48, _("Bahrain, Kingdom of")),
+    ("AS", "BD", "BGD", 50, _("Bangladesh, People's Republic of")),
+    ("AS", "AM", "ARM", 51, _("Armenia, Republic of")),
+    ("NA", "BB", "BRB", 52, _("Barbados")),
+    ("EU", "BE", "BEL", 56, _("Belgium, Kingdom of")),
+    ("NA", "BM", "BMU", 60, _("Bermuda")),
+    ("AS", "BT", "BTN", 64, _("Bhutan, Kingdom of")),
+    ("SA", "BO", "BOL", 68, _("Bolivia, Republic of")),
+    ("EU", "BA", "BIH", 70, _("Bosnia and Herzegovina")),
+    ("AF", "BW", "BWA", 72, _("Botswana, Republic of")),
+    ("AN", "BV", "BVT", 74, _("Bouvet Island (Bouvetoya)")),
+    ("SA", "BR", "BRA", 76, _("Brazil, Federative Republic of")),
+    ("NA", "BZ", "BLZ", 84, _("Belize")),
+    ("AS", "IO", "IOT", 86, _("British Indian Ocean Territory (Chagos Archipelago)")),
+    ("OC", "SB", "SLB", 90, _("Solomon Islands")),
+    ("NA", "VG", "VGB", 92, _("British Virgin Islands")),
+    ("AS", "BN", "BRN", 96, _("Brunei Darussalam")),
+    ("EU", "BG", "BGR", 100, _("Bulgaria, Republic of")),
+    ("AS", "MM", "MMR", 104, _("Myanmar, Union of")),
+    ("AF", "BI", "BDI", 108, _("Burundi, Republic of")),
+    ("EU", "BY", "BLR", 112, _("Belarus, Republic of")),
+    ("AS", "KH", "KHM", 116, _("Cambodia, Kingdom of")),
+    ("AF", "CM", "CMR", 120, _("Cameroon, Republic of")),
+    ("NA", "CA", "CAN", 124, _("Canada")),
+    ("AF", "CV", "CPV", 132, _("Cape Verde, Republic of")),
+    ("NA", "KY", "CYM", 136, _("Cayman Islands")),
+    ("AF", "CF", "CAF", 140, _("Central African Republic")),
+    ("AS", "LK", "LKA", 144, _("Sri Lanka, Democratic Socialist Republic of")),
+    ("AF", "TD", "TCD", 148, _("Chad, Republic of")),
+    ("SA", "CL", "CHL", 152, _("Chile, Republic of")),
+    ("AS", "CN", "CHN", 156, _("China, People's Republic of")),
+    ("AS", "TW", "TWN", 158, _("Taiwan")),
+    ("AS", "CX", "CXR", 162, _("Christmas Island")),
+    ("AS", "CC", "CCK", 166, _("Cocos (Keeling) Islands")),
+    ("SA", "CO", "COL", 170, _("Colombia, Republic of")),
+    ("AF", "KM", "COM", 174, _("Comoros, Union of the")),
+    ("AF", "YT", "MYT", 175, _("Mayotte")),
+    ("AF", "CG", "COG", 178, _("Congo, Republic of the")),
+    ("AF", "CD", "COD", 180, _("Congo, Democratic Republic of the")),
+    ("OC", "CK", "COK", 184, _("Cook Islands")),
+    ("NA", "CR", "CRI", 188, _("Costa Rica, Republic of")),
+    ("EU", "HR", "HRV", 191, _("Croatia, Republic of")),
+    ("NA", "CU", "CUB", 192, _("Cuba, Republic of")),
+    ("EU", "CY", "CYP", 196, _("Cyprus, Republic of")),
+    ("EU", "CZ", "CZE", 203, _("Czech Republic")),
+    ("AF", "BJ", "BEN", 204, _("Benin, Republic of")),
+    ("EU", "DK", "DNK", 208, _("Denmark, Kingdom of")),
+    ("NA", "DM", "DMA", 212, _("Dominica, Commonwealth of")),
+    ("NA", "DO", "DOM", 214, _("Dominican Republic")),
+    ("SA", "EC", "ECU", 218, _("Ecuador, Republic of")),
+    ("NA", "SV", "SLV", 222, _("El Salvador, Republic of")),
+    ("AF", "GQ", "GNQ", 226, _("Equatorial Guinea, Republic of")),
+    ("AF", "ET", "ETH", 231, _("Ethiopia, Federal Democratic Republic of")),
+    ("AF", "ER", "ERI", 232, _("Eritrea, State of")),
+    ("EU", "EE", "EST", 233, _("Estonia, Republic of")),
+    ("EU", "FO", "FRO", 234, _("Faroe Islands")),
+    ("SA", "FK", "FLK", 238, _("Falkland Islands (Malvinas)")),
+    ("AN", "GS", "SGS", 239, _("South Georgia and the South Sandwich Islands")),
+    ("OC", "FJ", "FJI", 242, _("Fiji, Republic of the Fiji Islands")),
+    ("EU", "FI", "FIN", 246, _("Finland, Republic of")),
+    ("EU", "AX", "ALA", 248, _("Åland Islands")),
+    ("EU", "FR", "FRA", 250, _("France, French Republic")),
+    ("SA", "GF", "GUF", 254, _("French Guiana")),
+    ("OC", "PF", "PYF", 258, _("French Polynesia")),
+    ("AN", "TF", "ATF", 260, _("French Southern Territories")),
+    ("AF", "DJ", "DJI", 262, _("Djibouti, Republic of")),
+    ("AF", "GA", "GAB", 266, _("Gabon, Gabonese Republic")),
+    ("AS", "GE", "GEO", 268, _("Georgia")),
+    ("AF", "GM", "GMB", 270, _("Gambia, Republic of the")),
+    ("AS", "PS", "PSE", 275, _("Palestinian Territory, Occupied")),
+    ("EU", "DE", "DEU", 276, _("Germany, Federal Republic of")),
+    ("AF", "GH", "GHA", 288, _("Ghana, Republic of")),
+    ("EU", "GI", "GIB", 292, _("Gibraltar")),
+    ("OC", "KI", "KIR", 296, _("Kiribati, Republic of")),
+    ("EU", "GR", "GRC", 300, _("Greece, Hellenic Republic")),
+    ("NA", "GL", "GRL", 304, _("Greenland")),
+    ("NA", "GD", "GRD", 308, _("Grenada")),
+    ("NA", "GP", "GLP", 312, _("Guadeloupe")),
+    ("OC", "GU", "GUM", 316, _("Guam")),
+    ("NA", "GT", "GTM", 320, _("Guatemala, Republic of")),
+    ("AF", "GN", "GIN", 324, _("Guinea, Republic of")),
+    ("SA", "GY", "GUY", 328, _("Guyana, Co-operative Republic of")),
+    ("NA", "HT", "HTI", 332, _("Haiti, Republic of")),
+    ("AN", "HM", "HMD", 334, _("Heard Island and McDonald Islands")),
+    ("EU", "VA", "VAT", 336, _("Holy See (Vatican City State)")),
+    ("NA", "HN", "HND", 340, _("Honduras, Republic of")),
+    ("AS", "HK", "HKG", 344, _("Hong Kong, Special Administrative Region of China")),
+    ("EU", "HU", "HUN", 348, _("Hungary, Republic of")),
+    ("EU", "IS", "ISL", 352, _("Iceland, Republic of")),
+    ("AS", "IN", "IND", 356, _("India, Republic of")),
+    ("AS", "ID", "IDN", 360, _("Indonesia, Republic of")),
+    ("AS", "IR", "IRN", 364, _("Iran, Islamic Republic of")),
+    ("AS", "IQ", "IRQ", 368, _("Iraq, Republic of")),
+    ("EU", "IE", "IRL", 372, _("Ireland")),
+    ("AS", "IL", "ISR", 376, _("Israel, State of")),
+    ("EU", "IT", "ITA", 380, _("Italy, Italian Republic")),
+    ("AF", "CI", "CIV", 384, _("Cote d'Ivoire, Republic of")),
+    ("NA", "JM", "JAM", 388, _("Jamaica")),
+    ("AS", "JP", "JPN", 392, _("Japan")),
+    ("AS", "KZ", "KAZ", 398, _("Kazakhstan, Republic of")),
+    ("AS", "JO", "JOR", 400, _("Jordan, Hashemite Kingdom of")),
+    ("AF", "KE", "KEN", 404, _("Kenya, Republic of")),
+    ("AS", "KP", "PRK", 408, _("Korea, Democratic People's Republic of")),
+    ("AS", "KR", "KOR", 410, _("Korea, Republic of")),
+    ("AS", "KW", "KWT", 414, _("Kuwait, State of")),
+    ("AS", "KG", "KGZ", 417, _("Kyrgyz Republic")),
+    ("AS", "LA", "LAO", 418, _("Lao People's Democratic Republic")),
+    ("AS", "LB", "LBN", 422, _("Lebanon, Lebanese Republic")),
+    ("AF", "LS", "LSO", 426, _("Lesotho, Kingdom of")),
+    ("EU", "LV", "LVA", 428, _("Latvia, Republic of")),
+    ("AF", "LR", "LBR", 430, _("Liberia, Republic of")),
+    ("AF", "LY", "LBY", 434, _("Libyan Arab Jamahiriya")),
+    ("EU", "LI", "LIE", 438, _("Liechtenstein, Principality of")),
+    ("EU", "LT", "LTU", 440, _("Lithuania, Republic of")),
+    ("EU", "LU", "LUX", 442, _("Luxembourg, Grand Duchy of")),
+    ("AS", "MO", "MAC", 446, _("Macao, Special Administrative Region of China")),
+    ("AF", "MG", "MDG", 450, _("Madagascar, Republic of")),
+    ("AF", "MW", "MWI", 454, _("Malawi, Republic of")),
+    ("AS", "MY", "MYS", 458, _("Malaysia")),
+    ("AS", "MV", "MDV", 462, _("Maldives, Republic of")),
+    ("AF", "ML", "MLI", 466, _("Mali, Republic of")),
+    ("EU", "MT", "MLT", 470, _("Malta, Republic of")),
+    ("NA", "MQ", "MTQ", 474, _("Martinique")),
+    ("AF", "MR", "MRT", 478, _("Mauritania, Islamic Republic of")),
+    ("AF", "MU", "MUS", 480, _("Mauritius, Republic of")),
+    ("NA", "MX", "MEX", 484, _("Mexico, United Mexican States")),
+    ("EU", "MC", "MCO", 492, _("Monaco, Principality of")),
+    ("AS", "MN", "MNG", 496, _("Mongolia")),
+    ("EU", "MD", "MDA", 498, _("Moldova, Republic of")),
+    ("EU", "ME", "MNE", 499, _("Montenegro, Republic of")),
+    ("NA", "MS", "MSR", 500, _("Montserrat")),
+    ("AF", "MA", "MAR", 504, _("Morocco, Kingdom of")),
+    ("AF", "MZ", "MOZ", 508, _("Mozambique, Republic of")),
+    ("AS", "OM", "OMN", 512, _("Oman, Sultanate of")),
+    ("AF", "NA", "NAM", 516, _("Namibia, Republic of")),
+    ("OC", "NR", "NRU", 520, _("Nauru, Republic of")),
+    ("AS", "NP", "NPL", 524, _("Nepal, State of")),
+    ("EU", "NL", "NLD", 528, _("Netherlands, Kingdom of the")),
+    ("NA", "AN", "ANT", 530, _("Netherlands Antilles")),
+    ("NA", "CW", "CUW", 531, _("Curaçao")),
+    ("NA", "AW", "ABW", 533, _("Aruba")),
+    ("NA", "SX", "SXM", 534, _("Sint Maarten (Netherlands)")),
+    ("NA", "BQ", "BES", 535, _("Bonaire, Sint Eustatius and Saba")),
+    ("OC", "NC", "NCL", 540, _("New Caledonia")),
+    ("OC", "VU", "VUT", 548, _("Vanuatu, Republic of")),
+    ("OC", "NZ", "NZL", 554, _("New Zealand")),
+    ("NA", "NI", "NIC", 558, _("Nicaragua, Republic of")),
+    ("AF", "NE", "NER", 562, _("Niger, Republic of")),
+    ("AF", "NG", "NGA", 566, _("Nigeria, Federal Republic of")),
+    ("OC", "NU", "NIU", 570, _("Niue")),
+    ("OC", "NF", "NFK", 574, _("Norfolk Island")),
+    ("EU", "NO", "NOR", 578, _("Norway, Kingdom of")),
+    ("OC", "MP", "MNP", 580, _("Northern Mariana Islands, Commonwealth of the")),
+    ("NA", "UM", "UMI", 581, _("United States Minor Outlying Islands")),
+    ("OC", "FM", "FSM", 583, _("Micronesia, Federated States of")),
+    ("OC", "MH", "MHL", 584, _("Marshall Islands, Republic of the")),
+    ("OC", "PW", "PLW", 585, _("Palau, Republic of")),
+    ("AS", "PK", "PAK", 586, _("Pakistan, Islamic Republic of")),
+    ("NA", "PA", "PAN", 591, _("Panama, Republic of")),
+    ("OC", "PG", "PNG", 598, _("Papua New Guinea, Independent State of")),
+    ("SA", "PY", "PRY", 600, _("Paraguay, Republic of")),
+    ("SA", "PE", "PER", 604, _("Peru, Republic of")),
+    ("AS", "PH", "PHL", 608, _("Philippines, Republic of the")),
+    ("OC", "PN", "PCN", 612, _("Pitcairn Islands")),
+    ("EU", "PL", "POL", 616, _("Poland, Republic of")),
+    ("EU", "PT", "PRT", 620, _("Portugal, Portuguese Republic")),
+    ("AF", "GW", "GNB", 624, _("Guinea-Bissau, Republic of")),
+    ("AS", "TL", "TLS", 626, _("Timor-Leste, Democratic Republic of")),
+    ("NA", "PR", "PRI", 630, _("Puerto Rico, Commonwealth of")),
+    ("AS", "QA", "QAT", 634, _("Qatar, State of")),
+    ("AF", "RE", "REU", 638, _("Reunion")),
+    ("EU", "RO", "ROU", 642, _("Romania")),
+    ("EU", "RU", "RUS", 643, _("Russian Federation")),
+    ("AF", "RW", "RWA", 646, _("Rwanda, Republic of")),
+    ("NA", "BL", "BLM", 652, _("Saint Barthelemy")),
+    ("AF", "SH", "SHN", 654, _("Saint Helena")),
+    ("NA", "KN", "KNA", 659, _("Saint Kitts and Nevis, Federation of")),
+    ("NA", "AI", "AIA", 660, _("Anguilla")),
+    ("NA", "LC", "LCA", 662, _("Saint Lucia")),
+    ("NA", "MF", "MAF", 663, _("Saint Martin")),
+    ("NA", "PM", "SPM", 666, _("Saint Pierre and Miquelon")),
+    ("NA", "VC", "VCT", 670, _("Saint Vincent and the Grenadines")),
+    ("EU", "SM", "SMR", 674, _("San Marino, Republic of")),
+    ("AF", "ST", "STP", 678, _("Sao Tome and Principe, Democratic Republic of")),
+    ("AS", "SA", "SAU", 682, _("Saudi Arabia, Kingdom of")),
+    ("AF", "SN", "SEN", 686, _("Senegal, Republic of")),
+    ("EU", "RS", "SRB", 688, _("Serbia, Republic of")),
+    ("AF", "SC", "SYC", 690, _("Seychelles, Republic of")),
+    ("AF", "SL", "SLE", 694, _("Sierra Leone, Republic of")),
+    ("AS", "SG", "SGP", 702, _("Singapore, Republic of")),
+    ("EU", "SK", "SVK", 703, _("Slovakia (Slovak Republic)")),
+    ("AS", "VN", "VNM", 704, _("Vietnam, Socialist Republic of")),
+    ("EU", "SI", "SVN", 705, _("Slovenia, Republic of")),
+    ("AF", "SO", "SOM", 706, _("Somalia, Somali Republic")),
+    ("AF", "ZA", "ZAF", 710, _("South Africa, Republic of")),
+    ("AF", "ZW", "ZWE", 716, _("Zimbabwe, Republic of")),
+    ("EU", "ES", "ESP", 724, _("Spain, Kingdom of")),
+    ("AF", "SS", "SSD", 728, _("South Sudan")),
+    ("AF", "EH", "ESH", 732, _("Western Sahara")),
+    ("AF", "SD", "SDN", 736, _("Sudan, Republic of")),
+    ("SA", "SR", "SUR", 740, _("Suriname, Republic of")),
+    ("EU", "SJ", "SJM", 744, _("Svalbard & Jan Mayen Islands")),
+    ("AF", "SZ", "SWZ", 748, _("Swaziland, Kingdom of")),
+    ("EU", "SE", "SWE", 752, _("Sweden, Kingdom of")),
+    ("EU", "CH", "CHE", 756, _("Switzerland, Swiss Confederation")),
+    ("AS", "SY", "SYR", 760, _("Syrian Arab Republic")),
+    ("AS", "TJ", "TJK", 762, _("Tajikistan, Republic of")),
+    ("AS", "TH", "THA", 764, _("Thailand, Kingdom of")),
+    ("AF", "TG", "TGO", 768, _("Togo, Togolese Republic")),
+    ("OC", "TK", "TKL", 772, _("Tokelau")),
+    ("OC", "TO", "TON", 776, _("Tonga, Kingdom of")),
+    ("NA", "TT", "TTO", 780, _("Trinidad and Tobago, Republic of")),
+    ("AS", "AE", "ARE", 784, _("United Arab Emirates")),
+    ("AF", "TN", "TUN", 788, _("Tunisia, Tunisian Republic")),
+    ("EU", "TR", "TUR", 792, _("Turkey, Republic of")),
+    ("AS", "TM", "TKM", 795, _("Turkmenistan")),
+    ("NA", "TC", "TCA", 796, _("Turks and Caicos Islands")),
+    ("OC", "TV", "TUV", 798, _("Tuvalu")),
+    ("AF", "UG", "UGA", 800, _("Uganda, Republic of")),
+    ("EU", "UA", "UKR", 804, _("Ukraine")),
+    ("EU", "MK", "MKD", 807, _("Macedonia, The Former Yugoslav Republic of")),
+    ("AF", "EG", "EGY", 818, _("Egypt, Arab Republic of")),
+    ("EU", "GB", "GBR", 826, _("United Kingdom")),
+    ("EU", "GG", "GGY", 831, _("Guernsey, Bailiwick of")),
+    ("EU", "JE", "JEY", 832, _("Jersey, Bailiwick of")),
+    ("EU", "IM", "IMN", 833, _("Isle of Man")),
+    ("AF", "TZ", "TZA", 834, _("Tanzania, United Republic of")),
+    ("NA", "US", "USA", 840, _("United States")),
+    ("NA", "VI", "VIR", 850, _("United States Virgin Islands")),
+    ("AF", "BF", "BFA", 854, _("Burkina Faso")),
+    ("SA", "UY", "URY", 858, _("Uruguay, Eastern Republic of")),
+    ("AS", "UZ", "UZB", 860, _("Uzbekistan, Republic of")),
+    ("SA", "VE", "VEN", 862, _("Venezuela, Bolivarian Republic of")),
+    ("OC", "WF", "WLF", 876, _("Wallis and Futuna")),
+    ("OC", "WS", "WSM", 882, _("Samoa, Independent State of")),
+    ("AS", "YE", "YEM", 887, _("Yemen")),
+    ("AF", "ZM", "ZMB", 894, _("Zambia, Republic of")),
+    ("OC", "XX", None, None, _("Disputed Territory")),
+    ("AS", "XE", None, None, _("Iraq-Saudi Arabia Neutral Zone")),
+    ("AS", "XD", None, None, _("United Nations Neutral Zone")),
+    ("AS", "XS", None, None, _("Spratly Islands")),
+    ("AS", "XS", None, None, _("Spratly Islands")),
+)
+
+countries = [
+    (c[1], c[4].partition(',')[0].partition('(')[0].strip())
+    for c in countries_raw
+]
+
+continents = (
+    ('AF', _('Africa')),
+    ('AN', _('Antarctica')),
+    ('AS', _('Asia')),
+    ('EU', _('Europe')),
+    ('NA', _('North America')),
+    ('OC', _('Oceania')),
+    ('SA', _('South America')),
+)
+
+currencies = (
+    ('USD', _('USD - United States Dollar')),
+    ('EUR', _('EUR - Euro Members')),
+    ('JPY', _('JPY - Japan Yen')),
+    ('GBP', _('GBP - United Kingdom Pound')),
+    ('CHF', _('CHF - Switzerland Franc')),
+    ('AED', _('AED - United Arab Emirates Dirham')),
+    ('AFN', _('AFN - Afghanistan Afghani')),
+    ('ALL', _('ALL - Albania Lek')),
+    ('AMD', _('AMD - Armenia Dram')),
+    ('ANG', _('ANG - Netherlands Antilles Guilder')),
+    ('AOA', _('AOA - Angola Kwanza')),
+    ('ARS', _('ARS - Argentina Peso')),
+    ('AUD', _('AUD - Australia Dollar')),
+    ('AWG', _('AWG - Aruba Guilder')),
+    ('AZN', _('AZN - Azerbaijan New Manat')),
+    ('BAM', _('BAM - Bosnia and Herzegovina Convertible Marka')),
+    ('BBD', _('BBD - Barbados Dollar')),
+    ('BDT', _('BDT - Bangladesh Taka')),
+    ('BGN', _('BGN - Bulgaria Lev')),
+    ('BHD', _('BHD - Bahrain Dinar')),
+    ('BIF', _('BIF - Burundi Franc')),
+    ('BMD', _('BMD - Bermuda Dollar')),
+    ('BND', _('BND - Brunei Darussalam Dollar')),
+    ('BOB', _('BOB - Bolivia Boliviano')),
+    ('BRL', _('BRL - Brazil Real')),
+    ('BSD', _('BSD - Bahamas Dollar')),
+    ('BTN', _('BTN - Bhutan Ngultrum')),
+    ('BWP', _('BWP - Botswana Pula')),
+    ('BYR', _('BYR - Belarus Ruble')),
+    ('BZD', _('BZD - Belize Dollar')),
+    ('CAD', _('CAD - Canada Dollar')),
+    ('CDF', _('CDF - Congo/Kinshasa Franc')),
+    ('CLP', _('CLP - Chile Peso')),
+    ('CNY', _('CNY - China Yuan Renminbi')),
+    ('COP', _('COP - Colombia Peso')),
+    ('CRC', _('CRC - Costa Rica Colon')),
+    ('CUC', _('CUC - Cuba Convertible Peso')),
+    ('CUP', _('CUP - Cuba Peso')),
+    ('CVE', _('CVE - Cape Verde Escudo')),
+    ('CZK', _('CZK - Czech Republic Koruna')),
+    ('DJF', _('DJF - Djibouti Franc')),
+    ('DKK', _('DKK - Denmark Krone')),
+    ('DOP', _('DOP - Dominican Republic Peso')),
+    ('DZD', _('DZD - Algeria Dinar')),
+    ('EGP', _('EGP - Egypt Pound')),
+    ('ERN', _('ERN - Eritrea Nakfa')),
+    ('ETB', _('ETB - Ethiopia Birr')),
+    ('FJD', _('FJD - Fiji Dollar')),
+    ('FKP', _('FKP - Falkland Islands (Malvinas) Pound')),
+    ('GEL', _('GEL - Georgia Lari')),
+    ('GGP', _('GGP - Guernsey Pound')),
+    ('GHS', _('GHS - Ghana Cedi')),
+    ('GIP', _('GIP - Gibraltar Pound')),
+    ('GMD', _('GMD - Gambia Dalasi')),
+    ('GNF', _('GNF - Guinea Franc')),
+    ('GTQ', _('GTQ - Guatemala Quetzal')),
+    ('GYD', _('GYD - Guyana Dollar')),
+    ('HKD', _('HKD - Hong Kong Dollar')),
+    ('HNL', _('HNL - Honduras Lempira')),
+    ('HRK', _('HRK - Croatia Kuna')),
+    ('HTG', _('HTG - Haiti Gourde')),
+    ('HUF', _('HUF - Hungary Forint')),
+    ('IDR', _('IDR - Indonesia Rupiah')),
+    ('ILS', _('ILS - Israel Shekel')),
+    ('IMP', _('IMP - Isle of Man Pound')),
+    ('INR', _('INR - India Rupee')),
+    ('IQD', _('IQD - Iraq Dinar')),
+    ('IRR', _('IRR - Iran Rial')),
+    ('ISK', _('ISK - Iceland Krona')),
+    ('JEP', _('JEP - Jersey Pound')),
+    ('JMD', _('JMD - Jamaica Dollar')),
+    ('JOD', _('JOD - Jordan Dinar')),
+    ('KES', _('KES - Kenya Shilling')),
+    ('KGS', _('KGS - Kyrgyzstan Som')),
+    ('KHR', _('KHR - Cambodia Riel')),
+    ('KMF', _('KMF - Comoros Franc')),
+    ('KPW', _('KPW - Korea (North) Won')),
+    ('KRW', _('KRW - Korea (South) Won')),
+    ('KWD', _('KWD - Kuwait Dinar')),
+    ('KYD', _('KYD - Cayman Islands Dollar')),
+    ('KZT', _('KZT - Kazakhstan Tenge')),
+    ('LAK', _('LAK - Laos Kip')),
+    ('LBP', _('LBP - Lebanon Pound')),
+    ('LKR', _('LKR - Sri Lanka Rupee')),
+    ('LRD', _('LRD - Liberia Dollar')),
+    ('LSL', _('LSL - Lesotho Loti')),
+    ('LTL', _('LTL - Lithuania Litas')),
+    ('LVL', _('LVL - Latvia Lat')),
+    ('LYD', _('LYD - Libya Dinar')),
+    ('MAD', _('MAD - Morocco Dirham')),
+    ('MDL', _('MDL - Moldova Le')),
+    ('MGA', _('MGA - Madagascar Ariary')),
+    ('MKD', _('MKD - Macedonia Denar')),
+    ('MMK', _('MMK - Myanmar (Burma) Kyat')),
+    ('MNT', _('MNT - Mongolia Tughrik')),
+    ('MOP', _('MOP - Macau Pataca')),
+    ('MRO', _('MRO - Mauritania Ouguiya')),
+    ('MUR', _('MUR - Mauritius Rupee')),
+    ('MVR', _('MVR - Maldives (Maldive Islands) Rufiyaa')),
+    ('MWK', _('MWK - Malawi Kwacha')),
+    ('MXN', _('MXN - Mexico Peso')),
+    ('MYR', _('MYR - Malaysia Ringgit')),
+    ('MZN', _('MZN - Mozambique Metical')),
+    ('NAD', _('NAD - Namibia Dollar')),
+    ('NGN', _('NGN - Nigeria Naira')),
+    ('NIO', _('NIO - Nicaragua Cordoba')),
+    ('NOK', _('NOK - Norway Krone')),
+    ('NPR', _('NPR - Nepal Rupee')),
+    ('NZD', _('NZD - New Zealand Dollar')),
+    ('OMR', _('OMR - Oman Rial')),
+    ('PAB', _('PAB - Panama Balboa')),
+    ('PEN', _('PEN - Peru Nuevo Sol')),
+    ('PGK', _('PGK - Papua New Guinea Kina')),
+    ('PHP', _('PHP - Philippines Peso')),
+    ('PKR', _('PKR - Pakistan Rupee')),
+    ('PLN', _('PLN - Poland Zloty')),
+    ('PYG', _('PYG - Paraguay Guarani')),
+    ('QAR', _('QAR - Qatar Riyal')),
+    ('RON', _('RON - Romania New Le')),
+    ('RSD', _('RSD - Serbia Dinar')),
+    ('RUB', _('RUB - Russia Ruble')),
+    ('RWF', _('RWF - Rwanda Franc')),
+    ('SAR', _('SAR - Saudi Arabia Riyal')),
+    ('SBD', _('SBD - Solomon Islands Dollar')),
+    ('SCR', _('SCR - Seychelles Rupee')),
+    ('SDG', _('SDG - Sudan Pound')),
+    ('SEK', _('SEK - Sweden Krona')),
+    ('SGD', _('SGD - Singapore Dollar')),
+    ('SHP', _('SHP - Saint Helena Pound')),
+    ('SLL', _('SLL - Sierra Leone Leone')),
+    ('SOS', _('SOS - Somalia Shilling')),
+    ('SPL', _('SPL - Seborga Luigino')),
+    ('SRD', _('SRD - Suriname Dollar')),
+    ('STD', _('STD - São Tomé and Príncipe Dobra')),
+    ('SVC', _('SVC - El Salvador Colon')),
+    ('SYP', _('SYP - Syria Pound')),
+    ('SZL', _('SZL - Swaziland Lilangeni')),
+    ('THB', _('THB - Thailand Baht')),
+    ('TJS', _('TJS - Tajikistan Somoni')),
+    ('TMT', _('TMT - Turkmenistan Manat')),
+    ('TND', _('TND - Tunisia Dinar')),
+    ('TOP', _("TOP - Tonga Pa'anga")),
+    ('TRY', _('TRY - Turkey Lira')),
+    ('TTD', _('TTD - Trinidad and Tobago Dollar')),
+    ('TVD', _('TVD - Tuvalu Dollar')),
+    ('TWD', _('TWD - Taiwan New Dollar')),
+    ('TZS', _('TZS - Tanzania Shilling')),
+    ('UAH', _('UAH - Ukraine Hryvna')),
+    ('UGX', _('UGX - Uganda Shilling')),
+    ('UYU', _('UYU - Uruguay Peso')),
+    ('UZS', _('UZS - Uzbekistan Som')),
+    ('VEF', _('VEF - Venezuela Bolivar')),
+    ('VND', _('VND - Viet Nam Dong')),
+    ('VUV', _('VUV - Vanuatu Vat')),
+    ('WST', _('WST - Samoa Tala')),
+    ('XAF', _('XAF - Communauté Financière Africaine (BEAC) CFA Franc BEAC')),
+    ('XCD', _('XCD - East Caribbean Dollar')),
+    ('XDR', _('XDR - International Monetary Fund (IMF) Special Drawing Rights')),
+    ('XOF', _('XOF - Communauté Financière Africaine (BCEAO) Franc')),
+    ('XPF', _('XPF - Comptoirs Français du Pacifique (CFP) Franc')),
+    ('YER', _('YER - Yemen Rial')),
+    ('ZAR', _('ZAR - South Africa Rand')),
+    ('ZMK', _('ZMK - Zambia Kwacha')),
+    ('ZWD', _('ZWD - Zimbabwe Dollar')),
+)
+
+class Country(models.Model):
+    """
+    Country model
+    =============
+
+    Stores 2-letter ISO country code 2-letter continent code
+    """
+
+    code = models.CharField(_('country'), max_length=2, choices=countries,
+                            unique=True)
+    continent = models.CharField(_('continent'), max_length=2,
+                                 choices=continents)
+
+

File international/settings.py

View file
+from __future__ import unicode_literals
+
+from django.utils.translation import ugettext as _
+
+COUNTRY_FORM_LABEL = 'country'
+COUNTRY_FORM_INCLUDE_EMPTY = False
+COUNTRY_FORM_EMPTY_VALUE = ''
+COUNTRY_FORM_EMPTY_LABEL = _('All countries')
+COUNTRY_FORM_INITIAL_VALUE = None
+COUNTRY_FORM_USE_STATIC = False
+CURRENCY_FORM_LABEL = 'currency'
+CURRENCY_FORM_INCLUDE_EMPTY = False
+CURRENCY_FORM_EMPTY_VALUE = ''
+CURRENCY_FORM_EMPTY_LABEL = _('All currencies')
+CURRENCY_FORM_INITIAL_VALUE = None

File international/views.py

View file
+# Create your views here.

File runtests.py

View file
+#!/usr/bin/env python
+
+from django.conf import settings, global_settings
+
+if not settings.configured:
+    settings.configure(
+        DATABASES={
+            'default': {
+                'ENGINE': 'django.db.backends.sqlite3',
+            }
+        },
+        INSTALLED_APPS=[
+            'international',
+            'tests',
+        ],
+        ROOT_URLCONF='',
+        DEBUG=False,
+        SITE_ID=1,
+    )
+
+
+import sys
+from os.path import dirname, abspath
+from optparse import OptionParser
+from django.test.simple import DjangoTestSuiteRunner
+
+def runtests(*test_args, **kwargs):
+    if 'south' in settings.INSTALLED_APPS:
+        from south.management.commands import
+        patch_for_test_db_setup
+        patch_for_test_db_setup()
+
+    if not test_args:
+        test_args = ['tests']
+    parent =
+    dirname(abspath(__file__))
+    sys.path.insert(0, parent)
+    test_runner = DjangoTestSuiteRunner(verbosity=kwargs.get('verbosity', 1),
+                                        interactive=kwargs.get('interactive',
+                                                               False),
+                                        failfast=kwargs.get('failfast'))
+    failures = test_runner.run_tests(test_args)
+    sys.exit(failures)
+
+if __name__ == '__main__':
+    parser = OptionParser()
+    parser.add_option('--failfast', action='store_true', default=False, dest='failfast')
+
+    (options, args) = parser.parse_args()
+
+    runtests(failfast=options.failfast, *args)
+

File test/tests.py

View file
+from __future__ import unicode_literals
+
+from django.test import TestCase
+from django.test.utils import override_settings
+
+from models import Country
+from forms import *
+
+class CountryTestCase(TestCase):
+    def setUp(self):
+        self.country = Country.objects.create(code='AR', continent='SA')
+
+    def test_can_get_country(self):
+        c = self.country
+        self.assertEquals(c.code, 'AR')
+        self.assertEquals(c.continent, 'SA')
+        self.assertEquals(c.get_code_display(), 'Argentina')
+        self.assertEquals(c.get_continent_display(), 'South America')
+
+    def tearDown(self):
+        Country.objects.all().delete()
+
+# We need a whole bunch of overrides to make sure all settings are at defaults
+@override_settings(
+    COUTNRY_FORM_LABEL='currency',
+    COUNTRY_FORM_INCLUDE_EMPTY=False,
+    COUNTRY_FORM_EMPTY_VALUE='',
+    COUNTRY_FORM_EMPTY_LABEL='All countries',
+    COUNTRY_FORM_INITIAL_VALUE='',
+    COUNTRY_FORM_USE_STATIC=False,
+)
+class CountryFormTestCase(TestCase):
+    def setUp(self):
+        self.country = Country.objects.create(code='AR', continent='SA')
+
+    def tearDown(self):
+        Country.objects.all().delete()
+
+    def test_default_form(self):
+        # We do the import here so that settings are properly evaluated
+        form = CountryForm()
+        self.assertIn(('AR', 'Argentina'), form.fields['country'].choices)
+        self.assertNotIn(('US', 'United States'),
+                         form.fields['country'].choices)
+
+    @override_settings(COUNTRY_FORM_USE_STATIC=True)
+    def test_form_with_static(self):
+        form = CountryForm()
+        self.assertIn(('AR', 'Argentina'), form.fields['country'].choices)
+        self.assertIn(('US', 'United States'),
+                      form.fields['country'].choices)
+
+    @override_settings(COUNTRY_FORM_LABEL='location')
+    def test_form_label(self):
+        form = CountryForm()
+        self.assertEquals(form.fields['country'].label, 'location')
+
+    @override_settings(COUNTRY_FORM_INCLUDE_EMPTY=True)
+    def test_has_empty_item(self):
+        form = CountryForm()
+        self.assertIn(('', 'All countries'), form.fields['country'].choices)
+
+    @override_settings(COUNTRY_FORM_INCLUDE_EMPTY=True,
+                       COUNTRY_FORM_EMPTY_VALUE='*',
+                       COUNTRY_FORM_EMPTY_LABEL='Any country')
+    def test_empty_label(self):
+        form = CountryForm()
+        self.assertIn(('*', 'Any country'), form.fields['country'].choices)
+
+
+    @override_settings(COUNTRY_FORM_INITIAL_VALUE='AR',
+                       COUNTRY_FORM_ALLOW_EMPTY=True,
+                       COUNTRY_FORM_EMPTY_VALUE='*')
+    def test_initial_value(self):
+        form = CountryForm()
+        self.assertEquals(form.fields['country'].initial, 'AR')
+
+        form = CountryForm(initial={'country': '*'})
+        self.assertEquals(form.fields['country'].initial, '*')
+
+# We need a whole bunch of overrides to make sure all settings are at defaults
+@override_settings(
+    CURRENCY_FORM_LABEL='currency',
+    CURRENCY_FORM_INCLUDE_EMPTY=False,
+    CURRENCY_FORM_EMPTY_VALUE='',
+    CURRENCY_FORM_EMPTY_LABEL='All currencies',
+    CURRENCY_FORM_INITIAL_VALUE=None,
+)
+class CurrencyFormTestCase(TestCase):
+    def test_default_form(self):
+        form = CurrencyForm()
+        self.assertEquals(form.fields['currency'].choices[0][0], 'USD')
+
+    @override_settings(CURRENCY_FORM_LABEL='transaction in')
+    def test_label(self):
+        form = CurrencyForm()
+        self.assertEquals(form.fields['currency'].label, 'transaction in')
+
+    @override_settings(CURRENCY_FORM_INCLUDE_EMPTY=True,
+                       CURRENCY_FORM_EMPTY_VALUE='*',
+                       CURRENCY_FORM_EMPTY_LABEL='Any currency')
+    def test_empty(self):
+        form = CurrencyForm()
+        self.assertIn(('*', 'Any currency'), form.fields['currency'].choices)
+
+    @override_settings(CURRENCY_FORM_INITIAL_VALUE='JPY')
+    def test_default_value(self):
+        form = CurrencyForm()
+        self.assertEquals(form.fields['currency'].initial, 'JPY')
+        form = CurrencyForm(initial={'currency': 'GBP'})
+        self.assertEquals(form.fields['currency'].initial, 'GBP')