Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Commit edc7784

Browse files
Merge branch 'master' into feat/add-share-custom
2 parents 5ea496f + 1f8b77c commit edc7784

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org>

inertia/middleware.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.http import HttpResponse
1+
from django.http import HttpResponse, HttpResponseRedirect
22
from .share import share
33
from .version import asset_version
44

@@ -20,10 +20,17 @@ def __call__(self, request):
2020
response = HttpResponse(status=409)
2121
response["X-Inertia-Location"] = request.get_full_path_info()
2222
return response
23+
2324
share(request, "flash", {
2425
'success': request.session.get("success", False),
2526
'error': request.session.get("error", False)
2627
})
2728
share(request, 'errors', request.session.get("errors", {}))
2829
response = self.get_response(request)
30+
31+
# manage PUT, PATCH, DELETE redirections
32+
if request.method in ["PUT", "PATCH", "DELETE"] and \
33+
isinstance(response, HttpResponseRedirect) and \
34+
response.status_code == 302:
35+
response.status_code = 303
2936
return response

inertia/share.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def share_flash(request, success=False, error=False, errors=False):
1414
request.session["error"] = error
1515

1616
if errors:
17-
request.session["error"] = errors
17+
request.session["errors"] = errors
1818

1919
# log.info(("share", success, error, errors))
2020
share(request, "flash",{'success':success,'error':error})

test.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import django
55
from django.conf import settings
66
from django.test import RequestFactory
7-
from django.http import HttpResponse
7+
from django.http import HttpResponse, HttpResponseRedirect
88
import os
99

1010
from inertia.share import share
@@ -82,3 +82,19 @@ def test_share_custom_data(self):
8282
response = render_inertia(request, "Index")
8383
self.assertTrue(b'share_custom_data"' in response.content)
8484
self.assertTrue(b'share_custom_value"' in response.content)
85+
86+
def test_redirect_303_for_put_patch_delete_requests(self):
87+
request = RequestFactory().put("/users/1")
88+
self.set_session(request)
89+
response = InertiaMiddleware(lambda x: HttpResponseRedirect(redirect_to="/users"))(request)
90+
self.assertTrue(response.status_code==303, response.status_code)
91+
92+
request = RequestFactory().patch("/users/1")
93+
self.set_session(request)
94+
response = InertiaMiddleware(lambda x: HttpResponseRedirect(redirect_to="/users"))(request)
95+
self.assertTrue(response.status_code==303, response.status_code)
96+
97+
request = RequestFactory().delete("/users/1")
98+
self.set_session(request)
99+
response = InertiaMiddleware(lambda x: HttpResponseRedirect(redirect_to="/users"))(request)
100+
self.assertTrue(response.status_code==303, response.status_code)

0 commit comments

Comments
 (0)