If you would like to contribute to the Civic Tech Index project, please see the issues and project management board in the repository for the React app which uses this Django app as its API backend.
This project uses Django with Django REST Framework. If you are not already familiar with Django, we suggest you work through the Django tutorial and the Django REST Framework tutorial to get familiar with the tools this project uses. (Don't spend too long on these; just use them to get a feel for Django development.)
This project can be run using Docker OR installed directly on your machine.
This project can be run locally using either Docker, Docker Compose or your local python. If you are running without docker please ensure that the right version of python is installed. We suggest using pyenv to manage multiple versions of python.
This repository contains a Dockerfile for building a container for running our
Django project - in dev and in AWS via FARGATE. To use Docker for development,
you will want to use the project's docker-compose.yaml
to also create a
Postgres database container, a volume for persisting your data, and a network
that allows your web container to talk to your database container.
- Install Docker
- Clone this repository
- Copy
config/.env.example
toconfig/.env
- Build and configure your docker container by running the following command:
docker-compose up -d --build
- Our
docker-compose.yaml
creates a volume for persisting the database information so you should only have to run the migrations, load the data, and create a superuser the first time you create your containers.init/setup-db.sh
- The site is now running at https://localhost:8888/
- Python 3.8
- Postgres 12 or greater
-
Install PostgreSQL if you haven't already.
-
Install Python 3.8. Try pyenv
-
Clone this repository
-
Create and activate a virtual environment
-
Install the packages
pip install -r requirements.txt
-
Set up a Postgres database and user for this application. Instructions
-
Copy
config/.env.example
toconfig/.env
and edit to provide the database credentials your project will use. The contents of your .env file should provide the following information ( do not use the default values in the example ):POSTGRES_NAME='<YOUR_DATABASE_NAME>' POSTGRES_PASSWORD='<YOUR_PASSWORD>' POSTGRES_USER='<YOUR_POSTGRES_USERNAME>' POSTGRES_HOST='localhost'
-
Execute the following steps to load the environment variables from above and set up your database. You should only need to do these steps the first time you create a new database.
source config/.env python manage.py migrate python manage.py createsuperuser python manage.py loaddata init/organizations.json pytest
If tests fail please reach out out to the team on the Slack Channel.
-
Start your web server in the foreground:
source config/.env python manage.py runserver
-
The site is now running at https://localhost:8000/
- Django Administration Page: Docker or Local
- Swagger Docs: Docker or Local
- OpenAPI Docs: Docker or Local
If you are running this project using Docker, log into the docker container: docker exec -ti cti-web /bin/bash
From the root of the project, run the tests: pytest
To run tests and see the coverage report run: pytest --cov=civictechindexadmin