Commit 249c3327 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

astakos: Filter with GET params in project API

Pass GET options in project API calls as GET parameters rather than a json
body.
parent c7da4899
...@@ -825,11 +825,11 @@ class AstakosClient(object): ...@@ -825,11 +825,11 @@ class AstakosClient(object):
filters["owner"] = owner filters["owner"] = owner
if mode is not None: if mode is not None:
filters["mode"] = mode filters["mode"] = mode
path = self.api_projects
if filters:
path += "?" + urllib.urlencode(filters)
req_headers = {'content-type': 'application/json'} req_headers = {'content-type': 'application/json'}
req_body = (parse_request({"filter": filters}, self.logger) return self._call_astakos(path, headers=req_headers)
if filters else None)
return self._call_astakos(self.api_projects,
headers=req_headers, body=req_body)
# ----------------------------------------- # -----------------------------------------
# do a GET to ``API_PROJECTS``/<project_id> # do a GET to ``API_PROJECTS``/<project_id>
...@@ -931,10 +931,13 @@ class AstakosClient(object): ...@@ -931,10 +931,13 @@ class AstakosClient(object):
In case of success, return a list of membership descriptions. In case of success, return a list of membership descriptions.
""" """
req_headers = {'content-type': 'application/json'} req_headers = {'content-type': 'application/json'}
body = {"project": project} if project is not None else None filters = {}
req_body = parse_request(body, self.logger) if body else None if project is not None:
return self._call_astakos(self.api_memberships, filters["project"] = project
headers=req_headers, body=req_body) path = self.api_memberships
if filters:
path += '?' + urllib.urlencode(filters)
return self._call_astakos(path, headers=req_headers)
# ----------------------------------------- # -----------------------------------------
# do a GET to ``API_MEMBERSHIPS``/<memb_id> # do a GET to ``API_MEMBERSHIPS``/<memb_id>
......
...@@ -279,9 +279,12 @@ def projects(request): ...@@ -279,9 +279,12 @@ def projects(request):
@transaction.commit_on_success @transaction.commit_on_success
def get_projects(request): def get_projects(request):
user = request.user user = request.user
input_data = read_json_body(request, default={}) filters = {}
filters = input_data.get("filter", {}) for key in PROJECT_QUERY.keys():
mode = input_data.get("mode", "default") value = request.GET.get(key)
if value is not None:
filters[key] = value
mode = request.GET.get("mode", "default")
query = make_project_query(filters) query = make_project_query(filters)
projects = _get_projects(query, mode=mode, request_user=user) projects = _get_projects(query, mode=mode, request_user=user)
data = get_projects_details(projects, request_user=user) data = get_projects_details(projects, request_user=user)
...@@ -619,8 +622,7 @@ def make_membership_query(input_data): ...@@ -619,8 +622,7 @@ def make_membership_query(input_data):
@transaction.commit_on_success @transaction.commit_on_success
def get_memberships(request): def get_memberships(request):
user = request.user user = request.user
input_data = read_json_body(request, default={}) query = make_membership_query(request.GET)
query = make_membership_query(input_data)
memberships = _get_memberships(query, request_user=user) memberships = _get_memberships(query, request_user=user)
data = get_memberships_details(memberships, user) data = get_memberships_details(memberships, user)
return json_response(data) return json_response(data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment