Skip to content
Danang Rahmatullah edited this page Jul 20, 2020 · 2 revisions

Pretix

Pretix is the chosen ticketing software for the Cosmos website. It is a Django instance separate from the actual website and hence require its own set of steps to get everything fully running.

Structure of API

Pretix has a REST API connecting users to the insides of the software. It consists of resources which structures how objects are organized in the system. The main resources we will be using are as follows:

Resource Usage Example
Organizer Current board year Cosmos 2020-2021
Team Committees Website committee
Event Event Potluck
Order Tickets ordered Potluck ticket

Each resource has been encapsulated in its own file with references to the Pretix documentation. Every single resource above can be created via a HTTP request with exception of the Organizer which requires one to access the Pretix Dashboard to make a new Organizer account. The admin of the server must also add their choice of payment option when installing the Pretix instance via Global settings > Settings. At the time of writing, Cosmos will be using either Mollie or Stripe. TODO decide on one.

Outside of the Pretix Dashboard, developers should only need to add onto the cosmos/event/user.py file to add functionality with Pretix or add a new resource class which extends cosmos.event.base.PretixService. Events are stored inside a single instance of Team (in our case, committees). In order to create an event, the developer must ensure that the client has a token with sufficient rights to Pretix. This is done by generating a Token (inside of cosmos.event.team.Token). Please refer to the Pretix documentation for more information.

Dependencies

  • cron - periodic task manager
  • MariaDB 10.2.7+, latest 10.4.13 - database (Assumed to be installed from installing Django instance for server)
  • nginx - HTTP(S) reverse proxy (Setup steps to be added)
  • redis - caching, only for development, remove in production

Setup

Based on the following tutorial: link

  1. Install dependencies
  • MariaDB
# Arch Linux
sudo pacman -S mariadb

# Debian/Ubuntu
sudo apt install mariadb-server
sudo mysql_secure_installation
  • Redis
# Arch Linux
yay -S redis
# Debian/Ubuntu
sudo apt update
sudo apt install redis-server
sudo systemctl enable redis
sudo systemctl start redis
  1. Create new unprivileged user:
# Arch Linux
useradd pretix --home /var/pretix
# Debian/Ubuntu
adduser pretix --disabled-password --home /var/pretix
  1. Create a database and database user
mysql -u root -p
CREATE USER pretix_tester@localhost IDENTIFIED BY '2020123';
CREATE DATABASE pretix DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON pretix.* TO pretix_tester@localhost;
  1. Pretix configuration as root
# Run all the following as root!
sudo su
mkdir /etc/pretix
cp pretix.cfg /etc/pretix/pretix.cfg
chown -R pretix:pretix /etc/pretix/
chmod 0600 /etc/pretix/pretix.cfg
  1. Pretix configuration as pretix user
# Change user to pretix
sudo su pretix
# Setup Python environment
python3 -m venv /var/pretix/venv
source /var/pretix/venv/bin/activate
pip3 install -U pip setuptools wheel
pip install "pretix[mysql]" pretix-mollie gunicorn

### Setup pretix ###
# Create data directory
mkdir -p /var/pretix/data/media
# Compile static files, translation data and create database structure
# Re-run when installing a new plugin!
python -m pretix migrate
python -m pretix rebuild
  1. Start pretix as a service
# Run all the following as root!
sudo su
cp pretix-web.service /etc/systemd/system/pretix-web.service
cp pretix-worker.service /etc/systemd/system/pretix-worker.service
systemctl daemon-reload
systemctl enable pretix-web pretix-worker
systemctl start pretix-web pretix-worker
  1. Login to pretix via localhost:8345
default username: admin@localhost
default password: admin
  1. Configure pretix via the web interface. Refer to "Structure of API" above.
Clone this wiki locally