forked from shunyeka/jQuery-QueryBuilder-Python-Evaluator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPKG-INFO
More file actions
168 lines (154 loc) · 5.75 KB
/
PKG-INFO
File metadata and controls
168 lines (154 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
Metadata-Version: 2.1
Name: jqqb
Version: 0.0.3
Summary: Python parsing, evaluation and inspection tools for jQuery-QueryBuilder rules
Home-page: https://github.com/Connecting-Food/jQueryQueryBuilder
Author: Connecting Food
Author-email: developers@connecting-food.com
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
# jQueryQueryBuilder
Python Rule evaluator for jQuery-QueryBuilder. It evaluates rules agains provided objects.
[Website](http://www.shunyeka.com) • [autobotAI Cloud Governance](https://autobot.live/)
Inspired from [SixiS/jquery_query_builder-rails](https://github.com/SixiS/jquery_query_builder-rails)
## Usage
Install the package.
```
pip install jqqb
```
Usage Example:
```python
from jqqb import QueryBuilder
rule_json = {
"condition": "AND",
"rules": [{
"id": "tagname",
"field": "tags.name",
"type": "string",
"input": "text",
"operator": "not_contains",
"value": "production"
}, {
"id": "tagname",
"field": "tags.name",
"type": "string",
"input": "text",
"operator": "begins_with",
"value": "development"
}, {
"condition": "OR",
"rules": [{
"id": "type",
"field": "type",
"type": "string",
"input": "text",
"operator": "equal",
"value": "ec2"
},{
"id": "type",
"field": "type",
"type": "string",
"input": "text",
"operator": "equal",
"value": "ami"
}]
}]
}
evaluator = QueryBuilder(rule_json)
object_1 = {'type': "ec2", "tags": [{"name": "hello"}, {"name": "asdfasfproduction_instance"}]}
object_2 = {'type': "ami", "tags": [{"name": "development"}, {"name": "asfdafdroduction_instance"}, {"name": "proction"}]}
objects = [object_1, object_2]
print(evaluator.match_objects(objects))
print(evaluator.inspect_objects(objects))
```
Result:
```python
[{'type': 'ami', 'tags': [{'name': 'development'}, {'name': 'asfdafdroduction_instance'}, {'name': 'proction'}]}]
[
{
'object': {'type': 'ec2', 'tags': [{'name': 'hello'}, {'name': 'asdfasfproduction_instance'}]},
'selected': False,
'results': [
(
{'id': 'tagname', 'field': 'tags.name', 'type': 'string', 'input': 'text', 'operator': 'not_contains', 'value': 'production'},
(['hello', 'asdfasfproduction_instance'], 'production', False)
),
(
{'id': 'tagname', 'field': 'tags.name', 'type': 'string', 'input': 'text', 'operator': 'begins_with', 'value': 'development'},
(['hello', 'asdfasfproduction_instance'], 'development', False)
),
(
{
'condition': 'OR',
'rules': [
{
'id': 'type',
'field': 'type',
'type': 'string',
'input': 'text',
'operator': 'equal',
'value': 'ec2'
}, {
'id': 'type',
'field': 'type',
'type': 'string',
'input': 'text',
'operator': 'equal',
'value': 'ami'
}
]
},
[
(
{'id': 'type', 'field': 'type', 'type': 'string', 'input': 'text', 'operator': 'equal', 'value': 'ec2'},
('ec2', 'ec2', True)
),
(
{'id': 'type', 'field': 'type', 'type': 'string', 'input': 'text', 'operator': 'equal', 'value': 'ami'},
('ec2', 'ami', False)
)
]
)
]
},
{
'object': {'type': 'ami', 'tags': [{'name': 'development'}, {'name': 'asfdafdroduction_instance'}, {'name': 'proction'}]},
'selected': True,
'results': [
(
{'id': 'tagname', 'field': 'tags.name', 'type': 'string', 'input': 'text', 'operator': 'not_contains', 'value': 'production'},
(
['development', 'asfdafdroduction_instance', 'proction'], 'production', True
)
), (
{'id': 'tagname', 'field': 'tags.name', 'type': 'string', 'input': 'text', 'operator': 'begins_with', 'value': 'development'},
(
['development', 'asfdafdroduction_instance', 'proction'], 'development', True
)
), (
{
'condition': 'OR',
'rules': [
{'id': 'type', 'field': 'type', 'type': 'string', 'input': 'text', 'operator': 'equal', 'value': 'ec2'},
{'id': 'type', 'field': 'type', 'type': 'string', 'input': 'text', 'operator': 'equal', 'value': 'ami'}
]
}, [
(
{'id': 'type', 'field': 'type', 'type': 'string', 'input': 'text', 'operator': 'equal', 'value': 'ec2'},
('ami', 'ec2', False)
), (
{'id': 'type', 'field': 'type', 'type': 'string', 'input': 'text', 'operator': 'equal', 'value': 'ami'},
('ami', 'ami', True)
)
]
)
]
}
]
```