Notify parent

This commit is contained in:
Mira Weller
2026-09-30 21:16:55 +02:00
parent 3dd8cc5862
commit 6d39d08085
3 changed files with 38 additions and 2 deletions
@@ -0,0 +1,11 @@
{% extends "error.html" %}
{% load i18n %}
{% load eventurl %}
{% load urlreplace %}
{% load static %}
{% block content %}
<h1>{% trans "Please wait..." %}</h1>
{{ notify_info|json_script:"notify_info" }}
<script type="text/javascript" src="{% static "pretixcontrol/js/notify_parent.js" %}"></script>
{% endblock %}
+19 -2
View File
@@ -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
@@ -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)
}