Developers Guide

Note

Disclaimer: This guide was developed and tested on Ubuntu Linux. While the instructions should work on other operating systems, some commands, package names, or installation steps may differ. If you encounter issues on a different OS, please refer to the specific documentation for your platform or reach out to the community for assistance.

Installing QATrack+ For Development

Due to the huge volume of tutorials already written on developing software using Python, Django, and git, only a brief high level overview of getting started developing for the QATrack+ project will be given here. That said, there are lots of steps involved which can be intimidating to newcomers (especially git!). Try not to get discouraged and if you get stuck on anything or have questions about using git or contributing code then please post to the mailing list so we can help you out!

Prerequisites

QATrack+ is developed using Python 3.12. We recommend using the latest stable version of Python 3.12 for the best development experience and compatibility.

Git

QATrack+ uses the git version control system. While it is possible to download and modify QATrack+ without git, if you want to contribute code back to the QATrack+ project, or keep track of your changes, you will need to learn about git.

You can download and install git from https://git-scm.com. After you have git installed it is recommended you go through a git tutorial to learn about git branches, commiting code and pull requests. There are many tutorials available online including a tutorial by the Django team as well as a tutorial on GitHub.

GitHub Account

The QATrack+ project currently uses GitHub for hosting its source code repository. To contribute code to QATrack+ you will need to create a fork of QATrack+ on GitHub, make your changes, then make a pull request to the main QATrack+ project.

Creating a fork of QATrack+ is explained in the GitHub documentation.

uv Package Manager

The QATrack+ project uses uv, a fast Python package manager. uv handles Python version management, virtual environments, and dependency management.

Install uv using the official installer (recommended):

# On Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Alternative method using pip
pip install uv

For other installation methods or troubleshooting, see the full installation guide at https://docs.astral.sh/uv/getting-started/installation/

Setting up your development environment

First create a fork of the QATrack+ repository on GitHub.

Then clone your fork to your local machine:

git clone https://github.com/YOUR_USERNAME/qatrackplus.git

Creating a Virtual Environment

Once you have decided on a text editor or IDE, create a virtual environment with Python 3.12 using uv:

# Create virtual environment with Python 3.12
uv venv --python 3.12

# Activate the virtual environment:
source .venv/bin/activate

Install development dependencies:

# Install all development dependencies
uv sync --dev

Understanding the Settings Files

QATrack+ uses a layered approach to Django settings, with each file serving a specific purpose. Understanding this hierarchy will help you configure your development and testing environment.

Settings File Hierarchy (Highest to Lowest Precedence):

  1. `local_test_settings.py` - Your custom test environment overrides - Contains all essential development and test settings in one place - This is the main file you’ll customize for your testing needs

  2. `local_settings.py` - Your custom development environment overrides - Contains development-specific settings like database configuration

  3. `test_settings.py` - Default test environment settings - Contains test-specific defaults like password hashers and notification settings

  4. `settings.py` - Base Django application settings - Contains core Django configuration, installed apps, middleware, etc.

Creating your development database

Rather than using a full blown database server for development work, You can use Sqlite3 which is included with Python.

Once you have the requirements installed, copy the debug local_settings.py and local_test_settings.py files from the deploy subdirectory and then create your database:

cp deploy/dev/local_settings.dev.py qatrack/local_settings.py
cp deploy/dev/local_test_settings.dev.py qatrack/local_test_settings.py
mkdir db
python manage.py migrate

this will put a database called default.db in the db subdirectory.

Loading Default Data (Fixtures)

QATrack+ comes with pre-configured default data that provides a foundation for development and testing. This includes common QA categories, test frequencies, modalities, vendors, and other essential data structures.

To load the default data into your development database:

python manage.py loaddata fixtures/defaults/*/*

This command will populate your database all default data.

You can also load specific fixture categories individually if you only need certain data:

# Load only QA-related fixtures
python manage.py loaddata fixtures/defaults/qa/*

# Load only unit-related fixtures
python manage.py loaddata fixtures/defaults/units/*

# Load only service log fixtures
python manage.py loaddata fixtures/defaults/service_log/*

Generating Sample Data

The default fixtures give you an empty, correctly configured QATrack+. To get a database that actually looks like a working clinic — useful when developing a feature or reviewing someone else’s pull request — use the generate_sample_data command:

python manage.py generate_sample_data

This creates a small radiation oncology centre: two linacs and a CT simulator, TG-142 style daily and monthly test lists with per unit references and tolerances, 90 days of rolling QA history (including an unreviewed backlog and one in-progress session to resume), service events with return to service QA, faults, a parts inventory with a low stock item, and saved reports with email schedules.

Options:

--days N

How many days of rolling QA history to generate (default 90). Must be zero or greater. The service and fault records are placed at fixed offsets and are created regardless of this value.

--clear

Delete the existing units, QA, service log, fault, parts and report data before generating. You are asked to confirm first.

--no-input

Skip that confirmation, for scripted use.

Warning

--clear deletes all of that data in the database, not just rows a previous run created. Only use it on a development database.

The generator creates the following accounts to attribute the data to, all with the same password. It is defined as DEFAULT_SAMPLE_PASSWORD in qatrack/qatrack_core/sample_data/small.py — currently password123 — and is deliberately well known: these accounts exist so sample records have an author, and they belong only on a development database.

Username

Groups

admin

QA Administrators (superuser)

jane.physicist

Medical Physicists, QA Administrators

mark.physicist

Medical Physicists

alex.resident

Medical Physicists

sarah.therapist

Radiation Therapists

dave.engineer

Service Engineers

If one of those usernames already exists it is reused rather than replaced: the account keeps its own password (unless it has no usable one, in which case it is given the sample password so you can log in) and its existing groups, to which the groups above are added. --clear does not delete user accounts.

Running the command again without --clear extends the sample data rather than duplicating it — QA sessions, service events and reports that are already there are left alone. Any default fixtures the generator depends on are loaded automatically if their tables are empty, so a fresh database needs nothing but migrate.

Collect Static Files

Before running the development server, you need to collect all static files to the STATIC_ROOT directory:

python manage.py collectstatic

Running the development server

After the database is created, create a super user so you can log into QATrack+:

python manage.py createsuperuser

and then run the development server:

python manage.py runserver

Once the development server is running you should be able to visit http://127.0.0.1:8000/ in your browser and log into QATrack+.

Selecting an Editor or IDE

You can use a variety of tools to edit and work on the QATrack+ codebase. Some popular options include:

  • VS Code: A free, open-source editor with Python and Django support.

  • Cursor: An AI-powered code editor that integrates with GitHub Copilot and other AI tools.

  • PyCharm: A Python IDE with advanced Django support.

  • Vim/Neovim: Lightweight, keyboard-driven editors.

  • Emacs: Highly customizable editor.

Choose the editor or IDE that best fits your workflow. All you need is a text editor and a terminal to get started!

Node.js (not currently required)

QATrack+ had a Vue 3 frontend bundle compiled with Vite. The faults UI now uses server-rendered HTMX with jQuery, and package.json was removed along with the bundle, so Node.js is not a prerequisite for anything today.

A frontend build is expected to return no earlier than 4.1. Until then there is nothing to build, and npm commands will fail for want of a manifest (see Building the Frontend below).

Building the Frontend

There is nothing to build at present.

The Vue/Vite bundle was retired when the faults UI moved to server-rendered HTMX, and package.json went with it, so npm ci has no manifest to read. A replacement is expected no earlier than 4.1.

The release workflow builds the frontend only when a package.json is present, so it will resume on its own once one is - nothing here needs changing at that point.

Next Steps

Now that you have the development server running, you are ready to begin modifying the code! If you have never used Django before it is highly recommended that you go through the official Django tutorial which is an excellent introduction to writing Django applications.

Once you are happy with your modifications, commit them to your source code repository, push your changes back to your online repository and make a pull request! If those terms mean nothing to you…read a git tutorial!

QATrack+ Development Guidelines

The following lists some guidelines to keep in mind when developing for QATrack+.

Internationalization & Translation

Please mark all strings and templates in QATrack+ for translation. This will allow for QATrack+ to be made available in multiple languages. Note that translatable labels for form fields (i.e. my_form_field = FieldClass(label=_l(“the_label”), …)) and translatable verbose names for model fields (i.e. my_model_field = ModelClass(verbose_name=_l(“the_verbose_name”), …)) are often required for the rendering of translated strings in the frontend, so the recommendation, as stated in the Django docs, is to always include them.

For discussion of how to mark templates and strings for translation please read the Django docs on translation.

Adding a New Language to QATrack+

For detailed instructions on adding a new language to QATrack+, including step-by-step workflows and translation automation, please refer to the Add Language Tutorial in the tutorials section.

Tool Tips And User Hints

Where possible all links, buttons and other “actionable” items should have a tooltip (via a title attribute or using one of the bootstrap tool tip libraries) which provides a concise description of what clicking the item will do. For example:

<a class="..."
    title="Click this link to perform XYZ"
    href="..."
>
    Foo
</a>

Other areas where tooltips are very useful is e.g. badges and labels where wording is abbreviated for display. For example:

<i class="fa fa-badge" title="There are 7 widgets for review">7<i>

<span title="This X has Y and Z for T">Foo baz qux</span>

Formatting & Style Guide

General formatting

QATrack+ uses ruff for both linting and formatting, configured in pyproject.toml under [tool.ruff]. To check your code:

uv run ruff check .

Warning

Format only the files you changed. The repository has never been formatted as a whole, so ruff format . rewrites hundreds of files and buries your change:

uv run ruff format path/to/the/file/you/changed.py

uv run pre-commit run --all-files before opening a pull request runs what CI runs.

Note

Earlier versions of this guide described flake8, yapf and isort, and make flake8 / make yapf targets. None of those tools is installed any more and neither target exists; setup.cfg still carries their configuration sections, which are dead and will be removed separately.

Import Order

Imports in your Python code should be split in three sections:

  1. Standard library imports

  2. Third party imports

  3. QATrack+ specific imports

and each section should be in alphabetical order. For example:

import math
import re
import sys

from django.apps import apps
from django.conf import settings
from django.contrib.auth.models import Group, User
from django.contrib.contenttypes.fields import (
    GenericForeignKey,
    GenericRelation,
)
from django_comments.models import Comment
import matplotlib
from matplotlib.backends.backend_agg import FigureCanvasAgg
import numpy
import scipy

from qatrack.qa import utils
from qatrack.units.models import Unit

Import order is checked by ruff’s I rules, which are enabled in pyproject.toml. uv run ruff check --fix . sorts them, scoped to the files you changed as above.

Indentation

  • Python: 4 spaces.

  • Templates and other HTML - every .html file under a templates/ directory, which is where QATrack+’s templates live: 2 spaces.

  • JavaScript that QATrack+ owns: 4 spaces. Vendored libraries under static/ keep whatever their upstream uses; do not reformat them.

Match the file you are editing before you match this list. The existing code is not consistent - of 213 template files, 138 use 2 spaces and 58 use 4; of 88 JavaScript files that are ours rather than vendored, 52 use 4 and 25 use 2. A patch that reindents a file to follow this page is a patch whose diff hides its own change.

Using Make Commands

QATrack+ includes a Makefile with convenient shortcuts for common development tasks like running tests, formatting code, and building documentation. You can see all available commands by running:

make help

For detailed information about using make and understanding Makefiles, refer to the GNU Make Manual.

Running The Test Suite

Once you have QATrack+ and its dependencies installed (and optionally configured Selenium browser testing above), you can run the test suite from the root QATrack+ directory using the py.test command:

./qatrackplus> py.test
Test session starts (platform: linux, Python 3.6.5, pytest 3.5.0, pytest-sugar 0.9.1)
Django settings: qatrack.settings (from ini file)
rootdir: /home/dev/projects/qatrackplus, inifile: pytest.ini
plugins: django-4.5.2, cov-3.0.0

qatrack/accounts/tests.py ✓✓✓

Running Different Types of Tests

Run all tests (including Selenium):

py.test

Run only Selenium tests:

pytest -m selenium

Run only non-Selenium tests (faster):

pytest -m "not selenium"

For more information on using py.test, refer to the py.test documentation.

New code should come with tests covering as much of it as you can manage. You can measure coverage with:

make cover

Tip

Testing is not solely the author’s job. If you are not sure how to test a change, or cannot cover all of it, open the pull request anyway and say so - a maintainer can help with the tests. A contribution held back because its tests were hard is worth less to everyone than one that arrives and gets finished together.

Setting Up Selenium Browser Testing

QATrack+ includes Selenium tests that simulate user interactions with the web interface and are marked with the @pytest.mark.selenium decorator.

This setup should be completed before running the test suite if you want to see the Selenium tests in action.

Browser Requirements

You will need to have both a browser and its corresponding driver installed on your system:

  • Option 1. Firefox + geckodriver

  • Option 2. Chromium + chromedriver

If you are unsure whether or not you have both a browser and its corresponding driver installed, you can run the following commands to check:

Finding Browser and Driver Paths:

# Check for Firefox browser
which firefox

# Check for geckodriver
which geckodriver

# Check for Chromium browser
which chromium

# Check for chromedriver
which chromedriver

Example Output:

/usr/bin/firefox
/snap/bin/geckodriver
/snap/bin/chromium
/usr/bin/chromedriver

Installing Missing Components

If you do not have both firefox and geckodriver or both chromium and chromedriver, you can install either pair using the following commands:

# Option 1: Install Firefox and geckodriver
sudo apt install firefox geckodriver

# Option 2: Install Chromium and chromedriver
sudo apt install chromium-browser chromium-chromedriver

Manual Downloads (Alternative Installation)

If the package manager installation doesn’t work or you need a specific version, you can download the drivers manually:

After downloading, make the driver executable and verify the path.

Configuring Selenium Tests

You’ll need to configure your browser settings in two files. First, update the Selenium configuration in qatrack/settings.py:

# Selenium Browser Configuration
# Options: 'firefox', 'chromium'
SELENIUM_BROWSER = ''

# Browser Driver Paths
SELENIUM_FIREFOX_DRIVER_PATH = ''  # Path to geckodriver as shown above
SELENIUM_CHROMIUM_DRIVER_PATH = ''   # Path to chromedriver as shown above

# Leave this False in 4.0 - see the note below
SELENIUM_VIRTUAL_DISPLAY = False

Then also set SELENIUM_VIRTUAL_DISPLAY in qatrack/test_settings.py:

# In qatrack/test_settings.py:
SELENIUM_VIRTUAL_DISPLAY = False

Configuration Examples

Firefox with visible browser:

# In qatrack/settings.py:
SELENIUM_BROWSER = 'firefox'
SELENIUM_VIRTUAL_DISPLAY = False
SELENIUM_FIREFOX_DRIVER_PATH = '/snap/bin/geckodriver'

# In qatrack/test_settings.py:
SELENIUM_VIRTUAL_DISPLAY = False

Chromium with visible browser:

# In qatrack/settings.py:
SELENIUM_BROWSER = 'chromium'
SELENIUM_VIRTUAL_DISPLAY = False
SELENIUM_CHROMIUM_DRIVER_PATH = '/usr/bin/chromedriver'

# In qatrack/test_settings.py:
SELENIUM_VIRTUAL_DISPLAY = False

Note

Headless running in 4.0 needs a system package, and cannot work on Windows. It is being replaced properly in 4.1.

SELENIUM_VIRTUAL_DISPLAY = True does not mean the browser’s own headless mode. It means a virtual X display driven through xvfb, so the browser still renders into a real X server - just one with no screen attached. The Python wrapper, PyVirtualDisplay, is a declared dependency and arrives with uv sync; xvfb itself is a system package and does not. Without it, enabling the setting fails when the display is started, and nothing in the error names the missing package.

On Debian and Ubuntu:

sudo apt install xvfb

On Fedora or RHEL the package is xorg-x11-server-Xvfb.

On Windows there is no xvfb at all, so headless cannot be made to work. Leave SELENIUM_VIRTUAL_DISPLAY = False and let the browser be visible.

With xvfb installed, headless does work on Linux - the full browser suite passes - and it keeps the test browser off your desktop, which a visible run cannot. If you are on a Wayland session, note that it is the visible path that is the awkward one: Firefox with MOZ_ENABLE_WAYLAND=1 ignores DISPLAY and renders through the compositor, so window-geometry behaviour differs from X11.

4.1 removes this whole question. The browser’s own headless mode is used instead of a virtual display, so no display server is needed on any operating system, and headless becomes the default rather than something to configure.

Writing Documentation

As well as writing tests for your new code, it will be extremely helpful for you to include documenation for the features you have built. The documentation for QATrack+ is located in the docs/ folder and is seperated into the following sections:

  1. User guide: Documentation for normal users of the QATrack+ installation.

  2. Admin guide: Documentation for users of QATrack+ who are responsible for configuring and maintaining Test Lists, Units etc.

  3. Tutorials: Complete examples of how to make use of QATrack+ features.

  4. Install: Documentation for the people responsible for installing, upgrading, and otherwise maintaining the QATrack+ server.

  5. Developers guide: You are reading it :)

Please browse through the docs and decide where is the most appropriate place to document your new feature.

While writing documentation, you can view the documentation locally in your web browser (at http://127.0.0.1:8008) by running one of the following commands:

make docs-autobuild
# -or-
sphinx-autobuild docs docs/_build/html --port 8008

The documentation build treats warnings as errors, so a build that reports a warning fails. Run it the way CI does before you push:

rm -rf docs/_build
uv run sphinx-build -W --keep-going -a --fresh-env -b html docs docs/_build/html

Removing docs/_build matters. Sphinx caches what it has already parsed, and an incremental build does not repeat a warning it reported last time - so a warning you introduced can be invisible to you and fail for the next person.

Fragments, and the leading underscore

A page that would otherwise be written out three times - once per platform, say - can be factored into a fragment and pulled into each page with .. include::. docs/install/_upgrade_4_0_before.rst is one.

Name a fragment with a leading underscore, and add it to exclude_patterns in docs/conf.py. Both, because they do different jobs:

  • The underscore is for people. It says this file is not a page and is not meant to be read on its own. Sphinx attaches no meaning to it whatsoever - unlike Sass partials or Jekyll’s _includes, where the convention is enforced by the tool. The names _build, _static and _templates are special only because conf.py points at them.

  • exclude_patterns is what gives it effect, and it is worth knowing exactly what it prevents. Without it Sphinx reads the fragment as a document as well as including it. With a fragment that defines no labels - which is what docs/install/_upgrade_4_0_*.rst are today - the build still passes, and the only consequence is a published page duplicating content that already appears in three guides.

    The moment a fragment defines a label, that changes. Measured: adding one .. _label: to an un-excluded fragment produces three duplicate-label warnings, one for each page that includes it plus the fragment itself, and -W turns those into a failed build. So excluding a fragment is cheap insurance that becomes necessary the first time somebody writes a label in one, which is not a thing anyone will remember to check.

exclude_patterns matches **/_*.rst, so a new fragment named with the underscore is excluded without further work. Keep the convention anyway: the pattern is what makes the build pass, and the name is what tells the next person why the file exists.

Give a fragment a comment at the top saying which pages include it. A reader who opens it directly has no other way to find out, and git grep for the filename is a poor substitute for a sentence.

Version Naming Convention

QATrack+ uses Eff Ver (Effort Versioning) for its version naming convention. Eff Ver is a versioning strategy that focuses on the effort required to upgrade rather than semantic meaning. This approach prioritizes the practical impact on users and developers when considering version changes.

For more information about Eff Ver, see the Eff Ver documentation.

Version Number Structure

The version number follows the format X.Y.Z where:

  • X (Major): Corresponds to the Django LTS release version - Currently at 4.0.1 (Django 4.2 LTS) - When upgrading to Django 5.2 LTS, version will become 5.0.0 - This ensures compatibility and upgrade path alignment with Django

  • Y (Minor): Feature releases within the same Django LTS cycle

  • Z (Patch): Bug fixes and minor improvements

Examples: - 4.0.0: Initial release on Django 4.2 LTS - 4.0.1: Bug fix release on the same Django LTS - 4.1.0: Major feature release while staying on Django 4.2 LTS - 4.1.1: Bug fix release - 5.0.0: Upgrade to Django 5.2 LTS

I’m not a developer, how can I help out?

Not everyone has development experience or the desire to contribute code to QATrack+ but still wants to help the project out. Here are a couple of ways that you can contribute to the QATrack+ project without doing any software development:

  • Translations: QATrack+ supports multiple languages through its internationalization infrastructure. We welcome community contributions for translation files in different languages. Use the translation manager script to help automate translations, then refine them manually for accuracy. See the “Internationalization & Translation” section above for detailed commands.

  • Tutorials: Tutorials are a great way for newcomers to learn their way around QATrack+. If you have an idea for a tutorial, we would love to include it in our tutorials section!

  • Mailing List: QATrack+ has a mailing list which QATrack+ users and administrators may find useful for getting support and discussing bugs and/or features. Join the list and chime in!

  • Spread the word: The QATrack+ community has grown primarily through word of mouth. Please let others know about QATrack+ when discussing QA/QC software :)

  • Other: Have any ideas for acquiring development funding for the QATrack+ project? We’d love to hear them!