Skip to content

Commit

Permalink
add Filter.within to be able to integrate with postGIS' St_DWithin
Browse files Browse the repository at this point in the history
  • Loading branch information
philae-ael committed Apr 23, 2017
1 parent d7567e1 commit 0e24aa2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions opv_api_client/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class Filter:
To set those values, you can respectively use the `name` and `val`/`value` fonction to set those
"""
_url_modifier = 0
_eq = 1

def name(self, name):
"""Allow to set the name's field of the filter
Expand Down Expand Up @@ -37,11 +40,24 @@ def get(self):
Allow to get the final filter, in a form that can directly be used by the API
"""
if self._type == self._url_modifier:
return {"_url": self._url}

return {self._name: self._value}

@classmethod
def within(cls, ids, meters):
"""Returns a filter that allow to integrate with ST_within"""
f = cls()

f._type = cls._url_modifier
f._url = "/" + "/".join(map(str, ids)) + "/within/" + str(meters) # should use client._gen_id
return f

def __init__(self, name=None):
self._name = name
self._value = None
self._type = self._eq

__eq__ = value

Expand Down
2 changes: 2 additions & 0 deletions opv_api_client/restclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ def make_all(self, ressource, filters=None):
else:
params = dict()

url += str(params.pop("_url", ""))

r = requests.get(url, params=params)
if r.status_code != 200:
raise RequestAPIException("Can't get the list of ressources", response=r)
Expand Down

0 comments on commit 0e24aa2

Please sign in to comment.