Skip to content

Commit 2e7cfff

Browse files
author
Evan Borgstrom
committed
Support filters
1 parent d52c42c commit 2e7cfff

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

xero/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,23 @@ def get_filter_params():
222222
return '"%s"' % str(kwargs[key])
223223

224224
def generate_param(key):
225-
return '%s==%s' % (
226-
key.replace('_','.'),
225+
parts = key.split("__")
226+
field = key.replace('_','.'),
227+
fmt = '%s==%s'
228+
if len(parts) == 2:
229+
# support filters:
230+
# Name__Contains=John becomes Name.Contains("John")
231+
if parts[1] in ["Contains", "StartsWith", "EndsWith"]:
232+
field = parts[0]
233+
fmt = ''.join(['%s.', parts[1], '(%s)'])
234+
235+
return fmt % (
236+
field,
227237
get_filter_params()
228238
)
229239

230240
params = [generate_param(key) for key in kwargs.keys()]
241+
print params
231242

232243
if params:
233244
uri += '?where=' + urllib.quote('&&'.join(params))

0 commit comments

Comments
 (0)