Skip to content

City-of-Helsinki/berth-reservations

Repository files navigation

Berth reservations

Version Continuous integration Coverage License

⛵ Bare-bones registration API for berth reservations ⛵

Contents

Development with Docker

  1. Copy .env.example to .env and modify it if needed.

  2. Run docker-compose up

  3. Run migrations if needed:

    • docker exec berth python manage.py migrate
  4. Create superuser if needed:

    • docker exec -it berth python manage.py createsuperuser

The project is now running at localhost:8081

Development without Docker

Project uses following software versions:

  • Postgres 11
  • Postgis 2.5
  • Python 3.9

Database

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;"

Install Geospatial libraries

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/

Daily running

  • Create .env file: touch .env
  • Set the DEBUG environment variable to 1.
  • Run python manage.py migrate
  • Run python manage.py runserver 0:8000

The project is now running at localhost:8000

Keeping Python requirements up to date

  1. Install pip-tools:

    • pip install pip-tools
  2. Add new packages to requirements.in or requirements-dev.in

  3. Update .txt file for the changed requirements file:

    • pip-compile requirements.in
    • pip-compile requirements-dev.in
  4. If you want to update dependencies to their newest versions, run:

    • pip-compile --upgrade requirements.in
  5. To install Python requirements run:

    • pip-sync requirements.txt

Code format

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.

Version control

Commits and pull requests

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

Releases

This project is following GitHub flow. Release notes can be found from GitHub tags/releases.

Running tests

pytest

In order to successfully run tests in applications/tests/test_applications_notifications.py you need to set env variable NOTIFICATIONS_ENABLED=1

Fixtures

Municipalities

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

Resources

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

Berth switch reasons

Load the fixtures with reasons for berth switch:

./manage.py loaddata switch-reasons.json

Stickers

Create WS sticker sequences:

./manage.py create_ws_lease_sticker_sequences

User groups and permissions

Load the User Groups:

./manage.py loaddata groups.json

And install the model permissions:

./manage.py set_group_model_permissions

Products

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