Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested solution to 'yielder' problem in resources.py #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions grapi/backend/kopano/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def respond(self, req, resp, obj, all_fields=None, deltalink=None):
expand[field.split('/')[1]] = self.get_fields(req, obj2, resource.fields, resource.fields)
resp.body = self.json(req, obj, fields, all_fields, expand=expand)

def generator(self, req, generator, count=0, args=None):
def generator(self, req, generator, count=0, args=None, query=None, store=None):
"""Response generator.

It also determines pagination and ordering.
Expand All @@ -292,7 +292,12 @@ def generator(self, req, generator, count=0, args=None):
if order:
order = tuple(('-' if len(o.split()) > 1 and o.split()[1] == 'desc' else '') + o.split()[0] for o in order)

return generator(page_start=skip, page_limit=top, order=order), top, skip, count
if query is not None:
restriction = _query_to_restriction(query, 'message', store)
else:
restriction = None

return generator(page_start=skip, page_limit=top, restriction=restriction, order=order), top, skip, count

def create_message(self, folder, fields, all_fields=None, message_class=None):
# TODO item.update and/or only save in the end
Expand Down Expand Up @@ -333,10 +338,7 @@ def folder_gen(self, req, folder):

if '$search' in args:
query = args['$search'][0]

def yielder(**kwargs):
for item in folder.items(query=query):
yield item
return self.generator(req, yielder, 0, args=args)

return self.generator(req, folder.items, 0, args=args, query=query, store=folder.store)
else:
return self.generator(req, folder.items, folder.count, args=args)