#35529: Have the template tag query_string support multiple arguments and 
arguments
of type Mapping[str, Any]
---------------------------------+--------------------------------------
     Reporter:  Sarah Boyce      |                    Owner:  nobody
         Type:  New feature      |                   Status:  new
    Component:  Template system  |                  Version:  5.1
     Severity:  Normal           |               Resolution:
     Keywords:                   |             Triage Stage:  Unreviewed
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+--------------------------------------
Changes (by Sarah Boyce):

 * 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]


Old description:

> Based off this discussion: https://forum.djangoproject.com/t/adding-a
> -template-tag-to-generate-query-strings/24521/28
>
> Currenty `query_string` only supports a `QueryDict` as an argument,
> consensus appears to want to update this to also support `Mapping[str,
> Any]`
>
> {{{#!diff
> --- a/tests/template_tests/syntax_tests/test_query_string.py
> +++ b/tests/template_tests/syntax_tests/test_query_string.py
> @@ -93,6 +93,14 @@ class QueryStringTagTests(SimpleTestCase):
>          )
>          self.assertEqual(output, "?a=2&b=2")
>
> +    @setup(
> +        {"query_string_dict": "{% query_string my_dict %}"}
> +    )
> +    def test_query_string_with_explicit_dict_and_no_request(self):
> +        context = {"my_dict": {"a": 1, "b": 2}}
> +        output = self.engine.render_to_string("query_string_dict",
> context)
> +        self.assertEqual(output, "?a=1&b=2")
> +
>      @setup({"query_string_no_request_no_query_dict": "{% query_string
> %}"})
>      def test_query_string_without_request_or_explicit_query_dict(self):
>          msg = "'Context' object has no attribute 'request'"
> }}}
>

> Note: I believe this is backwards compatible so not a release blocker

New description:

 Based off this discussion: https://forum.djangoproject.com/t/adding-a
 -template-tag-to-generate-query-strings/24521/28

 Currently `query_string` only supports a single `QueryDict` as an
 argument, consensus appears to want the following updates:

 - support arguments of type `Mapping[str, Any]`
 - support multiple arguments

 Tests which hopefully illustrate the requested updates

 {{{#!diff
 --- a/tests/template_tests/syntax_tests/test_query_string.py
 +++ b/tests/template_tests/syntax_tests/test_query_string.py
 @@ -93,6 +93,18 @@ class QueryStringTagTests(SimpleTestCase):
          )
          self.assertEqual(output, "?a=2&b=2")

 +    @setup({"query_string_dict": "{% query_string my_dict %}"})
 +    def test_query_string_with_explicit_dict_and_no_request(self):
 +        context = {"my_dict": {"a": 1, "b": 2}}
 +        output = self.engine.render_to_string("query_string_dict",
 context)
 +        self.assertEqual(output, "?a=1&b=2")
 +
 +    @setup({"query_string_multiple_args": "{% query_string my_dict
 my_query_dict %}"})
 +    def test_query_string_with_multiple_args(self):
 +        context = {"my_dict": {"a": 1, "b": 2}, "my_query_dict":
 QueryDict("c=1")}
 +        output =
 self.engine.render_to_string("query_string_multiple_args", context)
 +        self.assertEqual(output, "?a=1&b=2&c=1")
 +
      @setup({"query_string_no_request_no_query_dict": "{% query_string
 %}"})
      def test_query_string_without_request_or_explicit_query_dict(self):
 }}}

--
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35529#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701902beca843-8bbd79fb-1f59-48b7-9682-479977cfaf76-000000%40eu-central-1.amazonses.com.

Reply via email to