code: def extract_sort(self, params):
          '''Extract and build sort query from parameters'''
          sorts = params.pop('sort', [])
          sorts = [sorts] if isinstance(sorts, basestring) else sorts
          sorts = [(s[1:], 'desc')
                   if s.startswith('-') else (s, 'asc')
                   for s in sorts]
          self.sorts = [
              {self.adapter.sorts[s]: d}
              for s, d in sorts if s in self.adapter.sorts
          ]