def _normalize_sort_SQL(self, field_name, field_vals, sort_dir_str):
fvi = None<EOL>if sort_dir_str == '<STR_LIT>':<EOL><INDENT>fvi = (t for t in enumerate(field_vals)) <EOL><DEDENT>else:<EOL><INDENT>fvi = (t for t in enumerate(reversed(field_vals))) <EOL><DEDENT>query_sort_str = ['<STR_LIT>'.format(self._normalize_name(field_name))]<EOL>query_args = []<EOL>for i, v in fvi:<EOL><INDENT>query_sort_str.append('<STR_LIT>'.format(self.val_placeholder, i))<EOL>query_args.append(v)<EOL><DEDENT>query_sort_str.append('<STR_LIT>')<EOL>query_sort_str = "<STR_LIT:\n>".join(query_sort_str)<EOL>return query_sort_str, query_args<EOL>
allow sorting by a set of values

http://stackoverflow.com/questions/3303851/sqlite-and-custom-order-by