Exemplo n.º 1
0
Arquivo: page.py Projeto: laginha/yard
 def paginate(self, resources, offset, number):
     '''
     Paginate the resources
     '''
     if is_generator( resources ):
         return self.paginate_generator(resources, offset, number)
     return resources[offset:offset+number]
Exemplo n.º 2
0
 def __init__(self, resources, page, params):
     self.resources = resources   
     self.params    = params
     self.page      = page 
     if is_generator(self.resources):
         self.total_objects     = self.__no_support
         self.paginated_objects = self.__paginated_list
     elif is_list(self.resources):
         self.total_objects     = self.__total_in_list
         self.paginated_objects = self.__paginated_list
Exemplo n.º 3
0
Arquivo: meta.py Projeto: laginha/yard
 def page_count(self):
     '''
     Get the number of objects paginated in the response
     '''
     if not hasattr(self, '_page_count'):
         if isinstance(self.page, (list, tuple)) or is_generator(self.resources):
             self._page_count = len( self.page )
         else:
             self._page_count = self.page.count()
     return self._page_count
Exemplo n.º 4
0
Arquivo: meta.py Projeto: laginha/yard
 def __init__(self, request, resources, page, params, pagination):
     self.request   = request
     self.resources = resources
     self.params    = params
     self.page      = page
     self.results_name = pagination.results_per_page['parameter']
     self.offset_name  = pagination.offset_parameter
     if is_generator(self.resources):
         self.total_objects = lambda: None
         self.previous_page = lambda: None
Exemplo n.º 5
0
 def handle_response(self, request, response, fields, parameters):
     '''
     Proccess response into a JSON serializable object
     '''
     current_fields = fields(kwargs) if callable(fields) else fields
     status = DEFAULT_STATUS_CODE
     if is_tuple(response):
         status, response = response
     if is_valuesset(response):
         response = self.handle_list_response(
             request, list(response), current_fields, parameters)
     elif is_queryset(response):
         response = self.select_related(response, current_fields)
         response = self.handle_queryset_response(
             request, response, current_fields, parameters)
     elif is_modelinstance(response):
         response = self.handle_model_response(response, current_fields)
     elif is_generator(response) or is_list(response):
         response = self.handle_list_response(
             request, response, current_fields, parameters)
     
     response = self.uglify_json(response) if self.uglify else response
     return to_http(request, response, status)
Exemplo n.º 6
0
 def __paginate(self, resources, offset, number):
     if is_generator(resources):
         return self.__paginate_generator(resources, offset, number)
     return resources[offset : offset + number]