def before_render(self, remainder, params, output): if not isinstance(output, dict) or not self.name in output: return collection = output[self.name] page = Page(collection, request.paginate_page, request.paginate_items_per_page, controller='/') page.kwargs = request.paginate_params if self.page_param != 'name': page.pager = partial(page.pager, page_param=self.page_param) if not getattr(tmpl_context, 'paginators', None): tmpl_context.paginators = Bunch() tmpl_context.paginators[self.name] = output[self.name] = page
def before_render(self, remainder, params, output): if not isinstance(output, dict) or not self.name in output: return paginator = request.paginators[self.name] collection = output[self.name] page = Page(collection, paginator.paginate_page, paginator.paginate_items_per_page) page.kwargs = paginator.paginate_params if self.page_param != 'name': page.pager = partial(page.pager, page_param=self.page_param) if not getattr(tmpl_context, 'paginators', None): tmpl_context.paginators = Bunch() tmpl_context.paginators[self.name] = output[self.name] = page
def _w(*args, **kwargs): page = int(kwargs.pop(own_parameters["page"], 1)) real_items_per_page = int( kwargs.pop(own_parameters['items_per_page'], items_per_page)) argvars = inspect.getargspec(f)[0][1:] if argvars: args = list(args) for i, var in enumerate(args): if i >= len(argvars): break var = argvars[i] if var in kwargs: args[i] = kwargs[var] del kwargs[var] res = f(*args, **kwargs) if isinstance(res, dict) and name in res: additional_parameters = MultiDict() for key, value in request.str_params.iteritems(): if key not in own_parameters: additional_parameters.add(key, value) collection = res[name] page = Page(collection, page, items_per_page=real_items_per_page, **additional_parameters.dict_of_lists()) # wrap the pager so that it will render # the proper page-parameter page.pager = partial(page.pager, page_param=own_parameters["page"]) res[name] = page # this is a bit strange - it appears # as if c returns an empty # string for everything it dosen't know. # I didn't find that documented, so I # just put this in here and hope it works. if not hasattr(c, 'paginators') or type(c.paginators) == str: c.paginators = Bunch() c.paginators[name] = page return res
def _w(*args, **kwargs): page = int(kwargs.pop(own_parameters["page"], 1)) real_items_per_page = int( kwargs.pop( own_parameters['items_per_page'], items_per_page)) # Iterate over all of the named arguments expected by the function f # if any of those arguments have values present in the kwargs dict, # add the value to the positional args list, and remove it from the # kwargs dict argvars = inspect.getargspec(f)[0][1:] if argvars: args = list(args) for i, var in enumerate(args): if i>=len(argvars): break; var = argvars[i] if var in kwargs: if i+1 >= len(args): args.append(kwargs[var]) else: args[i+1] = kargs[var] del kwargs[var] res = f(*args, **kwargs) if isinstance(res, dict) and name in res: additional_parameters = MultiDict() for key, value in request.str_params.iteritems(): if key not in own_parameters: additional_parameters.add(key, value) collection = res[name] # Use CustomPage if our extra custom arg was provided if items_first_page is not None: page_class = CustomPage else: page_class = Page page = page_class( collection, page, items_per_page=real_items_per_page, items_first_page=items_first_page, **additional_parameters.dict_of_lists() ) # wrap the pager so that it will render # the proper page-parameter page.pager = partial(page.pager, page_param=own_parameters["page"]) res[name] = page # this is a bit strange - it appears # as if c returns an empty # string for everything it dosen't know. # I didn't find that documented, so I # just put this in here and hope it works. if not hasattr(c, 'paginators') or type(c.paginators) == str: c.paginators = Bunch() c.paginators[name] = page return res