/backend

Backend of the glef1x.dev website

Primary LanguagePython

Django project

This project is bootstrapped using fandsdev/django template. Drop a line if you have some issues.

Project structure

The main django app is called app. It contains .env file for django-environ. For examples see src/app/.env.ci. Here are some usefull app-wide tools:

  • app.admin — app-wide django-admin customizations (empty yet), check out usage examples
  • app.test.api_client (available as api and anon fixtures within pytest) — a convinient DRF test client.

Django user model is located in the separate users app.

Also, feel free to add as much django apps as you want.

Installing on a local machine

This project requires python 3.10. Deps are managed by pip-tools

Install requirements:

$ pip install --upgrade pip pip-tools
$ make

Run the server:

$ cd src && cp app/.env.ci app/.env  # default environment variables
$ ./manage.py migrate
$ ./manage.py createsuperuser
$ ./manage.py runserver

Testing:

# run lint
$ make lint

# run unit tests
$ make test

Development servers:

# run django dev server
$ ./manage.py runserver

Backend Code requirements

Style

  • Obey django's style guide.
  • Configure your IDE to use flake8 for checking your python code. To run our linters manualy, do make lint
  • Prefer English over your native language in comments and commit messages.
  • Commit messages should contain the unique id of issue they are linked to (refs #100500)
  • Every model, service and model method should have a docstring.

Code organisation

  • KISS and DRY.
  • Obey django best practices.
  • No logic is allowed within the views or serializers. Only services and models. When a model grows beyond 500 lines of code — go create some services.
  • Use PEP-484 type hints when possible.
  • Prefer composition over inheritance.
  • Never use signals or GenericRelations in your own code.
  • No l10n is allowed in python code, use django translation.