⛵ Bare-bones registration API for berth reservations ⛵
Contents
- Development with Docker
- Development without Docker
- Keeping Python requirements up to date
- Code format
- Version Control
- Running tests
- Fixtures
-
Copy
.env.example
to.env
and modify it if needed. -
Run
docker-compose up
-
Run migrations if needed:
docker exec berth python manage.py migrate
-
Create superuser if needed:
docker exec -it berth python manage.py createsuperuser
The project is now running at localhost:8081
Project uses following software versions:
- Postgres 11
- Postgis 2.5
- Python 3.9
To setup a database compatible with default database settings:
Create user and database
sudo -u postgres createuser -P -R -S berth_reservations # use password `berth_reservations`
sudo -u postgres createdb -O berth_reservations berth_reservations
Create extensions in the database
sudo -u postgres psql berth_reservations -c "CREATE EXTENSION postgis;"
Allow user to create test database
sudo -u postgres psql -c "ALTER USER berth_reservations CREATEDB;"
For Debian/Ubuntu:
apt-get install binutils libproj-dev gdal-bin
For more information, see https://docs.djangoproject.com/en/3.1/ref/contrib/gis/install/geolibs/
- Create
.env
file:touch .env
- Set the
DEBUG
environment variable to1
. - Run
python manage.py migrate
- Run
python manage.py runserver 0:8000
The project is now running at localhost:8000
-
Install
pip-tools
:pip install pip-tools
pip install --upgrade pip-tools
- Without this you'll probably get error
ImportError: cannot import name 'BAR_TYPES' from 'pip._internal.cli.progress_bars'
- Without this you'll probably get error
-
Add new packages to
requirements.in
orrequirements-dev.in
-
Update
.txt
file for the changed requirements file:pip-compile requirements.in
pip-compile requirements-dev.in
-
If you want to update dependencies to their newest versions, run:
pip-compile --upgrade requirements.in
-
To install Python requirements run:
pip-sync requirements.txt
This project uses black
for Python code formatting.
We follow the basic config, without any modifications. Basic black
commands:
- To let
black
do its magic:black .
- To see which files
black
would change:black --check .
The project also has pre-commit
setup with few hooks to avoid having "style fixing" commits.
To install it, run:
pre-commit install
This will setup three pre-commit hooks: black
, flake8
, and isort
.
We try to keep a clean git commit history. For that:
- Keep your commits as simple as possible
- Always rebase your PRs, don't merge the latest
master
into your branch - Don't be afraid to
push --force
once you have fixed your commits - Avoid using the GitHub merge/rebase buttons
This project is following GitHub flow. Release notes can be found from GitHub tags/releases.
pytest
In order to successfully run tests in applications/tests/test_applications_notifications.py
you need to set env variable NOTIFICATIONS_ENABLED=1
There are some fixtures available, that contain basic data about public
harbors and winter areas of the City of Helsinki. If you don't have divisions of Helsinki
imported yet through django-munigeo
,
import them first:
./manage.py geo_import finland --municipalities
./manage.py geo_import helsinki --divisions
Then load the fixtures with the following commands:
./manage.py loaddata helsinki-ws-resources.json
./manage.py loaddata helsinki-harbor-resources.json
./manage.py loaddata helsinki-harbor-resources-fixes-2021-06-11.json
And assign the corresponding region to areas:
./manage.py assign_area_regions
Point harbor and ws images to customer ui images:
./manage.py add_helsinki_harbors_images
./manage.py add_helsinki_winter_areas_images
Load the fixtures with reasons for berth switch:
./manage.py loaddata switch-reasons.json
Create WS sticker sequences:
./manage.py create_ws_lease_sticker_sequences
Load the User Groups:
./manage.py loaddata groups.json
And install the model permissions:
./manage.py set_group_model_permissions
There are fixtures for the pre-defined berth products. They are the products defined by the Boat Office, so they are the same for the production env.
./manage.py loaddata berth_products.json