Changes between Version 2 and Version 7 of Ticket #35529


Ignore:
Timestamp:
Jun 18, 2024, 10:17:28 AM (6 months ago)
Author:
Sarah Boyce
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #35529

    • Property Summary Have the template tag query_string support Mapping[str, Any] as an argumentHave the template tag query_string support multiple arguments and arguments of type Mapping[str, Any]
  • Ticket #35529 – Description

    v2 v7  
    11Based off this discussion: https://forum.djangoproject.com/t/adding-a-template-tag-to-generate-query-strings/24521/28
    22
    3 Currenty `query_string` only supports a `QueryDict` as an argument, consensus appears to want to update this to also support `Mapping[str, Any]`
     3Currently `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
     8Tests which hopefully illustrate the requested updates
    49
    510{{{#!diff
    611--- a/tests/template_tests/syntax_tests/test_query_string.py
    712+++ b/tests/template_tests/syntax_tests/test_query_string.py
    8 @@ -93,6 +93,14 @@ class QueryStringTagTests(SimpleTestCase):
     13@@ -93,6 +93,18 @@ class QueryStringTagTests(SimpleTestCase):
    914         )
    1015         self.assertEqual(output, "?a=2&b=2")
    1116
    12 +    @setup(
    13 +        {"query_string_dict": "{% query_string my_dict %}"}
    14 +    )
     17+    @setup({"query_string_dict": "{% query_string my_dict %}"})
    1518+    def test_query_string_with_explicit_dict_and_no_request(self):
    1619+        context = {"my_dict": {"a": 1, "b": 2}}
     
    1821+        self.assertEqual(output, "?a=1&b=2")
    1922+
     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+
    2029     @setup({"query_string_no_request_no_query_dict": "{% query_string %}"})
    2130     def test_query_string_without_request_or_explicit_query_dict(self):
    22          msg = "'Context' object has no attribute 'request'"
    2331}}}
    24 
    25 
    26 Note: I believe this is backwards compatible so not a release blocker
Back to Top