Added signals that allow to modify the voucher form

This commit is contained in:
Raphael Michel
2016-07-03 16:49:56 +02:00
parent 1e4e1578f7
commit 35a9ab8f62
4 changed files with 41 additions and 2 deletions

View File

@@ -43,6 +43,9 @@ Voucher system
.. automodule:: pretix.presale.signals .. automodule:: pretix.presale.signals
:members: voucher_redeem_info :members: voucher_redeem_info
.. automodule:: pretix.control.signals
:members: voucher_form_class, voucher_form_html
Dashboards Dashboards
---------- ----------

View File

@@ -73,3 +73,24 @@ should return a list of dictionaries, where each dictionary can have the keys:
This is a regular django signal (no pretix event signal). This is a regular django signal (no pretix event signal).
""" """
voucher_form_html = EventPluginSignal(
providing_args=['form']
)
"""
This signal allows you to add additional HTML to the form that is used for modifying vouchers.
You receive the form object in the ``form`` keyword argument.
As with all plugin signals, the ``sender`` keyword argument will contain the event.
"""
voucher_form_class = EventPluginSignal(
providing_args=['cls']
)
"""
This signal allows you to replace the form class that is used for modifying vouchers.
You will receive the default form class (or the class set by a previous plugin) in the
``cls`` argument such that you can inherit from it.
As with all plugin signals, the ``sender`` keyword argument will contain the event.
"""

View File

@@ -1,6 +1,7 @@
{% extends "pretixcontrol/items/base.html" %} {% extends "pretixcontrol/items/base.html" %}
{% load i18n %} {% load i18n %}
{% load bootstrap3 %} {% load bootstrap3 %}
{% load eventsignal %}
{% block title %}{% trans "Voucher" %}{% endblock %} {% block title %}{% trans "Voucher" %}{% endblock %}
{% block inside %} {% block inside %}
<h1>{% trans "Voucher" %}</h1> <h1>{% trans "Voucher" %}</h1>
@@ -36,6 +37,7 @@
{% bootstrap_field form.tag layout="horizontal" %} {% bootstrap_field form.tag layout="horizontal" %}
{% bootstrap_field form.comment layout="horizontal" %} {% bootstrap_field form.comment layout="horizontal" %}
</fieldset> </fieldset>
{% eventsignal request.event "pretix.control.signals.voucher_form_html" form=form %}
<div class="form-group submit-group"> <div class="form-group submit-group">
<button type="submit" class="btn btn-primary btn-save"> <button type="submit" class="btn btn-primary btn-save">
{% trans "Save" %} {% trans "Save" %}

View File

@@ -11,6 +11,7 @@ from django.views.generic import CreateView, DeleteView, ListView, UpdateView
from pretix.base.models import Voucher from pretix.base.models import Voucher
from pretix.control.forms.vouchers import VoucherBulkForm, VoucherForm from pretix.control.forms.vouchers import VoucherBulkForm, VoucherForm
from pretix.control.permissions import EventPermissionRequiredMixin from pretix.control.permissions import EventPermissionRequiredMixin
from pretix.control.signals import voucher_form_class
class VoucherList(EventPermissionRequiredMixin, ListView): class VoucherList(EventPermissionRequiredMixin, ListView):
@@ -70,11 +71,17 @@ class VoucherDelete(EventPermissionRequiredMixin, DeleteView):
class VoucherUpdate(EventPermissionRequiredMixin, UpdateView): class VoucherUpdate(EventPermissionRequiredMixin, UpdateView):
model = Voucher model = Voucher
form_class = VoucherForm
template_name = 'pretixcontrol/vouchers/detail.html' template_name = 'pretixcontrol/vouchers/detail.html'
permission = 'can_change_vouchers' permission = 'can_change_vouchers'
context_object_name = 'voucher' context_object_name = 'voucher'
def get_form_class(self):
form_class = VoucherForm
for receiver, response in voucher_form_class.send(self.request.event, cls=form_class):
if response:
form_class = response
return form_class
def get_object(self, queryset=None) -> VoucherForm: def get_object(self, queryset=None) -> VoucherForm:
url = resolve(self.request.path_info) url = resolve(self.request.path_info)
try: try:
@@ -104,11 +111,17 @@ class VoucherUpdate(EventPermissionRequiredMixin, UpdateView):
class VoucherCreate(EventPermissionRequiredMixin, CreateView): class VoucherCreate(EventPermissionRequiredMixin, CreateView):
model = Voucher model = Voucher
form_class = VoucherForm
template_name = 'pretixcontrol/vouchers/detail.html' template_name = 'pretixcontrol/vouchers/detail.html'
permission = 'can_change_vouchers' permission = 'can_change_vouchers'
context_object_name = 'voucher' context_object_name = 'voucher'
def get_form_class(self):
form_class = VoucherForm
for receiver, response in voucher_form_class.send(self.request.event, cls=form_class):
if response:
form_class = response
return form_class
def get_success_url(self) -> str: def get_success_url(self) -> str:
return reverse('control:event.vouchers', kwargs={ return reverse('control:event.vouchers', kwargs={
'organizer': self.request.event.organizer.slug, 'organizer': self.request.event.organizer.slug,