The goal is to fill the page with at least 20 products and to fill all grid lines
Thus, the page should be filled with products until there are 20 products and all lines of the grid are full.
for p in products:
x = min(max(p.website_size_x, 1), PPR)
y = min(max(p.website_size_y, 1), PPR)
for p in products:
x = min(max(p.website_size_x, 1), PPR)
y = min(max(p.website_size_y, 1), PPR)
x = y = 1
pos = minpos
while not self._check_place(pos%PPR, pos/PPR, x, y):
pos += 1
x = y = 1
pos = minpos
while not self._check_place(pos%PPR, pos/PPR, x, y):
pos += 1
-
- if index>PPG and (pos/PPR)>maxy:
+ # if 21st products (index 20) and the last line is full (PPR products in it), break
+ # (pos + 1.0) / PPR is the line where the product would be inserted
+ # maxy is the number of existing lines
+ # + 1.0 is because pos begins at 0, thus pos 20 is actually the 21st block
+ # and to force python to not round the division operation
+ if index >= PPG and ((pos + 1.0) / PPR) > maxy:
break
if x==1 and y==1: # simple heuristic for CPU optimization
break
if x==1 and y==1: # simple heuristic for CPU optimization