From 0d6e20d5b594278e79716a07b4581801fc43065d Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Fri, 1 Jan 2016 00:33:40 -0600 Subject: [PATCH] web: hosts: HostList: Add filtering to GET method --- src/rouse/web/hosts.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/rouse/web/hosts.py b/src/rouse/web/hosts.py index d7d0c74..c4224a3 100644 --- a/src/rouse/web/hosts.py +++ b/src/rouse/web/hosts.py @@ -11,8 +11,22 @@ log = logging.getLogger(__name__) class HostListController(controllers.BaseController): def GET(self, request): + hosts = request.db.query(model.Host) + for attr in request.GET: + try: + column = model.Host.__table__.columns[attr] + except KeyError: + continue + for value in request.GET.getall(attr): + if not value: + continue + value = value.replace('%', r'\%') + if not value.endswith('*'): + value += '*' + value = value.replace('*', '%') + hosts = hosts.filter(column.like(value)) response = request.ResponseClass() - response.set_payload(None, request.db.query(model.Host).all()) + response.set_payload(None, hosts.all()) return response def POST(self, request):