mirror of
https://github.com/pretix/pretix.git
synced 2025-12-27 17:42:27 +00:00
78 lines
3.2 KiB
ReStructuredText
78 lines
3.2 KiB
ReStructuredText
.. highlight:: python
|
|
:linenothreshold: 5
|
|
|
|
Plugin basics
|
|
=============
|
|
|
|
It is possible to extend pretix with custom Python code using the official plugin
|
|
API. Every plugin has to be implemented as an independent Django 'app' living
|
|
either in an own python package either installed like any python module or in
|
|
the ``pretixplugins/`` directory of your pretix installation. A plugin may only
|
|
require two steps to install:
|
|
|
|
* Add it to the ``INSTALLED_APPS`` setting of Django in ``pretix/settings.py``
|
|
* Perform database migrations by using ``python manage.py migrate``
|
|
|
|
The communication between pretix and the plugins happens via Django's
|
|
`signal dispatcher`_ pattern. The core modules of pretix, ``pretixbase``,
|
|
``pretixcontrol`` and ``pretixpresale`` expose a number of signals which are documented
|
|
on the next pages.
|
|
|
|
.. _`pluginsetup`:
|
|
|
|
Creating a plugin
|
|
-----------------
|
|
|
|
To create a new plugin, create a new python package as a subpackage to ``pretixplugins``.
|
|
In order to do so, you can place your module into pretix's :file:`pretixplugins` folder *or
|
|
anywhere else in your python import path* inside a folder called ``pretixplugins``.
|
|
|
|
.. IMPORTANT::
|
|
This makes use of a design pattern called `namespace packages`_ which is only
|
|
implicitly available as of Python 3.4. As we aim to support Python 3.2 for a bit
|
|
longer, you **MUST** put **EXACLTY** the following content into ``pretixplugins/__init__.py``
|
|
if you create a new ``pretixplugins`` folder somewhere in your path::
|
|
|
|
from pkgutil import extend_path
|
|
__path__ = extend_path(__path__, __name__)
|
|
|
|
Otherwise it **will break** on Python 3.2 systems *depending on the python path's order*,
|
|
which is not tolerable behaviour. Also, even on Python 3.4 the test runner seems to have
|
|
problems without this workaround.
|
|
|
|
|
|
Inside your newly created folder, you'll probably need the three python modules ``__init__.py``,
|
|
``models.py`` and ``signals.py``, although this is up to you. You can take the following
|
|
example, taken from the time restriction module (see next chapter) as a template for your
|
|
``__init__.py`` module::
|
|
|
|
from django.apps import AppConfig
|
|
from django.utils.translation import ugettext_lazy as _
|
|
from pretixbase.plugins import PluginType
|
|
|
|
|
|
class TimeRestrictionApp(AppConfig):
|
|
name = 'pretixplugins.timerestriction'
|
|
verbose_name = _("Time restriction")
|
|
|
|
class TixlPluginMeta:
|
|
type = PluginType.RESTRICTION
|
|
name = _("Restriciton by time")
|
|
author = _("the pretix team")
|
|
version = '1.0.0'
|
|
description = _("This plugin adds the possibility to restrict the sale " +
|
|
"of a given item or variation to a certain timeframe " +
|
|
"or change its price during a certain period.")
|
|
|
|
def ready(self):
|
|
from . import signals # NOQA
|
|
|
|
default_app_config = 'pretixplugins.timerestriction.TimeRestrictionApp'
|
|
|
|
.. IMPORTANT::
|
|
You have to implement a ``TixlPluginMeta`` class like in the example to make your
|
|
plugin available to the users.
|
|
|
|
.. _signal dispatcher: https://docs.djangoproject.com/en/1.7/topics/signals/
|
|
.. _namespace packages: http://legacy.python.org/dev/peps/pep-0420/
|