Skip to content

Commit 0e24aa2

Browse files
committed
add Filter.within to be able to integrate with postGIS' St_DWithin
1 parent d7567e1 commit 0e24aa2

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

opv_api_client/filter.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class Filter:
77
To set those values, you can respectively use the `name` and `val`/`value` fonction to set those
88
99
"""
10+
_url_modifier = 0
11+
_eq = 1
12+
1013
def name(self, name):
1114
"""Allow to set the name's field of the filter
1215
@@ -37,11 +40,24 @@ def get(self):
3740
3841
Allow to get the final filter, in a form that can directly be used by the API
3942
"""
43+
if self._type == self._url_modifier:
44+
return {"_url": self._url}
45+
4046
return {self._name: self._value}
4147

48+
@classmethod
49+
def within(cls, ids, meters):
50+
"""Returns a filter that allow to integrate with ST_within"""
51+
f = cls()
52+
53+
f._type = cls._url_modifier
54+
f._url = "/" + "/".join(map(str, ids)) + "/within/" + str(meters) # should use client._gen_id
55+
return f
56+
4257
def __init__(self, name=None):
4358
self._name = name
4459
self._value = None
60+
self._type = self._eq
4561

4662
__eq__ = value
4763

opv_api_client/restclient.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ def make_all(self, ressource, filters=None):
219219
else:
220220
params = dict()
221221

222+
url += str(params.pop("_url", ""))
223+
222224
r = requests.get(url, params=params)
223225
if r.status_code != 200:
224226
raise RequestAPIException("Can't get the list of ressources", response=r)

0 commit comments

Comments
 (0)