From 52ba0b3178de86a5274cff1748f9ca50c546d4cb Mon Sep 17 00:00:00 2001 From: Steve Lacey Date: Thu, 16 Dec 2021 12:54:27 +0700 Subject: [PATCH 1/2] Always set bundle even on detail requests --- worf/views/base.py | 9 ++++++++- worf/views/list.py | 2 -- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/worf/views/base.py b/worf/views/base.py index 1ee29cc..54810f7 100644 --- a/worf/views/base.py +++ b/worf/views/base.py @@ -204,6 +204,13 @@ def set_bundle(self, raw_bundle): self.bundle[field] = raw_bundle[key] self.keymap[field] = key + def set_bundle_from_request(self, request): + if request.method == "GET": + self.set_bundle_from_query_string(request) + return + + self.set_bundle_from_request_body(request) + def set_bundle_from_query_string(self, request): raw_bundle = self.flatten_bundle(parse_qs(request.META["QUERY_STRING"])) @@ -233,7 +240,7 @@ def dispatch(self, request, *args, **kwargs): try: self._check_permissions() # only returns 200 or HTTP_EXCEPTIONS - self.set_bundle_from_request_body(request) + self.set_bundle_from_request(request) return handler(request, *args, **kwargs) # calls self.serialize() except HTTP_EXCEPTIONS as e: return self.render_to_response(dict(message=e.message), e.status) diff --git a/worf/views/list.py b/worf/views/list.py index f4fd3dd..1b74c91 100644 --- a/worf/views/list.py +++ b/worf/views/list.py @@ -86,8 +86,6 @@ def set_search_lookup_kwargs(self): if not self.filter_fields and not self.search_fields: return - self.set_bundle_from_query_string(self.request) - # Whatever is not q or page as a querystring param will # be used for key-value search. query = self.bundle.pop("q", "").strip() From a05e69ac51a4e100c45032b02d6e7f189fced5af Mon Sep 17 00:00:00 2001 From: Steve Lacey Date: Thu, 16 Dec 2021 12:55:14 +0700 Subject: [PATCH 2/2] Transform bool/nulls in query param bundles --- worf/views/base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/worf/views/base.py b/worf/views/base.py index 54810f7..46b187b 100644 --- a/worf/views/base.py +++ b/worf/views/base.py @@ -214,7 +214,14 @@ def set_bundle_from_request(self, request): def set_bundle_from_query_string(self, request): raw_bundle = self.flatten_bundle(parse_qs(request.META["QUERY_STRING"])) - self.set_bundle(raw_bundle) + strings = dict(true=True, false=False, null=None) + + coerced_bundle = { + key: strings.get(str(value).lower(), value) + for key, value in raw_bundle.items() + } + + self.set_bundle(coerced_bundle) def set_bundle_from_request_body(self, request): raw_bundle = {}