def filter(self, leaf, *va, **kw):
		rsp = leaf(*va, **kw)
		if self.parameter in rsp:
			q = rsp[self.parameter]
		else:
			q = self.entity.query
		if not q:
			return rsp
		sort = kw.get(self.kwprefix+'sort', self.sortdefault)
		order = kw.get(self.kwprefix+'order', self.orderdefault)
		if sort:
			sort_key = getattr(self.entity, sort)
			if order == 'desc':
				q = q.order_by(sql.desc(sort_key))
			else:
				q = q.order_by(sort_key)
		rsp.update({
			self.parameter: q.all(),
			self.kwprefix+'sort': sort,
			self.kwprefix+'order': order,
			self.kwprefix+'inverse_order': ('desc','asc')[int(order=='desc')]
		})
		return rsp
dataset/ETHPy150Open rsms/smisk/lib/smisk/mvc/filters.py/sortable_entities.filter/original