From f3fd3f0b1012938bd7fe2a4dfd67bddcecf9fad8 Mon Sep 17 00:00:00 2001 From: David Buxton Date: Fri, 1 Dec 2023 10:27:31 +0000 Subject: [PATCH] Allow overriding the edit form action (#229) This makes it the same as the add form. Useful if you are doing something weird like using Google's blobstore.create_upload_url(..) API. --- .../templates/wagtailmedia/media/edit.html | 2 +- tests/templates/wagtailmedia/media/edit.html | 3 ++ tests/test_views.py | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/templates/wagtailmedia/media/edit.html diff --git a/src/wagtailmedia/templates/wagtailmedia/media/edit.html b/src/wagtailmedia/templates/wagtailmedia/media/edit.html index 1d456a61..06778b1f 100644 --- a/src/wagtailmedia/templates/wagtailmedia/media/edit.html +++ b/src/wagtailmedia/templates/wagtailmedia/media/edit.html @@ -30,7 +30,7 @@
-
+ {% csrf_token %} {% if next %}{% endif %}
    diff --git a/tests/templates/wagtailmedia/media/edit.html b/tests/templates/wagtailmedia/media/edit.html new file mode 100644 index 00000000..ba3abac8 --- /dev/null +++ b/tests/templates/wagtailmedia/media/edit.html @@ -0,0 +1,3 @@ +{% extends "wagtailmedia/media/edit.html" %} + +{% block action %}/somewhere/else/edit{% endblock %} diff --git a/tests/test_views.py b/tests/test_views.py index 0bce0e3e..d45da60f 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -468,6 +468,37 @@ def test_extends(self): self.assertContains(response, "sweet-form-row") self.assertContains(response, "sweet-stats") + def test_action_block(self): + with self.settings( + TEMPLATES=[ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [os.path.join(os.path.dirname(__file__), "templates")], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + "django.template.context_processors.request", + "wagtail.contrib.settings.context_processors.settings", + ], + "debug": True, + }, + } + ] + ): + response = self.client.get( + reverse("wagtailmedia:edit", args=(self.media.id,)) + ) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, "wagtailmedia/media/edit.html") + self.assertContains( + response, + '', + ) + def test_post(self): # Build a fake file fake_file = ContentFile("A boring example song", name="song.mp3")