/itdagene

API and admin interface for itdagene.no & admin.itdagene.no

Primary LanguagePythonMIT LicenseMIT

itDAGENE CircleCI

API and admin interface for itdagene.no & admin.itdagene.no

GraphQL API

https://itdagene.no/graphql

TL;DR

  • GraphQL API with django-graphene
  • Python 3.7 with Django
  • Postgres for persistant storage
  • Celery (with redis-broker) for async tasks
  • CircleCI for continuous integration
  • yarn for admin panel

Setup

First make sure that you have the following software installed on your system:

Setup python environment

$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -r requirements/dev.txt
$ echo "from itdagene.settings.dev import *" > itdagene/settings/local.py
$ docker-compose up -d # This starts the database & redis

Install and build frontend dependencies:

$ yarn
$ yarn build

Starting the app

$ docker-compose up -d
$ source venv/bin/activate
$ python manage.py runserver

Migrations

In order to setup a new dev environment you have to create a superuser. Every time there are new migrations, you have to apply them. If you don't, the runserver command will give you a warning.

$ python manage.py migrate
$ python manage.py createsuperuser

After creating the superuser, navigate to localhost:8000/superadmin and log in. You can now use the admin page at localhost:8000/admin.

Model changes

Have you changed a model? Then you have to make and apply migrations. Migrations should always be committed to the repo in the same commit/PR as the model change.

$ python manage.py makemigrations
$ python manage.py migrate

i18n

To update translations change them in this file and then run

$ python manage.py compilemessages

If you have added new messages or changed them in code please run

$ python manage.py makemessages -l nb --ignore venv

to update the .po file first.

Testing

In order to execute the tests, you have to install tox. The tests are always run in the continuous integration server, and no code that doesn't pass all the tests (including linting) should not be merged into the master branch.

$ pip install tox
$ tox

Code style

We enforce the style guide PEP 8 with flake8, and isort for import sorting. black is used for code formatting.

$ isort itdagene                    # Fix isort errors
$ black itdagene                    # Fix code formatting
$ tox -e isort -e flake8 -e black   # Verify code style

$ make fixme # Fix all formatting

Celery

$ celery worker -A itdagene # worker
$ celery beat -A itdagene   # beat
$ celery flower -A itdagene --address="127.0.0.1" --port=5555 # flower

Misc

Nice reads