Skip to content

Commit

Permalink
Adding the possiblity for custom options
Browse files Browse the repository at this point in the history
  • Loading branch information
suhrawardi committed Apr 15, 2020
1 parent f2afea8 commit 4f06367
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions odata/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def __init__(self, session=None, auth=None):
self.log = logging.getLogger('odata.context')
self.connection = ODataConnection(session=session, auth=auth)

def query(self, entitycls):
q = Query(entitycls, connection=self.connection)
def query(self, entitycls, options=None):
q = Query(entitycls, connection=self.connection, options=options)
return q

def call(self, action_or_function, **parameters):
Expand Down
5 changes: 3 additions & 2 deletions odata/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Query(object):
def __init__(self, entitycls, connection=None, options=None):
self.entity = entitycls
self.options = options or dict()
self.default_opts = options
self.connection = connection

def __iter__(self):
Expand Down Expand Up @@ -98,7 +99,7 @@ def _get_options(self):
Format current query options to a dict that can be passed to requests
:return: Dictionary
"""
options = dict()
options = self.options

_top = self.options.get('$top')
if _top is not None:
Expand Down Expand Up @@ -149,7 +150,7 @@ def _new_query(self):
:return: Query instance
"""
o = dict()
o = self.default_opts or dict()
o['$top'] = self.options.get('$top', None)
o['$skip'] = self.options.get('$skip', None)
o['$select'] = self.options.get('$select', [])[:]
Expand Down
4 changes: 2 additions & 2 deletions odata/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ def is_entity_saved(self, entity):
"""Returns boolean indicating entity's status"""
return self.default_context.is_entity_saved(entity)

def query(self, entitycls):
def query(self, entitycls, options=None):
"""
Start a new query for given entity class
:param entitycls: Entity to query
:return: Query object
"""
return self.default_context.query(entitycls)
return self.default_context.query(entitycls, options=options)

def delete(self, entity):
"""
Expand Down

0 comments on commit 4f06367

Please sign in to comment.