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

add translator between a predefined grammar and django's filter lookups #95

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

Conversation

juan-ignacio-sanchez
Copy link
Contributor

Description

Allows django drips to write simpler Human readable queries to be applied to Drips

Examples

Input: (enable is False) and (sent_drips null True) and (name is "Nacho's Drip")
Output: {'enabled': False, 'sent_drips__isnull': True, 'name': "Nacho's Drip"}

Usage

        input_expression = "(enabled is False) and (sent_drips null False)"
        filter = translate_query(input_expression, grammar)
        assert Drip.objects.filter(**filter).count() == 0

Changes include

  • New feature (non-breaking change that adds functionality)

Other comments

There is needed some work to include OR branching and stuff.

@juan-ignacio-sanchez juan-ignacio-sanchez requested a review from a team as a code owner December 24, 2020 01:28
@juan-ignacio-sanchez juan-ignacio-sanchez requested review from kaozdl and brunomichetti and removed request for a team December 24, 2020 01:28
@juan-ignacio-sanchez juan-ignacio-sanchez requested review from nsantos16 and removed request for kaozdl February 8, 2021 15:04
Copy link
Collaborator

@brunomichetti brunomichetti left a comment

Choose a reason for hiding this comment

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

Can you add a minor explanation in the README?

@@ -0,0 +1,26 @@
start : query
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you change " by ' in this file?

Comment on lines +12 to +18
operator_map = {
">": "__gt",
"<": "__lt",
"==": "__eq",
"is": "",
"null": "__isnull",
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question here: Can you change " by ' in this file?

from .parser import translate_query


class GrammarTest(TestCase):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same change here

%import common.WORD
%import common.NUMBER
%import common.ESCAPED_STRING
%ignore " "
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing blank line

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.

2 participants