def _dir(self, thing, reverse): ors = [] #for each sort add and a comparison operator for i in range(len(self._sort)): s = self._sort[i] if isinstance(s, operators.asc): op = operators.gt else: op = operators.lt if reverse: op = operators.gt if op == operators.lt else operators.lt #remember op takes lval and lval_name ands = [op(s.col, s.col, getattr(thing, s.col))] #for each sort up to the last add an equals operator for j in range(0, i): s = self._sort[j] ands.append(thing.c[s.col] == getattr(thing, s.col)) ors.append(operators.and_(*ands)) return self._filter(operators.or_(*ors))
def _dir(self, thing, reverse): ors = [] # this fun hack lets us simplify the query on /r/all # for postgres-9 compatibility. please remove it when # /r/all is precomputed. sorts = range(len(self._sort)) if self._filter_primary_sort_only: sorts = [0] #for each sort add and a comparison operator for i in sorts: s = self._sort[i] if isinstance(s, operators.asc): op = operators.gt else: op = operators.lt if reverse: op = operators.gt if op == operators.lt else operators.lt #remember op takes lval and lval_name ands = [op(s.col, s.col, getattr(thing, s.col))] #for each sort up to the last add an equals operator for j in range(0, i): s = self._sort[j] ands.append(thing.c[s.col] == getattr(thing, s.col)) ors.append(operators.and_(*ands)) return self._filter(operators.or_(*ors))