Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/city-of-helsinki/berth-reservations

Registration API for berth reservations
https://github.com/city-of-helsinki/berth-reservations

django graphene-django graphql python

Last synced: about 1 month ago
JSON representation

Registration API for berth reservations

Awesome Lists containing this project

README

        

# Berth reservations

![Version](https://img.shields.io/github/v/release/City-of-Helsinki/berth-reservations?label=version&logo=github)
![Continuous integration](https://github.com/City-of-Helsinki/berth-reservations/workflows/Continuous%20integration/badge.svg)
![Coverage](https://codecov.io/gh/City-of-Helsinki/berth-reservations/branch/master/graph/badge.svg)
![License](https://img.shields.io/github/license/City-of-Helsinki/berth-reservations)

:boat: Bare-bones registration API for berth reservations :boat:

**Contents**

- [Development with Docker](#development-with-docker)
- [Development without Docker](#development-without-docker)
- [Database](#database)
- [Daily running](#daily-running)
- [Install geospatial libraries](#install-geospatial-libraries)
- [Keeping Python requirements up to date](#keeping-python-requirements-up-to-date)
- [Code format](#code-format)
- [Version Control](#version-control)
- [Commits and pull requests](#commits-and-pull-requests)
- [Releases](#releases)
- [Running tests](#running-tests)
- [Fixtures](#fixtures)
- [Municipalities](#municipalities)
- [Resources](#resources)
- [Berth switch reasons](#berth-switch-reasons)
- [Stickers](#stickers)
- [User groups and permissions](#user-groups-and-permissions)
- [Products](#products)

## 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](http://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](http://localhost:8000)

## Keeping Python requirements up to date

1. 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'`

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`](https://github.com/ambv/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`](https://pre-commit.com/) 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](https://guides.github.com/pdfs/githubflow-online.pdf).
Release notes can be found from [GitHub tags/releases](https://github.com/City-of-Helsinki/berth-reservations/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`](https://github.com/City-of-Helsinki/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