forked from CGM_Public/pretix_original
Added process_response URL hook
This commit is contained in:
@@ -35,7 +35,7 @@ Request flow
|
|||||||
""""""""""""
|
""""""""""""
|
||||||
|
|
||||||
.. automodule:: pretix.presale.signals
|
.. automodule:: pretix.presale.signals
|
||||||
:members: process_request
|
:members: process_request, process_response
|
||||||
|
|
||||||
Vouchers
|
Vouchers
|
||||||
""""""""
|
""""""""
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from django.core.urlresolvers import resolve
|
from django.core.urlresolvers import resolve
|
||||||
|
|
||||||
|
from pretix.presale.signals import process_response
|
||||||
|
|
||||||
from .utils import _detect_event
|
from .utils import _detect_event
|
||||||
|
|
||||||
|
|
||||||
@@ -19,3 +21,8 @@ class EventMiddleware:
|
|||||||
# We need to create session even if we do not yet store something there, because we need the session
|
# We need to create session even if we do not yet store something there, because we need the session
|
||||||
# key for e.g. saving the user's cart
|
# key for e.g. saving the user's cart
|
||||||
request.session['_'] = '_'
|
request.session['_'] = '_'
|
||||||
|
|
||||||
|
def process_response(self, request, response):
|
||||||
|
for receiver, r in process_response.send(request.event, request=request, response=response):
|
||||||
|
response = r
|
||||||
|
return response
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ process_request = EventPluginSignal(
|
|||||||
"""
|
"""
|
||||||
This signal is sent out whenever a request is made to a event presale page. Most of the
|
This signal is sent out whenever a request is made to a event presale page. Most of the
|
||||||
time, this will be called from the middleware layer (except on plugin-provided pages
|
time, this will be called from the middleware layer (except on plugin-provided pages
|
||||||
this will be caled by the @event_view decorator). Similarly to Django's process_request
|
this will be called by the @event_view decorator). Similarly to Django's process_request
|
||||||
middleware method, if you return a Response, that response will be used and the request
|
middleware method, if you return a Response, that response will be used and the request
|
||||||
won't be processed any further down the stack.
|
won't be processed any further down the stack.
|
||||||
|
|
||||||
@@ -61,3 +61,20 @@ easy to cause serious performance problems.
|
|||||||
|
|
||||||
As with all plugin signals, the ``sender`` keyword argument will contain the event.
|
As with all plugin signals, the ``sender`` keyword argument will contain the event.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
process_response = EventPluginSignal(
|
||||||
|
providing_args=["request", "response"]
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
This signal is sent out whenever a response is sent from a event presale page. Most of
|
||||||
|
the time, this will be called from the middleware layer (except on plugin-provided pages
|
||||||
|
this will be called by the @event_view decorator). Similarly to Django's process_response
|
||||||
|
middleware method you must return a response object, that will be passed further up the
|
||||||
|
stack to other handlers of the signal. If you do not want to alter the response, just
|
||||||
|
return the ``response`` parameter.
|
||||||
|
|
||||||
|
WARNING: Be very careful about using this signal as listening to it makes it really
|
||||||
|
easy to cause serious performance problems.
|
||||||
|
|
||||||
|
As with all plugin signals, the ``sender`` keyword argument will contain the event.
|
||||||
|
"""
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from pretix.base.middleware import LocaleMiddleware
|
from pretix.base.middleware import LocaleMiddleware
|
||||||
from pretix.base.models import Event, EventPermission, Organizer
|
from pretix.base.models import Event, EventPermission, Organizer
|
||||||
from pretix.multidomain.urlreverse import get_domain
|
from pretix.multidomain.urlreverse import get_domain
|
||||||
from pretix.presale.signals import process_request
|
from pretix.presale.signals import process_request, process_response
|
||||||
|
|
||||||
|
|
||||||
def _detect_event(request):
|
def _detect_event(request):
|
||||||
@@ -80,5 +80,8 @@ def event_view(func):
|
|||||||
if ret:
|
if ret:
|
||||||
return ret
|
return ret
|
||||||
else:
|
else:
|
||||||
return func(request=request, *args, **kwargs)
|
response = func(request=request, *args, **kwargs)
|
||||||
|
for receiver, r in process_response.send(request.event, request=request, response=response):
|
||||||
|
response = r
|
||||||
|
return response
|
||||||
return wrap
|
return wrap
|
||||||
|
|||||||
Reference in New Issue
Block a user