Skip to main content

Build Status

Django Political Map

Django application to store geolocalized places and organize them according to political hierarchy.

Note: this project doesn't require GeoDjango or Gis fields, you should save geographical data in your own model in order to perform gis queries.

Features:

  • store your geographic data in a single model
  • provide address and process it to automatically fill all geo informations
  • using the provided form you can choose the place on the map
  • and process automatically the location

Installation

This package looks stable but it needs more live testing. If you want to try it in your project, you can pip install it:

  • pip install django-political-map

or via git:

  • pip install git+https://github.com/20tab/django-political-map.git

  • add politicalplaces in your INSTALLED_APPS

  • set mandatory parameters in your settings file:

# BACKEND (googlemaps is the only available backend)
POLITICAL_MAP_BACKEND = 'googlemaps'
# MAP LANGUAGE (en is the only available language)
POLITICAL_MAP_LANGUAGE_CODE = 'en'
# GMAPS (gmaps key is mandatory)
GOOGLE_API_KEY = "xxxxxxxxxxxxxxxx"
  • run migrations to update your db python manage.py migrate  
  • manage static files using:
    • django collectstatic or  
    • uwsgi static-map = /static/politicalplaces/=%(lib)/politicalplaces/static/politicalplaces    

How to

There is one only entry point to the app, that is the Placefield. This field is a Foreign Key to PoliticalPlace, so you should use it this way:

from django.db import models                                                
from politicalplaces.fields import PlaceField


class MyLocation(models.Model):
    place = PlaceField(
        on_delete=models.SET_NULL,
        null=True, blank=True)

PoliticalPlace and MapItem admin are available, but you should never add these objects directly.

Using PoliticalPlace in the views

from politicalplaces.models import PoliticalPlace
from .models import MyLocation


loc = MyLocation()
loc.name = "Test Location"
place = PoliticalPlace.get_or_create_from_address(
    address='via Luigi Gastinelli, Rome')
loc.place = place
loc.save()

Refresh Data (django command)

(django-political-map) 20tab:django-political-map gabbo$ python manage.py refresh_data --help
usage: manage.py refresh_data [-h] [--version] [-v {0,1,2,3}]
                              [--settings SETTINGS] [--pythonpath PYTHONPATH]
                              [--traceback] [--no-color]
                              [place_id [place_id ...]]

Refresh map data calling the external api

positional arguments:
  place_id              The id list, separeted by space, of the involved
                        PoliticalPlace objects.

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=verbose output, 3=very verbose output
  --settings SETTINGS   The Python path to a settings module, e.g.
                        "myproject.settings.main". If this isn't provided, the
                        DJANGO_SETTINGS_MODULE environment variable will be
                        used.
  --pythonpath PYTHONPATH
                        A directory to add to the Python path, e.g.
                        "/home/djangoprojects/myproject".
  --traceback           Raise on CommandError exceptions
  --no-color            Don't colorize the command output.

(django-political-map) 20tab:django-political-map gabbo$ python manage.py refresh_data 2
Refresh data started.
Refreshing data for PoliticalPlace: 2 - Brisbane QLD, Australia
Refresh data completed successfully  for 1 items, 0 errors.

(django-political-map) 20tab:django-political-map gabbo$ python manage.py refresh_data 2 3 4
Refresh data started.
Refreshing data for PoliticalPlace: 2 - Brisbane QLD, Australia
Refreshing data for PoliticalPlace: 3 - Via Luigi Gastinelli, 118, 00132 Roma RM, Italy
Refreshing data for PoliticalPlace: 4 - US-3, United States
Refresh data completed successfully for 3 items, 0 errors.

(django-political-map) 20tab:django-political-map gabbo$ python manage.py refresh_data 2 3 4 -v 0
Refresh data started.
Refresh data completed successfully for 3 items, 0 errors.

(django-political-map) 20tab:django-political-map gabbo$ python manage.py refresh_data
Refresh data started.
Refreshing data for PoliticalPlace: 2 - Brisbane QLD, Australia
Refreshing data for PoliticalPlace: 3 - Via Luigi Gastinelli, 118, 00132 Roma RM, Italy
[...]
Refreshing data for PoliticalPlace: 28 - Čerpadlová 572/5, Vysočany, 190 00 Praha-Praha 9, Czechia
Refresh data completed successfully for 27 items, 0 errors.

Javascript Initialization

Django Political Map has full support for admin change_form with single PlaceField, multiple PlaceField on the same model and inline models with PlaceField.

The default widget will work on your custom frontend too (just remember to use {{forms.media}} in your template).

The library also supports django inline formsets via the formset:added event if using django.jQuery ("admin/js/vendor/jquery/jquery.js", "admin/js/jquery.init.js"), otherwise you can attach to your custom event the politicalplaces.addNewWidget(widgetDOMElement, formsetName) handler. Example:

document.querySelector('button.add-form').addEventListener('click', function() {
  var formsetName = 'the_name_of_the_formset';
  var widgetDOMElement = document.querySelector('.widget');
  politicalplaces.addNewWidget(widgetDOMElement, formsetName);
});

GMAPS quota limit

Using googlemaps as backend, remember there's a quota limit as described here: https://developers.google.com/maps/documentation/javascript/usage

Metadata

Release files for django-political-map 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-political-map 1.2.2
File Size Uploaded
django-political-map-1.2.2.tar.gz 51.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-political-map 1.2.2
File Interpreter ABI Platform
django_political_map-1.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 110.6 kB

Release files / django-political-map-1.2.2.tar.gz

Download URL django-political-map-1.2.2.tar.gz
Size 51.5 kB
Tags Source
SHA-256 checksum
How to use checksums
83280b19275a1e4396380342386ff0a5cd68d0711a22350ff463832dae48208f
BLAKE2b-256 checksum
How to use checksums
55d8f096a5fa639bc43ba553a51ba5e7077893b394b001ecb7f9384481e83b2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.1

Release files / django_political_map-1.2.2-py3-none-any.whl

Download URL django_political_map-1.2.2-py3-none-any.whl
Size 59.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
473299b08b0504180ede1e74bc4d7e56ede8e02fc5e4b1384383ee6d61ec4a99
BLAKE2b-256 checksum
How to use checksums
2f53c016f8d3edf72409eab080dca461964aab907bca9427556ee3b92df6fddf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.1

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 release files

1.2.1

2 release files

1.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page