diff --git a/src/pretix/control/templates/pretixcontrol/notify_parent.html b/src/pretix/control/templates/pretixcontrol/notify_parent.html new file mode 100644 index 0000000000..6ce7a7acbb --- /dev/null +++ b/src/pretix/control/templates/pretixcontrol/notify_parent.html @@ -0,0 +1,11 @@ +{% extends "error.html" %} +{% load i18n %} +{% load eventurl %} +{% load urlreplace %} +{% load static %} + +{% block content %} +

{% trans "Please wait..." %}

+ {{ notify_info|json_script:"notify_info" }} + +{% endblock %} diff --git a/src/pretix/control/views/__init__.py b/src/pretix/control/views/__init__.py index cfff1c4519..e83fd858b9 100644 --- a/src/pretix/control/views/__init__.py +++ b/src/pretix/control/views/__init__.py @@ -22,9 +22,12 @@ import collections.abc import warnings +from django.contrib import messages from django.core.paginator import ( EmptyPage, PageNotAnInteger, UnorderedObjectListWarning, ) +from django.http.response import HttpResponseRedirect +from django.shortcuts import render from django.utils.translation import gettext_lazy as _ from django.views.generic import edit @@ -38,7 +41,21 @@ class EventBasedFormMixin: return kwargs -class CreateView(EventBasedFormMixin, edit.CreateView): +class TellParentFormMixin: + + def form_valid(self, form): + result = super().form_valid(form) + if self.request.GET.get('notify_parent') and isinstance(result, HttpResponseRedirect): + message_store = messages.get_messages(self.request) + msgs = [{'level': msg.level_tag, 'message': msg.message} for msg in message_store] + return render(self.request, 'pretixcontrol/notify_parent.html', { + 'notify_info': {'object': self.object.pk, 'object_str': str(self.object), 'redirect_url': result.url, 'messages': msgs}, + }) + else: + return result + + +class CreateView(EventBasedFormMixin, TellParentFormMixin, edit.CreateView): """ Like Django's default CreateView, but passes the optional event argument to the form. This is necessary for I18nModelForms to work @@ -47,7 +64,7 @@ class CreateView(EventBasedFormMixin, edit.CreateView): pass -class UpdateView(EventBasedFormMixin, edit.UpdateView): +class UpdateView(EventBasedFormMixin, TellParentFormMixin, edit.UpdateView): """ Like Django's default UpdateView, but passes the optional event argument to the form. This is necessary for I18nModelForms to work diff --git a/src/pretix/static/pretixcontrol/js/notify_parent.js b/src/pretix/static/pretixcontrol/js/notify_parent.js new file mode 100644 index 0000000000..c372ec2769 --- /dev/null +++ b/src/pretix/static/pretixcontrol/js/notify_parent.js @@ -0,0 +1,8 @@ +try { + window.parent.postMessage({ + type: 'pretix:notify-parent', + data: JSON.parse(document.getElementById('notify_info').textContent), + }, location.origin) +} catch (e) { + console.error('Could not post message to parent.', e) +}