Django app to manage data for the 'Homes for Ukraine' scheme.
- Quickstart
- Database management and seed data
- Linting formatting and tests
- Docker and containerisation
- User management
- Troubleshooting
- Extra documentation / guides
For general development, the instructions below are sufficient for running the app. Refer to other sections of this README for more detailed information.
- Python >= 3.13 (https://www.python.org/downloads/)
- Poetry (https://python-poetry.org/)
- Docker (https://docs.docker.com/get-started/get-docker/)
- Docker compose (https://docs.docker.com/compose/install/)
poetry installcp .env.dev .envSet DB_HOST=localhost
docker compose up -d databasepoetry run dev5. Access at http://localhost:8000
cp .env.dev .envdocker compose up
# Hint: If you need to run any command:
docker compose run web python manage.py3. Access at http://localhost:8010
These instructions will get the app running. You may also want to seed the database. See seed data.
# Local development
python manage.py flush
# Force delete the db
docker compose down
docker volume rm hfu-case-management-webapp_postgres_data
docker compose upWe use Django 'fixtures' to handle our seed data.
Seeding using the seeder script
poetry run seed-dbpython manage.py dumpdata --exclude auth.permission --exclude contenttypes --exclude admin.logentry > db.jsonWe use LocalStack in our docker-compose setup to emulate AWS services locally. This allows you to develop and test AWS integrations (like S3) without connecting to real AWS services.
For unit and integration tests, we use moto to mock AWS services.
The S3TestCaseMixin class in webapp/tests/test_s3.py sets up a mocked S3 environment for your tests. If your test needs to test AWS features, just inherit from the S3TestCaseMixin class.
LocalStack automatically starts when you run:
docker compose up localstackIf you want to run both the database and localstack:
docker compose up database localstackOn start up localstack will run the bash script from hfurb_scripts/localstack-script.sh.
This creates a bucket with four files inside.
The database seeder creates UAM records that reference these LocalStack files as attachments. This means UAM download functionality works immediately after running the seeder - no additional setup required.
If you run the web app outside Docker and want to use the LocalStack S3 service, make sure your environment variables in the .env file are set for the AWS region, S3 bucket name and LocalStack AWS endpoint.
Note: LocalStack is only required if you need upload and download functionality for files in UAMs, Interactions, and Comments. Without LocalStack, file features will be missing in the app.
poetry run lintpoetry run formatNote: this requires the database container to be up and running
poetry run test
poetry run test-parallel
poetry run test-parallel uams.tests.test_detail_filesIf you've added a new pre-commit hook or the currently installed ones aren't running, you can try running
poetry run pre-commit installand if you've added a new one, run it against all the files (pre-commit will only run on the changed files during git hooks)
poetry run pre-commit run --all-filesIncluded in this repository is a Dockerfile.local for building an image to run the django web app. There is also a docker compose file that runs the aforementioned image along with nginx to serve static files and proxy requests along with a postgres database.
Docker volumes are used to store the database data and so will persist between container runs.
Before you run docker compose up, copy .env.dev to .env
If you're developing the webapp locally you'll need a postgres database running for it to connect to. You can run one via
docker compose up -d databaseRun
docker compose buildYou can apply the migrations from your local changes to the postgres database by running
python manage.py makemigrations
python manage.py migrateYou can apply the migrations in the web docker image to the postgres database running in docker by running
docker compose run web python manage.py makemigrations
docker compose run web python manage.py migrateThe docker-compose.yaml contains a configuration of running the app using gunicorn to serve the app behind nginx which proxies the requests and serves the static files. A postgres database is also run.
Build the images
docker compose buildRun the app
docker compose upAccess at http://localhost:8010
This app uses the built-in Django user system.
poetry run python manage.py createsuperuser --username=joe --email=joe@example.comUse the admin interface while logged in as superuser.
Django includes a built-in admin site at localhost:8000/admin (if running with Poetry) or localhost:8010/admin (if running with Docker). You'll need to create a super user account to be able to access it, see creating a super user.
If you encounter issues resolving the static files in the template files while using Pycharm, ensure you have marked the template folder as a 'template folder' and static as a 'Resource root', and importantly that the settings file in Settings/Languages & Frameworks/Django is set to caseManagement/settings.py
First stop any running containers,
docker compose downthen, try deleting the static_volume volume with
docker volume rm static_volumefinally, re-build the images
docker compose buildIf you get an error about having the incorrect python version, try using pyenv to install a supported version.
We are not accepting external contributions for this repository.
If you are a security researcher and have discovered a vulnerability in this code, we appreciate your help in disclosing it to us in a responsible manner. Please refer to MHCLG's vulnerability disclosure policy for details.