openpolis/django-popolo insteadDEPRECATED - Please consider using
NOTE: Development on PopIt has stopped and it is no longer being maintained. Please read the announcement to find out more.
PopIt Django App
A Django app that makes it easy to locally store and use data from one or more PopIt API instances.
What is PopIt and PopIt-API?
PopIt is a project from mySociety that aims to make it really simple to store and share data on people such as politicians, organisations such as parliaments and political parties, and the posts and memberships that link the people to the organisations.
The PopIt-API is a self standing server that provides a HTTP REST API to read and write this data. It is a separate codebase to this one.
This Django app lets you fetch data from several PopIt-APIs and store it locally in your Django project so that you can use all the power of the Django ORM to query the data. There are also management commands that make it easy to fetch the latest updates from the PopIt-API.
It will also let you store your own data in the same models so that you can add to the data from the PopIt-APIs. In time it should be possible to push this local data out to a PopIt-API so that it is easy for others to reuse.
WARNING - Alpha code
This is alpha code and subject to frequent and backwards incompatible change. Feel free to experiment but do not use in production until this message is removed.
This code is a work in progress - it is probably not useful to you yet. Please
IDEAS.md file for possible future additions and the current
issues for more
immediately planned work.
Installing and configuring
popit-django from PyPI. You should also add it to your
pip install popit-django --use-mirrors
popit to your
uses South to manage database migrations so make sure it comes first).
INSTALLED_APPS = [ # ... 'south', 'popit', # .... ]
Setup the database:
python manage.py syncdb python manage.py migrate
Now create a
popit.models.ApiInstance entry and fetch all the documents from that API instance:
python manage.py popit_retrieve_all
For some of the referential integrity we use a
UNIQUE INDEX to prevent
duplicates on values that are
NOT NULL. This is known to work with Postgres
and SQLite, but other databases may have issues. See the
popit/fields.py for more details.
If you want to contribute to the development of
popit-django that would be
great, we aim to be responsive to pull requests. These instructions should get
you a dev environment set up.
To run the tests you'll need a local PopIt-API instance that can be deleted.
This will be installed for you by the
start_local_popit_api.bash script, but
it requires the following:
- MongoDB for the PopIt-API instance. Should
allow anonymous access and db creation (the default).
- Node.js installed.
# get the code (you might want to clone your fork instead) git clone https://github.com/mysociety/popit-django.git cd popit-django # Set up virtual environment virtualenv --no-site-packages .venv . .venv/bin/activate # Install the python dependencies pip install -r requirements.txt --use-mirrors # Install (if needed) and start the popit-api server ./start_local_popit_api.bash # Run the tests ./manage.py test popit