Skip to content

Commit

Permalink
new paged approach for data handling
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Mar 26, 2015
1 parent 059b449 commit d04a7e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
21 changes: 5 additions & 16 deletions data/src/entity_manager/system.py
Expand Up @@ -2338,24 +2338,12 @@ def count(self, entity_class, options = None, lock = False, **kwargs):
return result

def find(self, entity_class, options = {}, lock = False, **kwargs):
# retrieves the start record and the number of records so that
# it's possible to infer if the current request is going to be
# paged or if a typical (eager) retrieval should be performed
start_record = options.get("start_record", 0)
number_records = options.get("number_records", 0)
allow_paged = options.get("paged", False)

# calculates the total number of records to be retrieved and
# then used the target page size calculates the number of pages
# and verifies if the requested should be paged or not
record_count = number_records - start_record
page_count = int(math.ceil(record_count / float(PAGE_SIZE)))
is_paged = page_count > 1 and allow_paged

# in case this is a paging situation the proper paging handler
# verifies if the current find operation is meant to be paged
# in case that's the request approach the proper paging handler
# must be used so that the values are properly yielded allowing
# a lazy base evaluation of the values from the entity manager
if is_paged: return self.page(
paged = options.get("paged", False)
if paged: return self.page(
entity_class,
options = options,
lock = lock,
Expand Down Expand Up @@ -2422,6 +2410,7 @@ def page(self, entity_class, options = {}, lock = False, **kwargs):
# that is going to be changed for each iteration and then
# initializes the current record value with the start record
_options = dict(options)
_options["paged"] = False
current_record = start_record

# iterates over the complete set of pages for the data set
Expand Down
7 changes: 7 additions & 0 deletions mvc/src/mvc_utils/entity_model.py
Expand Up @@ -739,6 +739,7 @@ def _class_create_filter(cls, data, defaults = {}, entity_manager = None):
name = defaults.get("name", None)
type_s = defaults.get("type", "both")
order_by = defaults.get("order_by", None)
paged = defaults.get("paged", False)
eager = defaults.get("eager", ())
allowed = defaults.get("allowed", ())
filters = defaults.get("filters", [])
Expand All @@ -748,6 +749,7 @@ def _class_create_filter(cls, data, defaults = {}, entity_manager = None):
# defaulting to the pre-defined default values
filter_string = data.get("filter_string", "")
sort = data.get("sort", None)
paged_s = data.get("paged", "0")
eager_s = data.get("eager", [])
filters_s = data.get("filters", [])
start_record = data.get("start_record", 0)
Expand All @@ -769,6 +771,10 @@ def _class_create_filter(cls, data, defaults = {}, entity_manager = None):
sort_value, sort_order = sort and sort.split(":", 1) or ("default", None)
order_by = not sort_value == "default" and ((sort_value, sort_order),) or order_by

# tries to retrieve the proper value for the paged element
# taking into account a possible boolean approach
paged = True if paged_s == "1" else False

def eager_r(eager_s):
# in case the eager sequence is not valid or empty
# or if the data type of the eager structure is not
Expand Down Expand Up @@ -933,6 +939,7 @@ def resolve_s(attribute):
filter = dict(
range = (start_record, number_records),
order_by = order_by or (),
paged = paged,
eager = eager,
filters = filters,
map = map
Expand Down

0 comments on commit d04a7e2

Please sign in to comment.