Skip to content
Snippets Groups Projects
Commit 475deb73 authored by chbaeh's avatar chbaeh
Browse files

add pagination and sort

parent 3d7a20ae
Branches
Tags sprint10
No related merge requests found
......@@ -101,11 +101,37 @@ class OdshGroupController(OrganizationController):
action = super(OdshGroupController, self)._action(name)
def custom_org_list(context, data_dict):
query = data_dict['q']
result = action(context, data_dict)
sort_desc = data_dict['sort'] == u'name desc'
d = data_dict.copy()
if 'offset' in d:
del d['offset']
del d['limit']
# print(data_dict)
if d["type"] is not 'organization':
return action(context, d)
all = d['all_fields']
query = d['q']
result = action(context, d)
seen = set([(r['id'] if all else r) for r in result])
for q in query.split(' '):
data_dict['q'] = q
result += action(context, data_dict)
d['q'] = q
ret = action(context, d)
for r in ret:
id = r['id'] if all else r
if id not in seen:
result.append(r)
seen.add(id)
if all:
result = sorted(
result, key=lambda k: k['name'], reverse=sort_desc)
else:
result = sorted(result, reverse=sort_desc)
if 'offset' in data_dict:
off = data_dict['offset']
limit = data_dict['limit']
return result[off:off+limit]
return result
if name is 'group_list':
......@@ -113,6 +139,7 @@ class OdshGroupController(OrganizationController):
else:
return super(OdshGroupController, self)._action(name)
class OdshApiController(ApiController):
def action(self, logic_function, ver=None):
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment