Changes between Version 2 and Version 7 of Ticket #35529
- Timestamp:
- Jun 18, 2024, 10:17:28 AM (6 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #35529
- Property Summary Have the template tag query_string support Mapping[str, Any] as an argument → Have the template tag query_string support multiple arguments and arguments of type Mapping[str, Any]
-
Ticket #35529 – Description
v2 v7 1 1 Based off this discussion: https://forum.djangoproject.com/t/adding-a-template-tag-to-generate-query-strings/24521/28 2 2 3 Currenty `query_string` only supports a `QueryDict` as an argument, consensus appears to want to update this to also support `Mapping[str, Any]` 3 Currently `query_string` only supports a single `QueryDict` as an argument, consensus appears to want the following updates: 4 5 - support arguments of type `Mapping[str, Any]` 6 - support multiple arguments 7 8 Tests which hopefully illustrate the requested updates 4 9 5 10 {{{#!diff 6 11 --- a/tests/template_tests/syntax_tests/test_query_string.py 7 12 +++ b/tests/template_tests/syntax_tests/test_query_string.py 8 @@ -93,6 +93,1 4@@ class QueryStringTagTests(SimpleTestCase):13 @@ -93,6 +93,18 @@ class QueryStringTagTests(SimpleTestCase): 9 14 ) 10 15 self.assertEqual(output, "?a=2&b=2") 11 16 12 + @setup( 13 + {"query_string_dict": "{% query_string my_dict %}"} 14 + ) 17 + @setup({"query_string_dict": "{% query_string my_dict %}"}) 15 18 + def test_query_string_with_explicit_dict_and_no_request(self): 16 19 + context = {"my_dict": {"a": 1, "b": 2}} … … 18 21 + self.assertEqual(output, "?a=1&b=2") 19 22 + 23 + @setup({"query_string_multiple_args": "{% query_string my_dict my_query_dict %}"}) 24 + def test_query_string_with_multiple_args(self): 25 + context = {"my_dict": {"a": 1, "b": 2}, "my_query_dict": QueryDict("c=1")} 26 + output = self.engine.render_to_string("query_string_multiple_args", context) 27 + self.assertEqual(output, "?a=1&b=2&c=1") 28 + 20 29 @setup({"query_string_no_request_no_query_dict": "{% query_string %}"}) 21 30 def test_query_string_without_request_or_explicit_query_dict(self): 22 msg = "'Context' object has no attribute 'request'"23 31 }}} 24 25 26 Note: I believe this is backwards compatible so not a release blocker