Skip to main content

Simple alternative to django-cities

Project description

https://secure.travis-ci.org/jazzband/django-cities-light.svg?branch=master https://pypip.in/d/django-cities-light/badge.png https://pypip.in/v/django-cities-light/badge.png https://codecov.io/github/jazzband/django-cities-light/coverage.svg Jazzband

django-cities-light – Simple django-cities alternative

This add-on provides models and commands to import country, subregion, region/state, and city data in your database.

The data is pulled from GeoNames and contains cities, subregions, regions/states and countries.

Spatial query support is not required by this application.

This application is very simple and is useful if you want to make a simple address book for example. If you intend to build a fully featured spatial database, you should use django-cities.

Requirements:

  • Python >= 3.6

  • Django >= 2.2

  • MySQL or PostgreSQL or SQLite.

Yes, for some reason, code that used to work on MySQL (not without pain xD) does not work anymore. So we’re now using django.db.transaction.atomic which comes from Django 1.6 just to support MySQL quacks.

Upgrade

See CHANGELOG.

Installation

Install django-cities-light:

pip install django-cities-light

Or the development version:

pip install -e git+git@github.com:jazzband/django-cities-light.git#egg=cities_light

Add cities_light to your INSTALLED_APPS.

Configure filters to exclude data you don’t want, ie.:

CITIES_LIGHT_TRANSLATION_LANGUAGES = ['fr', 'en']
CITIES_LIGHT_INCLUDE_COUNTRIES = ['FR']
CITIES_LIGHT_INCLUDE_CITY_TYPES = ['PPL', 'PPLA', 'PPLA2', 'PPLA3', 'PPLA4', 'PPLC', 'PPLF', 'PPLG', 'PPLL', 'PPLR', 'PPLS', 'STLMT',]

Now, run migrations, it will only create tables for models that are not disabled:

./manage.py migrate

Data import/update

Finally, populate your database with command:

./manage.py cities_light

This command is well documented, consult the help with:

./manage.py help cities_light

By default, update procedure attempts to update all fields, including Country/Region/Subregion/City slugs. But there is an option to keep them intact:

./manage.py cities_light --keep-slugs

Get more cities

The configuration parameter CITIES_LIGHT_CITY_SOURCES, comes with the default value http://download.geonames.org/export/dump/cities15000.zip that has cities with a population over 15000, if you need to load cities with less population please use another source. For the list of available source please check here: http://download.geonames.org/export/dump/readme.txt

Using fixtures

Geonames.org is updated on daily basis and its full import is quite slow, so if you want to import the same data multiple times (for example on different servers) it is convenient to use fixtures with the helper management command:

./manage.py cities_light_fixtures dump
./manage.py cities_light_fixtures load

To reduce space, JSON fixtures are compressed with bzip2 and can be fetched from any HTTP server or local filesystem.

Consult the help with:

./manage.py help cities_light_fixtures

Development

Create development virtualenv (you need to have tox installed in your base system):

tox -e dev
source .tox/dev/bin/activate

Then run the full import:

test_project/manage.py migrate
test_project/manage.py cities_light

There are several environment variables which affect project settings (like DB_ENGINE and CI), you can find them all in test_project/settings.py.

To run the test suite you need to have postgresql or mysql installed with passwordless login, or just use sqlite. Otherwise the tests which try to create/drop database will fail.

Running the full test suite:

tox

To run the tests in specific environment use the following command:

tox -e py37-django31-sqlite

And to run one specific test use this one:

tox -e py37-django31-sqlite -- cities_light/tests/test_form.py::FormTestCase::testCountryFormNameAndContinentAlone

To run it even faster, you can switch to specific tox virtualenv:

source .tox/py27-django18-sqlite/bin/activate
CI=true test_project/manage.py test cities_light.tests.test_form.FormTestCase.testCountryFormNameAndContinentAlone

If you want to build the docs, use the following steps:

source .tox/dev/bin/activate
cd docs
make html

If you are ready to send a patch, please read the Jazzband guidelines.

Resources

You could subscribe to the mailing list ask questions or just be informed of package updates.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-cities-light-3.8.1.tar.gz (99.3 kB view details)

Uploaded Source

Built Distribution

django_cities_light-3.8.1-py3-none-any.whl (116.9 kB view details)

Uploaded Python 3

File details

Details for the file django-cities-light-3.8.1.tar.gz.

File metadata

  • Download URL: django-cities-light-3.8.1.tar.gz
  • Upload date:
  • Size: 99.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for django-cities-light-3.8.1.tar.gz
Algorithm Hash digest
SHA256 2f2ffe76eb8d25cf813172e5d0e145f716ed9294c5a9d5d4e718515d373c13f3
MD5 a1be404a6f920e0291452c4a745000a1
BLAKE2b-256 f96c73cd8fbbfefa34893d63381e7820f7fa7772c358d91db1e3afc6eac7dec4

See more details on using hashes here.

File details

Details for the file django_cities_light-3.8.1-py3-none-any.whl.

File metadata

  • Download URL: django_cities_light-3.8.1-py3-none-any.whl
  • Upload date:
  • Size: 116.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for django_cities_light-3.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c48ad18f69fcc7603c99801de120d6eb0bbe0a65b8e4990af76b3cfd193b2a5d
MD5 bc2ad1c782e1492c9ea1fc3c53210052
BLAKE2b-256 dde54a7bc3fe6a1678ccc09cdce2d09f30e7fcf6d15af1f77e79077b3a0df62d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page