mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Add new bundled plugin "returnurl"
This commit is contained in:
21
src/pretix/plugins/returnurl/__init__.py
Normal file
21
src/pretix/plugins/returnurl/__init__.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from django.apps import AppConfig
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from pretix import __version__ as version
|
||||
|
||||
|
||||
class ReturnURLApp(AppConfig):
|
||||
name = 'pretix.plugins.returnurl'
|
||||
verbose_name = _("Redirection from order page")
|
||||
|
||||
class PretixPluginMeta:
|
||||
name = _("Redirection from order page")
|
||||
author = _("the pretix team")
|
||||
version = version
|
||||
description = _("This plugin allows to link to payments and redirect back afterwards.")
|
||||
|
||||
def ready(self):
|
||||
from . import signals # NOQA
|
||||
|
||||
|
||||
default_app_config = 'pretix.plugins.returnurl.ReturnURLApp'
|
||||
50
src/pretix/plugins/returnurl/signals.py
Normal file
50
src/pretix/plugins/returnurl/signals.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.dispatch import receiver
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import resolve, reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from pretix.control.signals import nav_event_settings
|
||||
from pretix.presale.signals import process_request
|
||||
|
||||
|
||||
@receiver(process_request, dispatch_uid="returnurl_process_request")
|
||||
def returnurl_process_request(sender, request, **kwargs):
|
||||
try:
|
||||
r = resolve(request.path_info)
|
||||
except:
|
||||
return
|
||||
|
||||
urlname = r.url_name
|
||||
urlkwargs = r.kwargs
|
||||
|
||||
if urlname.startswith('event.order'):
|
||||
key = 'order_{}_{}_{}_return_url'.format(urlkwargs.get('organizer', '-'), urlkwargs['event'],
|
||||
urlkwargs['order'])
|
||||
if urlname == 'event.order' and key in request.session:
|
||||
r = redirect(request.session.get(key))
|
||||
del request.session[key]
|
||||
return r
|
||||
elif urlname != 'event.order' and 'return_url' in request.GET:
|
||||
u = request.GET.get('return_url')
|
||||
if not sender.settings.returnurl_prefix:
|
||||
raise PermissionDenied('No return URL prefix set.')
|
||||
elif not u.startswith(sender.settings.returnurl_prefix):
|
||||
raise PermissionDenied('Invalid return URL.')
|
||||
request.session[key] = u
|
||||
|
||||
|
||||
@receiver(nav_event_settings, dispatch_uid='returnurl_nav')
|
||||
def navbar_info(sender, request, **kwargs):
|
||||
url = resolve(request.path_info)
|
||||
if not request.user.has_event_permission(request.organizer, request.event, 'can_change_event_settings',
|
||||
request=request):
|
||||
return []
|
||||
return [{
|
||||
'label': _('Redirection'),
|
||||
'url': reverse('plugins:returnurl:settings', kwargs={
|
||||
'event': request.event.slug,
|
||||
'organizer': request.organizer.slug,
|
||||
}),
|
||||
'active': url.namespace == 'plugins:returnurl',
|
||||
}]
|
||||
@@ -0,0 +1,16 @@
|
||||
{% extends "pretixcontrol/event/settings_base.html" %}
|
||||
{% load i18n %}
|
||||
{% load bootstrap3 %}
|
||||
{% block inside %}
|
||||
<h1>{% trans "Redirection from order page" %}</h1>
|
||||
<form action="" method="post" class="form-horizontal" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form_errors form %}
|
||||
{% bootstrap_field form.returnurl_prefix layout="horizontal" %}
|
||||
<div class="form-group submit-group">
|
||||
<button type="submit" class="btn btn-primary btn-save">
|
||||
{% trans "Save" %}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
8
src/pretix/plugins/returnurl/urls.py
Normal file
8
src/pretix/plugins/returnurl/urls.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import ReturnSettings
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^control/event/(?P<organizer>[^/]+)/(?P<event>[^/]+)/returnurl/settings$',
|
||||
ReturnSettings.as_view(), name='settings'),
|
||||
]
|
||||
30
src/pretix/plugins/returnurl/views.py
Normal file
30
src/pretix/plugins/returnurl/views.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from django import forms
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from pretix.base.forms import SettingsForm
|
||||
from pretix.base.models import Event
|
||||
from pretix.control.views.event import (
|
||||
EventSettingsFormView, EventSettingsViewMixin,
|
||||
)
|
||||
|
||||
|
||||
class ReturnSettingsForm(SettingsForm):
|
||||
returnurl_prefix = forms.URLField(
|
||||
label=_("Base redirection URL"),
|
||||
help_text=_("Redirection will only be allowed to URLs that start with this prefix."),
|
||||
required=False,
|
||||
)
|
||||
|
||||
|
||||
class ReturnSettings(EventSettingsViewMixin, EventSettingsFormView):
|
||||
model = Event
|
||||
form_class = ReturnSettingsForm
|
||||
template_name = 'returnurl/settings.html'
|
||||
permission = 'can_change_settings'
|
||||
|
||||
def get_success_url(self) -> str:
|
||||
return reverse('plugins:returnurl:settings', kwargs={
|
||||
'organizer': self.request.event.organizer.slug,
|
||||
'event': self.request.event.slug
|
||||
})
|
||||
Reference in New Issue
Block a user