django-countries-5.3.2/0000755000175000017500000000000013340700564015240 5ustar chrischris00000000000000django-countries-5.3.2/setup.cfg0000644000175000017500000000305413340700564017063 0ustar chrischris00000000000000[metadata] name = django-countries version = 5.3.2 description = Provides a country field for Django models. long_description = file: README.rst, CHANGES.rst author = Chris Beaven author_email = smileychris@gmail.com url = https://github.com/SmileyChris/django-countries/ keywords = django, countries, flags license = MIT classifiers = Development Status :: 5 - Production/Stable Environment :: Web Environment Intended Audience :: Developers License :: OSI Approved :: MIT License Operating System :: OS Independent Programming Language :: Python Programming Language :: Python :: 2.7 Programming Language :: Python :: 3.4 Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 Framework :: Django [options] zip_safe = False include_package_data = True packages = find: [options.extras_require] maintainer = transifex-client zest.releaser[recommended] django dev = tox django pytest pytest-django test = pytest pytest-django pytest-cov [bdist_wheel] universal = 1 [flake8] exclude = .tox, .git, __pycache__, build, dist [coverage:run] source = django_countries omit = django_countries/release.py django_countries/makesprite.py [zest.releaser] less-zeros = yes version-levels = 2 tag-format = v{version} tag-message = Version {version} tag-signing = yes date-format = %%-d %%B %%Y prereleaser.middle = django_countries.release.translations [check-manifest] ignore-bad-ideas = *.mo [tool:pytest] django_settings_module = django_countries.tests.settings filterwarnings = module [egg_info] tag_build = tag_date = 0 django-countries-5.3.2/LICENSE0000644000175000017500000000206013340700563016242 0ustar chrischris00000000000000Copyright (c) 2010 Chris Beaven and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.django-countries-5.3.2/django_countries/0000755000175000017500000000000013340700564020575 5ustar chrischris00000000000000django-countries-5.3.2/django_countries/release.py0000644000175000017500000000164413340700563022573 0ustar chrischris00000000000000""" This file provides zest.releaser entrypoints using when releasing new django-countries versions. """ import os from txclib.commands import cmd_pull from txclib.utils import find_dot_tx from txclib.log import logger from zest.releaser.utils import ask, execute_command from django.core.management import call_command import django_countries def translations(data): if data['name'] != 'django-countries': return if not ask('Pull translations from transifex and compile', default=True): return _handlers = logger.handlers logger.handlers = [] try: cmd_pull(argv=['-a', '--minimum-perc=60'], path_to_tx=find_dot_tx()) finally: logger.handlers = _handlers _cwd = os.getcwd() os.chdir(os.path.dirname(django_countries.__file__)) try: call_command('compilemessages') execute_command(['git', 'add', 'locale']) finally: os.chdir(_cwd) django-countries-5.3.2/django_countries/conf.py0000644000175000017500000000532413340700563022077 0ustar chrischris00000000000000import django.conf class AppSettings(object): """ A holder for app-specific default settings that allows overriding via the project's settings. """ def __getattribute__(self, attr): if attr == attr.upper(): try: return getattr(django.conf.settings, attr) except AttributeError: pass return super(AppSettings, self).__getattribute__(attr) class Settings(AppSettings): COUNTRIES_FLAG_URL = 'flags/{code}.gif' """ The URL for a flag. It can either be relative to the static url, or an absolute url. The location is parsed using Python's string formatting and is passed the following arguments: * code * code_upper For example: ``COUNTRIES_FLAG_URL = 'flags/16x10/{code_upper}.png'`` """ COUNTRIES_COMMON_NAMES = True """ Whether to use the common names for some countries, as opposed to the official ISO name. Some examples: "Bolivia" instead of "Bolivia, Plurinational State of" "South Korea" instead of "Korea (the Republic of)" "Taiwan" instead of "Taiwan (Province of China)" """ COUNTRIES_OVERRIDE = {} """ A dictionary of names to override the defaults. Note that you will need to handle translation of customised country names. Setting a country's name to ``None`` will exclude it from the country list. For example:: COUNTRIES_OVERRIDE = { 'NZ': _('Middle Earth'), 'AU': None } """ COUNTRIES_ONLY = {} """ Similar to COUNTRIES_OVERRIDE A dictionary of names to include in selection. Note that you will need to handle translation of customised country names. For example:: COUNTRIES_ONLY = { 'NZ': _('Middle Earth'), 'AU': _('Desert'), } """ COUNTRIES_FIRST = [] """ Countries matching the country codes provided in this list will be shown first in the countries list (in the order specified) before all the alphanumerically sorted countries. """ COUNTRIES_FIRST_REPEAT = False """ Countries listed in :attr:`COUNTRIES_FIRST` will be repeated again in the alphanumerically sorted list if set to ``True``. """ COUNTRIES_FIRST_BREAK = None """ Countries listed in :attr:`COUNTRIES_FIRST` will be followed by a null choice with this title (if set) before all the alphanumerically sorted countries. """ COUNTRIES_FIRST_SORT = False """ Countries listed in :attr:`COUNTRIES_FIRST` will be alphanumerically sorted based on their translated name instead of relying on their order in :attr:`COUNTRIES_FIRST`. """ settings = Settings() django-countries-5.3.2/django_countries/serializers.py0000644000175000017500000000231213340700563023500 0ustar chrischris00000000000000from . import fields, serializer_fields from rest_framework import serializers class CountryFieldMixin(object): def build_standard_field(self, field_name, model_field): field_class, field_kwargs = ( super(CountryFieldMixin, self) .build_standard_field(field_name, model_field) ) if ( # Only deal with CountryFields. not isinstance(model_field, fields.CountryField) or # Some other mixin has changed the field class already! field_class is not serializers.ChoiceField ): return field_class, field_kwargs field_kwargs['countries'] = model_field.countries del field_kwargs['choices'] if not model_field.multiple: field_class = serializer_fields.CountryField else: field_class = serializers.ListField child_field = serializer_fields.CountryField(**field_kwargs) field_kwargs = {'child': child_field} if 'max_length' in serializers.ListField.default_error_messages: # Added in DRF 3.5.4 field_kwargs['max_length'] = len(child_field.countries) return field_class, field_kwargs django-countries-5.3.2/django_countries/tests/0000755000175000017500000000000013340700564021737 5ustar chrischris00000000000000django-countries-5.3.2/django_countries/tests/models.py0000644000175000017500000000207013340700563023572 0ustar chrischris00000000000000from django.db import models from django_countries.fields import CountryField from django_countries.tests import custom_countries class Person(models.Model): name = models.CharField(max_length=50) country = CountryField() other_country = CountryField( blank=True, countries_flag_url='//flags.example.com/{code}.gif') favourite_country = CountryField(default='NZ') fantasy_country = CountryField( countries=custom_countries.FantasyCountries, blank=True) class Meta: ordering = ('name',) class AllowNull(models.Model): country = CountryField(null=True, blank_label='(select country)') class MultiCountry(models.Model): countries = CountryField(multiple=True) uneditable_countries = CountryField(multiple=True, editable=False) class WithProp(models.Model): country = CountryField() _private_field = models.CharField(max_length=10) @property def public_field(self): return self._private_field @public_field.setter def public_field(self, value): self._private_field = value django-countries-5.3.2/django_countries/tests/custom_countries.py0000644000175000017500000000016313340700563025715 0ustar chrischris00000000000000from django_countries import Countries class FantasyCountries(Countries): only = ['NZ', ('NV', 'Neverland')] django-countries-5.3.2/django_countries/tests/apps.py0000644000175000017500000000021213340700563023246 0ustar chrischris00000000000000from django.apps import AppConfig class TestConfig(AppConfig): name = 'django_countries.tests' label = 'django_countries_tests' django-countries-5.3.2/django_countries/tests/test_settings.py0000644000175000017500000000317013340700563025210 0ustar chrischris00000000000000from __future__ import unicode_literals from django.test import TestCase from django.utils import six from django_countries import countries, data, base class TestSettings(TestCase): def setUp(self): del countries.countries def tearDown(self): del countries.countries def test_override_additional(self): with self.settings(COUNTRIES_OVERRIDE={'XX': 'New'}): self.assertEqual(countries.name('XX'), 'New') def test_override_replace(self): with self.settings(COUNTRIES_OVERRIDE={'NZ': 'Middle Earth'}): self.assertEqual(countries.name('NZ'), 'Middle Earth') def test_override_remove(self): with self.settings(COUNTRIES_OVERRIDE={'AU': None}): self.assertNotIn('AU', countries) self.assertEqual(countries.name('AU'), '') def test_override_only(self): with self.settings(COUNTRIES_ONLY={'AU': 'Desert'}): self.assertTrue(len(countries.countries) == 1) self.assertIn('AU', countries) self.assertEqual(countries.name('AU'), 'Desert') def test_common_names(self): common_code, common_name = ( list(base.CountriesBase.COMMON_NAMES.items())[0]) common_name = six.text_type(common_name) name = six.text_type(countries.countries[common_code]) self.assertEqual(name, common_name) del countries.countries official_name = six.text_type(data.COUNTRIES[common_code]) with self.settings(COUNTRIES_COMMON_NAMES=False): name = six.text_type(countries.countries[common_code]) self.assertEqual(name, official_name) django-countries-5.3.2/django_countries/tests/settings.py0000644000175000017500000000206313340700563024151 0ustar chrischris00000000000000SECRET_KEY = 'test' INSTALLED_APPS = ( 'django.contrib.contenttypes', 'django.contrib.auth', 'django_countries', 'django_countries.tests', ) DATABASES = { 'default': {'ENGINE': 'django.db.backends.sqlite3'} } STATIC_URL = '/static-assets/' MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.locale.LocaleMiddleware' ) TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.contrib.auth.context_processors.auth', 'django.template.context_processors.debug', 'django.template.context_processors.i18n', 'django.template.context_processors.media', 'django.template.context_processors.static', 'django.template.context_processors.tz', 'django.contrib.messages.context_processors.messages', ], }, }, ] django-countries-5.3.2/django_countries/tests/test_widgets.py0000644000175000017500000000501413340700563025015 0ustar chrischris00000000000000from __future__ import unicode_literals from unittest import skipIf try: from urllib import parse as urlparse except ImportError: import urlparse # Python 2 from distutils.version import StrictVersion import django from django.forms.models import modelform_factory from django.test import TestCase from django.utils import safestring from django.utils.html import escape from django_countries import widgets, countries, fields from django_countries.conf import settings from django_countries.tests.models import Person class TestCountrySelectWidget(TestCase): def setUp(self): del countries.countries self.Form = modelform_factory( Person, fields=['country'], widgets={'country': widgets.CountrySelectWidget}) def tearDown(self): del countries.countries def test_not_default_widget(self): Form = modelform_factory(Person, fields=['country']) widget = Form().fields['country'].widget self.assertFalse(isinstance(widget, widgets.CountrySelectWidget)) def test_render_contains_flag_url(self): with self.settings(COUNTRIES_ONLY={'AU': 'Desert'}): html = self.Form().as_p() self.assertIn(escape(urlparse.urljoin( settings.STATIC_URL, settings.COUNTRIES_FLAG_URL)), html) def test_render(self): with self.settings(COUNTRIES_ONLY={'AU': 'Desert'}): html = self.Form().as_p() self.assertIn(fields.Country('__').flag, html) self.assertNotIn(fields.Country('AU').flag, html) def test_render_initial(self): with self.settings(COUNTRIES_ONLY={'AU': 'Desert'}): html = self.Form(initial={'country': 'AU'}).as_p() self.assertIn(fields.Country('AU').flag, html) self.assertNotIn(fields.Country('__').flag, html) def test_render_escaping(self): output = widgets.CountrySelectWidget().render('test', '