Skip to content

Commit

Permalink
Allow overriding the edit form action (#229)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davidwtbuxton authored Dec 1, 2023
1 parent 29c75ea commit f3fd3f0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/wagtailmedia/templates/wagtailmedia/media/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="row row-flush nice-padding">

<div class="col10 divider-after">
<form action="{% url 'wagtailmedia:edit' media.pk %}" method="POST" enctype="multipart/form-data" novalidate>
<form action="{% block action %}{% url 'wagtailmedia:edit' media.pk %}{% endblock %}" method="POST" enctype="multipart/form-data" novalidate>
{% csrf_token %}
{% if next %}<input type="hidden" value="{{ next }}" name="next">{% endif %}
<ul class="fields">
Expand Down
3 changes: 3 additions & 0 deletions tests/templates/wagtailmedia/media/edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends "wagtailmedia/media/edit.html" %}

{% block action %}/somewhere/else/edit{% endblock %}
31 changes: 31 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
'<form action="/somewhere/else/edit" method="POST" enctype="multipart/form-data" novalidate>',
)

def test_post(self):
# Build a fake file
fake_file = ContentFile("A boring example song", name="song.mp3")
Expand Down

0 comments on commit f3fd3f0

Please sign in to comment.