This repository implements the API for the Tanzanian Mesh Hernia Registry.
These instructions will get you a copy of the project up and running.
A step by step series of examples that tell you how to get a development env running.
For local development, we use Docker Compose.
First install the prerequisite software:
- Install Docker and Docker Compose.
- Install Python 3 and pip.
If you want to run outside of Docker you will also need to:
- Install PostgreSQL, even if you are not runninga local database this is required for
psycopg2
, the PostgreSQL database adapter for Python, to correctly install when youmake dep
.
If you are on Windows and not Linux (or other *nix) you will also need to have installed:
- MSYS or an alternative set of Unix compatible tools that includes
make
. - Microsoft C++ Build Tools which are required to install some of the Python Django dependencies.
Create a virtual environment for this project.
If you are using pyenv:
pyenv virtualenv registry-api
pyenv activate registry-api
Or if you prefer to use virtualenv directly without pyenv:
# Linux
$ virtualenv venv
$ activate venv
# Windows
> virtualenv venv
> .\venv\Scripts\activate
Run before committing/pushing:
./checkInCheck.sh
Install project dependencies:
make dep
Spin up the project:
make run
Run migrations (every time you update Django models):
make migrate
Run tests:
make test
Run one test:
make test-one file=tmh_registry/registry/tests/api/viewsets/test_discharges.py test_name=TestDischargeCreate
Run checks before committing:
make pre-commit
Everything you need for this project is under Makefile. Take a look at the commands by running make
.
Before you can login to the registry you will need to create an account via. the local Django admin console:
- Go ot the admin console on http://localhost:8000/admin/ or from Containers in Docker Desktop
- Enter the username and password from
.envs/.local/.django
- Create a new user
Set Up Docker(detailed guide):
- Go to
File
->Settings
->Build, Execution, Deployment
->Docker
- Press the
+
button to create a Docker configuration if one does not already exist. - Connect to Docker Daemon with your preferred setting and make sure you see a "Connection successful" message.
Set up remote interpreter with Docker-Compose(detailed guide):
- Go to
File
->Settings
->Project: registry-api
->Python Interpreter
. - In the upper right corner, click the cog icon and select
Add..
. - In the
Configuration file
option, choose thelocal.yml
file. - In the
Service
option, choosetmh_registry_local_django
. - Click
OK
.
Set up Django Server(detailed guide):
- Go to
Run
->Edit Configurations
. - Press the
+
button and chooseDjango Server
. - Change the host to
0.0.0.0
. - Choose the Python Interpreter you created in the previous step.
- Click
OK
.
This project follows Semantic Versioning for releases.
Feel free to use any commit messages you like in the PR. However, please always squash and merge the PR with commit messages that follow the Conventional Commits specification.
From within the Docker Terminal execute psql -d tmh_registry -U admin
to get a local psql session.
Generating migration files with the make migrate
command, results in files which have the root
account as their
owner. In order to be able to run pre-commit on them and commit them, you need to change the owner to your user:
sudo chown <your_user>:<your_user> <migration_file>