django-cities-light


Namedjango-cities-light JSON
Version 3.10.1 PyPI version JSON
download
home_pagehttps://github.com/yourlabs/django-cities-light
SummarySimple alternative to django-cities
upload_time2024-01-08 22:50:58
maintainer
docs_urlNone
authorJames Pic,Dominick Rivard,Alexey Evseev
requires_python
licenseMIT
keywords django cities countries postal codes
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            .. image:: https://secure.travis-ci.org/yourlabs/django-cities-light.svg?branch=master
    :target: http://travis-ci.org/yourlabs/django-cities-light
.. image:: https://img.shields.io/pypi/dm/django-cities-light.svg
    :target: https://crate.io/packages/django-cities-light
.. image:: https://img.shields.io/pypi/v/django-cities-light.svg
    :target: https://crate.io/packages/django-cities-light
.. image:: https://codecov.io/github/yourlabs/django-cities-light/coverage.svg
    :target: https://codecov.io/github/yourlabs/django-cities-light


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
<http://www.geonames.org/>`_ 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
<https://github.com/coderholic/django-cities>`_.

Requirements:

- Python >= 3.8
- Django >= 3.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.

Features
--------
- GraphQL support
- Built-in admin support
- Rest-Framework support
- Ajax Select Lookup support

Upgrade
-------

See CHANGELOG.

Installation
------------

Install django-cities-light::

    pip install django-cities-light

Or the development version::

    pip install -e git+git@github.com:yourlabs/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

To run the test project, with the folder of the project as the current directory, run::
    
    export PYTHONPATH="${PYTHONPATH}:/app/src"
    docker run  -d postgres -p 5432:5432


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.

For example to change the database engine, you can run::

    export DB_ENGINE=postgresql
    export DB_HOST=192.168.0.118
    export DB_NAME=app
    export DB_USER=postgres
    export DB_PORT=5432

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/py37-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

TODOS
-----

- Add ruff for formatting
- Improve the performance of the import command
- Improve the local development environment with https://tox.wiki/en/legacy/example/devenv.html

Resources
---------

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

- `Git graciously hosted
  <https://github.com/yourlabs/django-cities-light/>`_ by `GitHub
  <http://github.com>`_,
- `Documentation graciously hosted
  <http://django-cities-light.rtfd.org>`_ by `RTFD
  <http://rtfd.org>`_,
- `Package graciously hosted
  <http://pypi.python.org/pypi/django-cities-light/>`_ by `PyPi
  <http://pypi.python.org/pypi>`_,
