Skip to content
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

json complex backend #321

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

json complex backend #321

wants to merge 15 commits into from

Conversation

ferrants
Copy link
Contributor

No description provided.

@codecov-io
Copy link

Codecov Report

Merging #321 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@ferrants
Copy link
Contributor Author

ferrants commented Nov 16, 2019

@philipn , we found the existing Complex Backend to be too annoying to integrate with because of the double encodings and the order of and and or wasn't explicit enough. We are using this in our app instead and thought we could contribute it back.

tests/testapp/urls.py Outdated Show resolved Hide resolved
@@ -52,6 +52,19 @@ class pagination_class(pagination.PageNumberPagination):
page_size_query_param = 'page_size'


class ComplexJsonFilterFieldsUserViewSet(FilterFieldsUserViewSet):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP-8 nitpick: ComplexJSONFilterFieldsUserViewSet JSON (and all acronyms) should be capitalized: Note: When using acronyms in CapWords, capitalize all the letters of the acronym. Thus HTTPServerError is better than HttpServerError.

@FlipperPA
Copy link

This looks fantastic, @ferrants - thank you for the contribution.

@rpkilby - what do you think about this direction? I'm hesitant to use it until it receives your blessing going forward. Thanks!

README.rst Outdated Show resolved Hide resolved
@@ -94,3 +98,60 @@ def get_filtered_querysets(self, querystrings, request, queryset, view):
if errors:
raise ValidationError(errors)
return querysets


class ComplexJsonFilterBackend(RestFrameworkFilterBackend):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ComplexJsonFilterBackend -> ComplexJSONFilterBackend

tests/test_backends.py Outdated Show resolved Hide resolved
@FlipperPA
Copy link

@ferrants A total nitpick, but one that was pointing out to me on one of my projects recently, so I figured I'd pay it forward! This really looks excellent, I'm hoping for a merge.

@rgs258
Copy link

rgs258 commented Mar 26, 2020

bump

@ferrants
Copy link
Contributor Author

Considering making another package that can be installed that will include this. This repo isn't very active.

@FlipperPA
Copy link

We'd be happy to help test out and contribute where we can, @ferrants!

@softzer0
Copy link

softzer0 commented May 7, 2020

This project is so inactive that even the pip package has older version in it. When this will be merged into the main branch and repository for pip updated, @rpkilby, @philipn, anyone? I need it for my project to properly include it into requirements file.

@ferrants
Copy link
Contributor Author

ferrants commented May 7, 2020

@Soft0 , you can probably copy the code for the ComplexJSONFilterBackend into your project and it should work. I doubt this will get merged, this project isn't active.

@softzer0
Copy link

softzer0 commented May 7, 2020

What a shame. Maybe you should continue on this project from your fork and create a new pip package from it?
My workaround is that I have just specified your repository and branch (git+https://github.com/ferrants/django-rest-framework-filters.git@json-filter) in requirements file.

@softzer0
Copy link

softzer0 commented May 10, 2020

Hey @ferrants, it would be really nice if annotation exists along this filter. It would be then the complete solution.
For example, this:

User.objects.annotate(
  foo=Sum(Case(When(
      Q(history__action__name='argle') | Q(history__action__name='bargle'),
      history__since__lte=now,
      history__until__gte=now,
      then=1
  ), output_field=IntegerField()))
)

To be translated from this JSON query:

{
    "foo": {
        "type": "Sum",
        "value": {
            "type": "Case",
            "When": [
                {
                    "and": [
                        {
                            "or": [
                                {
                                    "history__action__name": "argle"
                                },
                                {
                                    "history__action__name": "bargle"
                                }
                            ]
                        },
                        {
                            "history__since__lte": "2020-05-10T09:50:54.018Z",
                            "history__until__gte": "2020-05-10T09:50:54.018Z"
                        }
                    ],
                    "then": 1
                }
            ],
            "output_field": "IntegerField"
        }
    }
}

@ferrants
Copy link
Contributor Author

@Soft0 , looks cool. Maybe you should make a library that would do this.

@softzer0
Copy link

Unfortunately I don't have much experience to work on it, that's why I proposed to you. Maybe if it's much needed in the future I would need to knock off some sloppy implementation. Until then I will stick to this and make annotation queries directly in the code of the view.

Copy link

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the small merge conflict. the works looks great

@pabrrs
Copy link

pabrrs commented Aug 5, 2022

Nice work on this!
Up 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants