-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/256 filter klantcontact on betrokkenen #285
Feature/256 filter klantcontact on betrokkenen #285
Conversation
…betrokkene -> partij uuid/url
… betrokkene -> partij uuid/url
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionality wise I think the changes are good! I do think we can add these changes and remove some repeated code and give the test suite some love.
src/openklant/components/klantinteracties/api/filterset/klantcontacten.py
Outdated
Show resolved
Hide resolved
@@ -92,6 +107,48 @@ def setUp(self): | |||
onderwerpobjectidentificator_code_register="5", | |||
) | |||
|
|||
def test_filter_partij_url(self): | |||
partij_url = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using reverse
here in combination with http://testserver
would be nice.
src/openklant/components/klantinteracties/api/tests/test_filters.py
Outdated
Show resolved
Hide resolved
3ec6e17
to
f07fdb4
Compare
f07fdb4
to
6662711
Compare
src/openklant/components/klantinteracties/api/tests/test_filters.py
Outdated
Show resolved
Hide resolved
…urls and removed the setupdata
…ri, decided to use this not so elegant way to set this data because using extend_schema_field on the URLViewFilter would remove the help_texts of the filters. The other solutions were to use the extend_view to set every parameter for the views we use this fields by hand, to define one generic description or to let the queryparam type be wrongly defined and give a warning in the help_text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's still a lot of hardcoded URLs in the test, please replace them with reverse
src/openklant/utils/query.py
Outdated
if parameter["name"].endswith("__url"): | ||
parameter["schema"] = {"type": "string", "format": "uri"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SonnyBA I discussed this with @bart-maykin, because the underlying field that is referred to is a uuid
, drf-spectacular adds format: uuid
for all these fields in the OAS. It's not possible to set the format via the filter class, so that leaves us with this workaround or to add extend_schema_field
for all fields and override the format (and add the help text). What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a workable solution but I would make a separate FilterExtension
for it to make things a bit more explicit. These changes currently are hidden away in the CamelizeFilterExtension
which should only camelize the parameters in my opinion (like the name suggests).
Maybe we could also do a bit more filtering, like checking for the parameters type
(string
) and the in
value (query
) to prevent changing parameters that should not be affected.
Some inspiration:
class UUIDURLFilterExtension(DjangoFilterExtension):
priority = 2
def get_schema_operation_parameters(self, auto_schema, *args, **kwargs) -> list[dict]:
parameters: list[dict] = super().get_schema_operation_parameters(
auto_schema, *args, **kwargs
)
for parameter in parameters:
parameter_name = parameter["name"]
is_query = parameter["in"] == OpenApiParameter.QUERY
is_string = parameter["schema"]["type"] == "string"
is_url_field = parameter_name.endswith("__url")
if all((is_query, is_string, is_url_field,)):
parameter["schema"] = {"type": "string", "format": "uri"}
return parameters
src/openklant/components/klantinteracties/api/tests/test_filters.py
Outdated
Show resolved
Hide resolved
src/openklant/components/klantinteracties/api/tests/test_filters.py
Outdated
Show resolved
Hide resolved
src/openklant/components/klantinteracties/api/tests/test_filters.py
Outdated
Show resolved
Hide resolved
src/openklant/components/klantinteracties/api/tests/test_filters.py
Outdated
Show resolved
Hide resolved
src/openklant/components/klantinteracties/api/tests/test_filters.py
Outdated
Show resolved
Hide resolved
src/openklant/components/klantinteracties/api/tests/test_filters.py
Outdated
Show resolved
Hide resolved
src/openklant/components/klantinteracties/api/tests/test_filters.py
Outdated
Show resolved
Hide resolved
src/openklant/components/klantinteracties/api/tests/test_filters.py
Outdated
Show resolved
Hide resolved
src/openklant/components/klantinteracties/api/tests/test_filters.py
Outdated
Show resolved
Hide resolved
src/openklant/utils/query.py
Outdated
if parameter["name"].endswith("__url"): | ||
parameter["schema"] = {"type": "string", "format": "uri"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a workable solution but I would make a separate FilterExtension
for it to make things a bit more explicit. These changes currently are hidden away in the CamelizeFilterExtension
which should only camelize the parameters in my opinion (like the name suggests).
Maybe we could also do a bit more filtering, like checking for the parameters type
(string
) and the in
value (query
) to prevent changing parameters that should not be affected.
Some inspiration:
class UUIDURLFilterExtension(DjangoFilterExtension):
priority = 2
def get_schema_operation_parameters(self, auto_schema, *args, **kwargs) -> list[dict]:
parameters: list[dict] = super().get_schema_operation_parameters(
auto_schema, *args, **kwargs
)
for parameter in parameters:
parameter_name = parameter["name"]
is_query = parameter["in"] == OpenApiParameter.QUERY
is_string = parameter["schema"]["type"] == "string"
is_url_field = parameter_name.endswith("__url")
if all((is_query, is_string, is_url_field,)):
parameter["schema"] = {"type": "string", "format": "uri"}
return parameters
…ter doesn't end in valid uuid
@SonnyBA I did add the extra filtering for the |
@bart-maykin see #292 |
Fixes #256
Changes
Add two filter fields to the klantcontact api endpoint: