This tool is used to manage the student representative website at https://myhpi.de. It is a CMS based on Wagtail/Django and adds several functionalities like polls.
For a quick start, use the dev container, e.g. by installing the Dev Containers extension in Visual Studio Code or using the built-in feature in JetBrains IDEs. This automatically installs all dependencies in a container. After starting the container, setup your local data by following the Manual Setup from step 9 (creating a superuser).
To set up a development version on your local machine, you need to execute the following steps:
- Check out repository and cd to it
- Set up a virtualenv for the project with Python >=3.11 and activate it (e.g.,
python3 -m venv venvandsource venv/bin/activate) - Install poetry (if not already installed):
curl -sSL https://install.python-poetry.org/ | python - - Install dependencies with
poetry install - Create env file by copying the
.env.examplefile to.env, e.g.cp .env.example .env(Notice that for some functionality like OIDC some settings must be changed) - Migrate the database with
python manage.py migrate - Install bootstrap with
python tools/install_bootstrap.py - Optionally: Compile translations with
python manage.py compilemessages -i venv(does not work on Windows, recommended to skip this step or see docs) - Optionally: Create test data with
python manage.py create_test_data - Create a local superuser with
python manage.py createsuperuser - Start the development server with
python manage.py runserver - Open your web browser, visit
http://localhost:8000/admin/and log in with the user you just created
Test the code with python manage.py test myhpi.tests.
We recommend installing a pre-commit hook with pre-commit install. The hook will do the following steps before every commit:
- run
autoflakewith a couple of flags to remove unused imports, - run
isort .to sort imports, - run
black .to format the python code - run
djlint-reformat-django --quietanddjlint-djangoto format and lint template files (html) according to thepyproject.tomlconfiguration - run
prettier-eslint --write --list-differentto format the JavaScript code, (S)CSS, Markdown and YAML files according to the.prettierrcconfiguration
If you want to do that manually, run pre-commit run --all-files. Next to that, we also run pylint myhpi to check for semantic issues in the code.
To get optional linting-related warnings within your IDE and format files when saving them, follow these steps:
- Install IDE plugins
- black (IDE integrations)
- djLint (VSCode Marketplace)
- Prettier (IDE integrations)
- Set configuration
- Linting and formatting are already configured by the
.prettierrcandpyproject.tmlfiles which are also used by the pre-commit hook - You still have to write IDE-specific configuration to e.g. enable formatting on save and assign file types to the correct plugin
- Find configuration examples for IDEs below
- Linting and formatting are already configured by the
Workspace settings:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "ms-python.black-formatter",
"[javascript][css][scss][markdown][yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "monosans.djlint"
},
}
- To create translations: Run
python manage.py makemessages -l de -i venv. Fill in the translations indjango.po. Apply changes by runningpython manage.py compilemessages -i venv.
- Delete
db.sqlite3 - Conduct development setup steps 7+