#35529: Have the template tag query_string support Mapping[str, Any] as an
argument
---------------------------------+--------------------------------------
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
---------------------------------+--------------------------------------
Description changed by Sarah Boyce:
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.
>
> {{{#!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_query_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
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_query_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
--
--
Ticket URL: <https://code.djangoproject.com/ticket/35529#comment:1>
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/010701902a468bbd-f6553477-1143-4383-950f-9cb1c3895535-000000%40eu-central-1.amazonses.com.