- `Continuous integration graciously hosted
  <http://travis-ci.org/yourlabs/django-cities-light>`_ by `Travis-ci
  <http://travis-ci.org>`_

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/yourlabs/django-cities-light",
    "name": "django-cities-light",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "django cities countries postal codes",
    "author": "James Pic,Dominick Rivard,Alexey Evseev",
    "author_email": "jamespic@gmail.com, dominick.rivard@gmail.com, myhappydo@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/70/af/cda4cc6427d8332ad167079872f7dfae42f12e1610142e94160b14f15879/django-cities-light-3.10.1.tar.gz",
    "platform": null,
    "description": ".. image:: https://secure.travis-ci.org/yourlabs/django-cities-light.svg?branch=master\n    :target: http://travis-ci.org/yourlabs/django-cities-light\n.. image:: https://img.shields.io/pypi/dm/django-cities-light.svg\n    :target: https://crate.io/packages/django-cities-light\n.. image:: https://img.shields.io/pypi/v/django-cities-light.svg\n    :target: https://crate.io/packages/django-cities-light\n.. image:: https://codecov.io/github/yourlabs/django-cities-light/coverage.svg\n    :target: https://codecov.io/github/yourlabs/django-cities-light\n\n\ndjango-cities-light -- *Simple django-cities alternative*\n=========================================================\n\nThis add-on provides models and commands to import country, subregion, region/state, and\ncity data in your database.\n\nThe data is pulled from `GeoNames\n<http://www.geonames.org/>`_ and contains cities, subregions, regions/states and countries.\n\nSpatial query support is not required by this application.\n\nThis application is very simple and is useful if you want to make a simple\naddress book for example. If you intend to build a fully featured spatial\ndatabase, you should use\n`django-cities\n<https://github.com/coderholic/django-cities>`_.\n\nRequirements:\n\n- Python >= 3.8\n- Django >= 3.2\n- MySQL or PostgreSQL or SQLite.\n\nYes, for some reason, code that used to work on MySQL (not without pain xD)\ndoes not work anymore. So we're now using django.db.transaction.atomic which\ncomes from Django 1.6 just to support MySQL quacks.\n\nFeatures\n--------\n- GraphQL support\n- Built-in admin support\n- Rest-Framework support\n- Ajax Select Lookup support\n\nUpgrade\n-------\n\nSee CHANGELOG.\n\nInstallation\n------------\n\nInstall django-cities-light::\n\n    pip install django-cities-light\n\nOr the development version::\n\n    pip install -e git+git@github.com:yourlabs/django-cities-light.git#egg=cities_light\n\nAdd `cities_light` to your `INSTALLED_APPS`.\n\nConfigure filters to exclude data you don't want, ie.::\n\n    CITIES_LIGHT_TRANSLATION_LANGUAGES = ['fr', 'en']\n    CITIES_LIGHT_INCLUDE_COUNTRIES = ['FR']\n    CITIES_LIGHT_INCLUDE_CITY_TYPES = ['PPL', 'PPLA', 'PPLA2', 'PPLA3', 'PPLA4', 'PPLC', 'PPLF', 'PPLG', 'PPLL', 'PPLR', 'PPLS', 'STLMT',]\n\nNow, run migrations, it will only create tables for models that are not\ndisabled::\n\n    ./manage.py migrate\n\nData import/update\n------------------\n\nFinally, populate your database with command::\n\n    ./manage.py cities_light\n\nThis command is well documented, consult the help with::\n\n    ./manage.py help cities_light\n\nBy default, update procedure attempts to update all fields, including Country/Region/Subregion/City slugs. But there is an option to keep them intact::\n\n    ./manage.py cities_light --keep-slugs\n\n\nGet more cities\n---------------\n\nThe configuration parameter CITIES_LIGHT_CITY_SOURCES, comes with the default value\nhttp://download.geonames.org/export/dump/cities15000.zip that has cities with a population\nover 15000, if you need to load cities with less population please use another source. For the list\nof available source please check here: http://download.geonames.org/export/dump/readme.txt\n\n\n\nUsing fixtures\n--------------\n\nGeonames.org is updated on daily basis and its full import is quite slow, so\nif you want to import the same data multiple times (for example on different\nservers) it is convenient to use fixtures with the helper management command::\n\n    ./manage.py cities_light_fixtures dump\n    ./manage.py cities_light_fixtures load\n\nTo reduce space, JSON fixtures are compressed with bzip2 and can be fetched\nfrom any HTTP server or local filesystem.\n\nConsult the help with::\n\n    ./manage.py help cities_light_fixtures\n\nDevelopment\n-----------\n\nCreate development virtualenv (you need to have tox installed in your base system)::\n\n    tox -e dev\n    source .tox/dev/bin/activate\n\nTo run the test project, with the folder of the project as the current directory, run::\n    \n    export PYTHONPATH=\"${PYTHONPATH}:/app/src\"\n    docker run  -d postgres -p 5432:5432\n\n\nThen run the full import::\n\n    test_project/manage.py migrate\n    test_project/manage.py cities_light\n\nThere are several environment variables which affect project settings (like DB_ENGINE and CI), you can find them all in test_project/settings.py.\n\nFor example to change the database engine, you can run::\n\n    export DB_ENGINE=postgresql\n    export DB_HOST=192.168.0.118\n    export DB_NAME=app\n    export DB_USER=postgres\n    export DB_PORT=5432\n\nTo 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.\n\nRunning the full test suite::\n\n    tox\n\nTo run the tests in specific environment use the following command::\n\n    tox -e py37-django31-sqlite\n\nAnd to run one specific test use this one::\n\n    tox -e py37-django31-sqlite -- cities_light/tests/test_form.py::FormTestCase::testCountryFormNameAndContinentAlone\n\nTo run it even faster, you can switch to specific tox virtualenv::\n\n    source .tox/py37-django18-sqlite/bin/activate\n    CI=true test_project/manage.py test cities_light.tests.test_form.FormTestCase.testCountryFormNameAndContinentAlone\n\nIf you want to build the docs, use the following steps::\n\n    source .tox/dev/bin/activate\n    cd docs\n    make html\n\nTODOS\n-----\n\n- Add ruff for formatting\n- Improve the performance of the import command\n- Improve the local development environment with https://tox.wiki/en/legacy/example/devenv.html\n\nResources\n---------\n\nYou could subscribe to the mailing list ask questions or just be informed of\npackage updates.\n\n- `Git graciously hosted\n  <https://github.com/yourlabs/django-cities-light/>`_ by `GitHub\n  <http://github.com>`_,\n- `Documentation graciously hosted\n  <http://django-cities-light.rtfd.org>`_ by `RTFD\n  <http://rtfd.org>`_,\n- `Package graciously hosted\n  <http://pypi.python.org/pypi/django-cities-light/>`_ by `PyPi\n  <http://pypi.python.org/pypi>`_,\n- `Continuous integration graciously hosted\n  <http://travis-ci.org/yourlabs/django-cities-light>`_ by `Travis-ci\n  <http://travis-ci.org>`_\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simple alternative to django-cities",
    "version": "3.10.1",
    "project_urls": {
        "Homepage": "https://github.com/yourlabs/django-cities-light"
    },
    "split_keywords": [
        "django",
        "cities",
        "countries",
        "postal",
        "codes"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06ef79ad551f1e914a396bc7538c57316b727dfa349546623ffa5f3ad5118075",
                "md5": "5b7b6b22178dda932128a235163219dc",
                "sha256": "aff7052e37716d32608738a99aa0b5e4569c353ee190307d7fccf52452818ac9"
            },
            "downloads": -1,
            "filename": "django_cities_light-3.10.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5b7b6b22178dda932128a235163219dc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 121736,
            "upload_time": "2024-01-08T22:50:55",
            "upload_time_iso_8601": "2024-01-08T22:50:55.661617Z",
            "url": "https://files.pythonhosted.org/packages/06/ef/79ad551f1e914a396bc7538c57316b727dfa349546623ffa5f3ad5118075/django_cities_light-3.10.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "70afcda4cc6427d8332ad167079872f7dfae42f12e1610142e94160b14f15879",
                "md5": "c4c82c2884bf09e7b909c22309e4da19",
                "sha256": "0d333dd53ad85f3acfcc2c4c8c8d3ab3a7dfdcdb5a61dcff9c96c393e2781ed8"
            },
            "downloads": -1,
            "filename": "django-cities-light-3.10.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c4c82c2884bf09e7b909c22309e4da19",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 103709,
            "upload_time": "2024-01-08T22:50:58",
            "upload_time_iso_8601": "2024-01-08T22:50:58.143783Z",
            "url": "https://files.pythonhosted.org/packages/70/af/cda4cc6427d8332ad167079872f7dfae42f12e1610142e94160b14f15879/django-cities-light-3.10.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-08 22:50:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yourlabs",
    "github_project": "django-cities-light",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "django-cities-light"
}
        
Elapsed time: 0.17240s