mirror of
https://github.com/pretix/pretix.git
synced 2026-05-08 15:44:02 +00:00
Added signals that allow to modify the voucher form
This commit is contained in:
@@ -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).
|
||||
"""
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{% extends "pretixcontrol/items/base.html" %}
|
||||
{% load i18n %}
|
||||
{% load bootstrap3 %}
|
||||
{% load eventsignal %}
|
||||
{% block title %}{% trans "Voucher" %}{% endblock %}
|
||||
{% block inside %}
|
||||
<h1>{% trans "Voucher" %}</h1>
|
||||
@@ -36,6 +37,7 @@
|
||||
{% bootstrap_field form.tag layout="horizontal" %}
|
||||
{% bootstrap_field form.comment layout="horizontal" %}
|
||||
</fieldset>
|
||||
{% eventsignal request.event "pretix.control.signals.voucher_form_html" form=form %}
|
||||
<div class="form-group submit-group">
|
||||
<button type="submit" class="btn btn-primary btn-save">
|
||||
{% trans "Save" %}
|
||||
|
||||
@@ -11,6 +11,7 @@ from django.views.generic import CreateView, DeleteView, ListView, UpdateView
|
||||
from pretix.base.models import Voucher
|
||||
from pretix.control.forms.vouchers import VoucherBulkForm, VoucherForm
|
||||
from pretix.control.permissions import EventPermissionRequiredMixin
|
||||
from pretix.control.signals import voucher_form_class
|
||||
|
||||
|
||||
class VoucherList(EventPermissionRequiredMixin, ListView):
|
||||
@@ -70,11 +71,17 @@ class VoucherDelete(EventPermissionRequiredMixin, DeleteView):
|
||||
|
||||
class VoucherUpdate(EventPermissionRequiredMixin, UpdateView):
|
||||
model = Voucher
|
||||
form_class = VoucherForm
|
||||
template_name = 'pretixcontrol/vouchers/detail.html'
|
||||
permission = 'can_change_vouchers'
|
||||
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:
|
||||
url = resolve(self.request.path_info)
|
||||
try:
|
||||
@@ -104,11 +111,17 @@ class VoucherUpdate(EventPermissionRequiredMixin, UpdateView):
|
||||
|
||||
class VoucherCreate(EventPermissionRequiredMixin, CreateView):
|
||||
model = Voucher
|
||||
form_class = VoucherForm
|
||||
template_name = 'pretixcontrol/vouchers/detail.html'
|
||||
permission = 'can_change_vouchers'
|
||||
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:
|
||||
return reverse('control:event.vouchers', kwargs={
|
||||
'organizer': self.request.event.organizer.slug,
|
||||
|
||||
Reference in New Issue
Block a user