
def default_pagination_params(limit=None, offset=None, sort=None):
    """Returns default params unless they are set"""
    if limit is None:
        limit = 25
    if offset is None:
        offset = 0
    if sort is None:
        sort = [('_id', -1)]

    return limit, offset, sort

def parse_pagination_params(params):
    """Parse params and get (limit, offset, sort)
    The defaults will be returned if not found in params.
    """
    # Defaults
    limit, offset, sort = default_pagination_params()
    if params:
        if 'limit' in params:
            limit = int(params['limit'])
        if 'offset' in params:
            offset = int(params['offset'])
        if 'sort' in params and 'sortdir' in params:
            sort = [(params['sort'], int(params['sortdir']))]

    return limit, offset, sort


def search_results_dict(results, limit, offset, sort):
    """This is for consistent search results"""
    ret = {
        'matches': len(results),
        'limit': limit,
        'offset': offset,
        'results': results
    }
    return ret

from girder.constants import SortDir

def default_pagination_params(limit=None, offset=None, sort=None):
    """Returns default params unless they are set"""
    if limit is None:
        limit = 25
    if offset is None:
        offset = 0
    if sort is None:
        sort = [('_id', SortDir.DESCENDING)]

    return limit, offset, sort

def parse_pagination_params(params):
    """Parse params and get (limit, offset, sort)
    The defaults will be returned if not found in params.
    """
    # Defaults
    limit, offset, sort = default_pagination_params()
    if params:
        if 'limit' in params:
            limit = int(params['limit'])
        if 'offset' in params:
            offset = int(params['offset'])
        if 'sort' in params and 'sortdir' in params:
            sort = [(params['sort'], int(params['sortdir']))]

    return limit, offset, sort


def search_results_dict(results, limit, offset, sort):
    """This is for consistent search results"""
    ret = {
        'matches': len(results),
        'limit': limit,
        'offset': offset,
        'results': results
    }
    return ret

Use SortDir.DESCENDING for default sort direction
Use SortDir.DESCENDING for default sort direction

Signed-off-by: Patrick Avery <743342299f279e7a8c3ff5eb40671fce3e95f13a@kitware.com>

+ from girder.constants import SortDir
  
  def default_pagination_params(limit=None, offset=None, sort=None):
      """Returns default params unless they are set"""
      if limit is None:
          limit = 25
      if offset is None:
          offset = 0
      if sort is None:
-         sort = [('_id', -1)]
+         sort = [('_id', SortDir.DESCENDING)]
  
      return limit, offset, sort
  
  def parse_pagination_params(params):
      """Parse params and get (limit, offset, sort)
      The defaults will be returned if not found in params.
      """
      # Defaults
      limit, offset, sort = default_pagination_params()
      if params:
          if 'limit' in params:
              limit = int(params['limit'])
          if 'offset' in params:
              offset = int(params['offset'])
          if 'sort' in params and 'sortdir' in params:
              sort = [(params['sort'], int(params['sortdir']))]
  
      return limit, offset, sort
  
  
  def search_results_dict(results, limit, offset, sort):
      """This is for consistent search results"""
      ret = {
          'matches': len(results),
          'limit': limit,
          'offset': offset,
          'results': results
      }
      return ret
  
Use SortDir.DESCENDING for default sort direction
## Code Before:

def default_pagination_params(limit=None, offset=None, sort=None):
    """Returns default params unless they are set"""
    if limit is None:
        limit = 25
    if offset is None:
        offset = 0
    if sort is None:
        sort = [('_id', -1)]

    return limit, offset, sort

def parse_pagination_params(params):
    """Parse params and get (limit, offset, sort)
    The defaults will be returned if not found in params.
    """
    # Defaults
    limit, offset, sort = default_pagination_params()
    if params:
        if 'limit' in params:
            limit = int(params['limit'])
        if 'offset' in params:
            offset = int(params['offset'])
        if 'sort' in params and 'sortdir' in params:
            sort = [(params['sort'], int(params['sortdir']))]

    return limit, offset, sort


def search_results_dict(results, limit, offset, sort):
    """This is for consistent search results"""
    ret = {
        'matches': len(results),
        'limit': limit,
        'offset': offset,
        'results': results
    }
    return ret

## Instruction:
Use SortDir.DESCENDING for default sort direction
## Code After:
from girder.constants import SortDir

def default_pagination_params(limit=None, offset=None, sort=None):
    """Returns default params unless they are set"""
    if limit is None:
        limit = 25
    if offset is None:
        offset = 0
    if sort is None:
        sort = [('_id', SortDir.DESCENDING)]

    return limit, offset, sort

def parse_pagination_params(params):
    """Parse params and get (limit, offset, sort)
    The defaults will be returned if not found in params.
    """
    # Defaults
    limit, offset, sort = default_pagination_params()
    if params:
        if 'limit' in params:
            limit = int(params['limit'])
        if 'offset' in params:
            offset = int(params['offset'])
        if 'sort' in params and 'sortdir' in params:
            sort = [(params['sort'], int(params['sortdir']))]

    return limit, offset, sort


def search_results_dict(results, limit, offset, sort):
    """This is for consistent search results"""
    ret = {
        'matches': len(results),
        'limit': limit,
        'offset': offset,
        'results': results
    }
    return ret
