*Simple django-cities alternative with spatial support *
django-cities-light --This add-on provides models and commands to import country, region/state, and city data in your database.
The data is pulled from GeoNames and contains cities, regions/states and countries.
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 database, you should use django-cities.
Requirements:
- Python 2.7 or 3.3,
- Django 1.9
- PostgreSQL
Upgrade
See CHANGELOG.
Installation
Install django-cities-light:
pip install -e git+git@github.com:max-arnold/django-cities-light.git@spatial#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/City slugs. But there is an option to keep them intact:
./manage.py cities_light --keep-slugs
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
To run the test suite you need to have postgresql installed with passwordless login. 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 py27-django19-postgresql
And to run one specific test use this one:
tox -e py27-django19-postgresql -- cities_light/tests/test_form.py::FormTestCase::testCountryFormNameAndContinentAlone
To run it even faster, you can switch to specific tox virtualenv:
source .tox/py27-django19-postgresql/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 YourLabs guidelines: https://github.com/yourlabs/community/blob/master/docs/guidelines.rst
Resources
You could subscribe to the mailing list ask questions or just be informed of package updates.
- Mailing list graciously hosted by Google
- For Security issues, please contact yourlabs-security@googlegroups.com
- Git graciously hosted by GitHub,
- Documentation graciously hosted by RTFD,
- Package graciously hosted by PyPi,
- Continuous integration graciously hosted by Travis-ci
- **Online paid support** provided via HackHands,