Generate a MongoDB sort order list using the Django ORM style.
489545
def S(Document, *fields):
	""""""
	
	result = []
	
	for field in fields:
		if isinstance(field, tuple):  # Unpack existing tuple.
			field, direction = field
			result.append((field, direction))
			continue
		
		direction = ASCENDING
		
		if not field.startswith('__'):
			field = field.replace('__', '.')
		
		if field[0] == '-':
			direction = DESCENDING
		
		if field[0] in ('+', '-'):
			field = field[1:]
		
		_field = traverse(Document, field, default=None)
		
		result.append(((~_field) if _field else field, direction))
	
	return result
394093
function sortBy(collection, evaluator) {
        var array = map(collection, function(item){return item})
        array.sort(function(a,b){
          var aValue = evaluator(a),
              bValue = evaluator(b)
          return aValue==bValue ? 0 : (aValue>bValue ? 1 : -1)
        })
        var sortedCollection = map(array, function(item){return item}, features.newCollection, features.append)
        return sortedCollection
      }
188689
def _sortObjects(orderby='created', **kwargs):
    """"""
    o = []
    
    for m in kwargs.values():
        for l in iter(m):
            o.append(l)
    o = list(set(o))
    sortfunc = _sortByCreated if orderby == 'created' else _sortByModified
    if six.PY2:
        o.sort(sortfunc)
    else:
        o.sort(key=functools.cmp_to_key(sortfunc))

    return o
638040
def dict2orderedlist(dic, order_list, default='', **kwargs):
    
    result = []
    for key_order in order_list:
        value = get_element(dic, key_order, **kwargs)
        result.append(value if value is not None else default)
    return result
78606
def gen_ordered_statistics(transaction_manager, record):
    
    items = record.items
    for combination_set in combinations(sorted(items), len(items) - 1):
        items_base = frozenset(combination_set)
        items_add = frozenset(items.difference(items_base))
        confidence = (
            record.support / transaction_manager.calc_support(items_base))
        lift = confidence / transaction_manager.calc_support(items_add)
        yield OrderedStatistic(
            frozenset(items_base), frozenset(items_add), confidence, lift)
1219809
def order_by_raw(self, sql, bindings=None):
        
        if bindings is None:
            bindings = []

        type = "raw"

        self.orders.append({"type": type, "sql": sql})

        self.add_binding(bindings, "order")

        return self
786990
def _sorted_keys_items(dobj):
    """"""
    keys = sorted(dobj.keys())
    for key in keys:
        yield key, dobj[key]
654293
def get_ordering(self, *args, **kwargs):
        """"""
        result = super(SequenceCursorPagination, self).get_ordering(*args, **kwargs)

        # Because paginate_queryset sets self.ordering after reading it...we
        # need to only modify it sometimes. (This allows re-use of the
        # paginator, which probably only happens in tests.)
        if result[0] != '#':
            result = ('#', ) + result

        return result
347867
def sort(records: Sequence[Record]) -> List[Record]:
    ""
    return sorted(records, key=_record_key)
994174
def _order_queries(self):
        """"""
        from .condition import Order
        order = []
        for column in self.columns:
            if column.order_by:
                o = Order(self.cls, column.attr, column.order_by)
                order.append(o.__query__())
        if not order:
            k = self.columns[0].attr
            o = Order(self.cls, k)
            self.columns[0].order_by = o.order
            order.append(o.__query__())
        return order
473919
def _sort_schema(schema):
    """"""

    if isinstance(schema, dict):
        for k, v in sorted(schema.items()):
            if isinstance(v, dict):
                yield k, OrderedDict(_sort_schema(v))
            elif isinstance(v, list):
                yield k, list(_sort_schema(v))
            else:
                yield k, v
    elif isinstance(schema, list):
        for v in schema:
            if isinstance(v, dict):
                yield OrderedDict(_sort_schema(v))
            elif isinstance(v, list):
                yield list(_sort_schema(v))
            else:
                yield v
    else:
        yield d
686450
def get_orders(self):
        ''''''
        orders = []
        iSortingCols = self.dt_data['iSortingCols']
        dt_orders = [(self.dt_data['iSortCol_%s' % i], self.dt_data['sSortDir_%s' % i]) for i in xrange(iSortingCols)]
        for field_idx, field_dir in dt_orders:
            direction = '-' if field_dir == DESC else ''
            if hasattr(self, 'sort_col_%s' % field_idx):
                method = getattr(self, 'sort_col_%s' % field_idx)
                result = method(direction)
                if isinstance(result, (bytes, text_type)):
                    orders.append(result)
                else:
                    orders.extend(result)
            else:
                field = self.get_field(field_idx)
                if RE_FORMATTED.match(field):
                    tokens = RE_FORMATTED.findall(field)
                    orders.extend(['%s%s' % (direction, token) for token in tokens])
                else:
                    orders.append('%s%s' % (direction, field))
        return orders
578166
def get_ordering(self):
        """"""
        if self.sorting_field:
            return [self.sorting_field]
        prefix = self.get_prefix()
        fields = self.get_ordering_with_prefix()
        if self.prefix:
            fields = [f.replace(prefix, "", 1) for f in fields]
        return [
            f
            for f in fields
            if f.lstrip("-") in self.get_ordering_fields_lookups()
        ]
581853
def model_to_list(model_class, filter_dict=None, order_by_list=None,
                  select_related_fields=None, q_filter=None,
                  values=None,
                  to_json_method='to_json'):
    
    return model_to_page_list(model_class, page_num=None,
                              filter_dict=filter_dict, order_by_list=order_by_list,
                              select_related_fields=select_related_fields,
                              q_filter=q_filter, values=values,
                              to_json_method=to_json_method)
57999
def sort_query(self, query, sort_info):
        
        for sort_opt in sort_info:
            field = sort_opt['field']
            if not hasattr(self.model, field):
                raise InvalidSort("{} has no attribute {}".format(self.model.__name__, field))
            query = query.order_by(getattr(getattr(self.model, field), sort_opt['order'])())
        return query
1354399
def gen_ordered(self):
        
        run = None
        for idx, (op_type, operation) in enumerate(self.ops):
            if run is None:
                run = _Run(op_type)
            elif run.op_type != op_type:
                yield run
                run = _Run(op_type)
            run.add(idx, operation)
        yield run
821156
function( json, field, params, callback ){
    field = field || 'id';
    var objectIds = [],
      props;

    if (params.orderByFields && params.orderByFields !== ''){
      var fld = params.orderByFields.split(' ');
      var order = params.orderByFields;
      if (fld[fld.length-1] == 'DESC'){
        order = '-' + params.orderByFields;
      }
      json.features = this.orderBy(json.features, params.orderByFields, order);
    }

    json.features.forEach( function(f){
      props = f.attributes || f.properties;
      objectIds.push( props[ field ] );
    });

    callback( null, {
      objectIdField: field,
      objectIds: objectIds
    });
  }