Apartment application service
-
Copy the contents of .env.example to .env and modify it if needed.
-
Run docker-compose up
The project is now running at localhost:8081
Prerequisites:
- PostgreSQL 12
- Python 3.8
- Pip 24.2
- Run
pip install -r requirements.txt - Run
pip install -r requirements-dev.txt(development requirements)
To setup a database compatible with default database settings:
Create user and database
sudo -u postgres createuser -P -R -S apartment-application # use password `apartment-application`
sudo -u postgres createdb -O apartment-application apartment-application
Allow user to create test database
sudo -u postgres psql -c 'ALTER USER "apartment-application" CREATEDB;'
Some model fields are encrypted using pgcrypto, which requires a PGP keypair.
For instructions on how to generate the keys, see the
pgcrypto documentation:
Use the PostgreSQL preferred key type ("DSA and Elgamal") and at least 2048 bits as the key size.
To convert the multi-line PEM key into a single line (for .env), you can use this snippet:
cat your-key-file | awk '{print}' ORS='\\n'
For local development, you can use the example keys in .env.example.
Do not use these example keys in production!
- Create
.envfile:touch .env - Set the
DEBUGenvironment variable to1. - Run
python manage.py migrate - Run
python manage.py runserver 0:8081
The project is now running at localhost:8081
If you have the make command available, you can use the following commands to run certain common tasks:
make check- Run all checks (linting, Django checks, tests)make lint- Run linters (flake8, black, isort)make test- Run testsmake fix- Run code formmitng fixes (isort, black)make requirements- Update all requirements*.txtfiles from their corresponding*.infilesmake deploy- Run the deployment tasks (migrate, compilemessages, collectstatic)
This project uses pip-tools
to manage the Python requirements. It works with two kind of files:
*.in and *.txt. The *.in files are the source files, which list
the directly required packages and their version constraints. The
*.txt files are generated from the *.in files and they list the
exact versions of the packages that are installed.
-
pip-toolsis installed fromrequirements-dev.txt:pip install -r requirements-dev.txt
-
Add new packages to
requirements.inorrequirements-dev.in -
Update
.txtfile for the changed requirements file:pip-compile requirements.inpip-compile requirements-dev.in- There is also a Makefile target for updating all requirement
files:
make requirements
-
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,
flake8 and
isort
for code formatting and quality checking. Project follows the basic
black config, without any modifications.
Basic black commands:
- To let
blackdo its magic:black . - To see which files
blackwould change:black --check .
There is also make lint and make fix commands for code style
checking and fixing.
For Django, this project mostly follows the styleguide defined in Django-Styleguide.
To be able to send installments to SAP, the following settings need to be set:
SAP_SFTP_SEND_USERNAME
SAP_SFTP_SEND_PASSWORD
SAP_SFTP_SEND_HOST
SAP_SFTP_SEND_PORT
Also,
python manage.py send_installments_to_sap
needs to be run periodically.
For fetching payments from SAP, the following settings need to be set:
SAP_SFTP_FETCH_USERNAME
SAP_SFTP_FETCH_PASSWORD
SAP_SFTP_FETCH_HOST
SAP_SFTP_FETCH_PORT
Also,
python manage.py fetch_payments_from_sap
needs to be run periodically.
You may also use variables named SAP_SFTP_USERNAME,
SAP_SFTP_PASSWORD, SAP_SFTP_HOST and SAP_SFTP_PORT to set default
values for the corresponding send/fetch settings.
There are also two other management commands, which should not be needed for normal usage, but can be useful for testing purposes and exceptional situations:
- Generating an XML file of given installments
python manage.py create_sap_xml [reference numbers]
- Sending an XML file to the SAP SFTP server
python manage.py send_sap_xml <filename>
There are few commands that are needed to be run periodically to get full functionality of some features. The easiest way to do this should be using cron.
-
to get SAP invoices actually sent to the SFTP server
python manage.py send_pending_installments_to_saponce a day during night at some point.
-
to get reservation states updated based on expired offers
python manage.py update_reservations_based_on_offer_expirationonce a day as close to midnight as possible, but must be after it.