A Django-powered interface for newsroom data at the Star Tribune. Used for internal purposes.
Data management happens through the Django Admin, which is at /admin/
.
An API has been exposed for each model. Each request requires a username
and api-key
.
/api/v01/company_details/
: Custom endpoint for Companies and their connected records. Note that these are slow endpoints./api/v01/company_details/?coid=1234&limit=100&username=XXXXXX&api_key=XXXXXX
- Use the custom filter
finance_publishyear
to get companies that have a Finance record for that year. For example:/api/v01/company_details/?finance_publishyear=2018&limit=100&username=XXXXXX&api_key=XXXXXX
- Use the custom filter
nonprofit_finance_publishyear
to get companies that have a Finance record for that year. For example:/api/v01/company_details/?nonprofit_finance_publishyear=2017&limit=10&username=XXXXXX&api_key=XXXXXX
Note that you can use Docker for local development as well; see section below.
- Python 3.6+
- pipenv
brew install pipenv
- Or
pip install pipenv --user
Settings that are unique to the environment are managed with environment variables. You can manage these how you want, or you can use a .env
file. The following variables are required or suggested to be set.
DEBUG
:True
orFalse
, defaults to false.- Have run into issues where the Debug Toolbar slows down the page significantly, so this is a separate
DEBUG_TOOLBAR
variable.
- Have run into issues where the Debug Toolbar slows down the page significantly, so this is a separate
SECRET_KEY
: Random, unique stringDEFAULT_DB_URI
: Databsase URI for the default database that manages users, something likedatabase-type://user:pass@host:port/database-name
, defaults to a local SQLite file.- If using the Docker deployment, it includes a Postgres instance and sets this variable to that.
DATADROP_BUSINESS_DB_URI
: Databsase URI for the business companies database, something likemysql://user:pass@host:3306/database-name
- If using the Docker deployment locally, you can refer to your local host with:
host.docker.internal
- If using the Docker deployment locally, you can refer to your local host with:
TIME_ZONE
: Defaults toAmerica/Chicago
STATIC_ROOT
: Defaults to localstatic-assets/
directory.
pipenv shell
pipenv install
python manage.py migrate && python manage.py migrate --database=datadrop_business
- For first time setup, create an admin user:
python manage.py createsuperuser
python manage.py collectstatic
python manage.py runserver
- This will start a webserver at localhost:8000.
For each dataset, we make a new Django "app". For instance, say we have a campaign finance database that we want to hook up.
python manage.py startapp campaign_finance
- Creates a new directory for the app with some basics
- Create models based on the database and all the tables in it
python manage.py inspectdb --database="campaign_finance_db" > campaign_finance/models.py
- You can add options to
inspectdb
to only get specific tables.
- ...
Deployment is managed with Docker.
- Install Docker on your system.
- Install `docker-compose`` on your system.
See settings above. Suggested to use a .env
file.
docker-compose up -d
- Note that this command will end quickly, but it will take a moment for the services to be available.
Some helpful commands
- To see what is running:
docker ps
- To see what images are available:
docker-compose images
- To manually shut down:
docker-compose down
- To rebuild image:
docker-compose build --no-cache
To create the first admin user, you will need to connect to the Docker image.
docker-compose run web python manage.py createsuperuser