Get a field to sort by
174430
def get_sortkey(table):
    
    # Just pick the first column in the table in alphabetical order.
    # Ideally we would get the primary key from bcdc api, but it doesn't
    # seem to be available
    wfs = WebFeatureService(url=bcdata.OWS_URL, version="2.0.0")
    return sorted(wfs.get_schema("pub:" + table)["properties"].keys())[0]
1093678
def order_by(self, field_name=None):
        
        assert self.query.can_filter(), "Cannot reorder a query once a slice has been taken."

        clone = self._clone()
        clone.query.clear_ordering()

        if field_name is not None:
            clone.query.add_ordering(field_name)

        return clone
948069
public function sort_by_many_fields($a, $b) {
        foreach ($this->sortfields as $field => $mult) {
            // Nulls first.
            if (is_null($a->$field) && !is_null($b->$field)) {
                return -$mult;
            }
            if (is_null($b->$field) && !is_null($a->$field)) {
                return $mult;
            }

            if (is_string($a->$field) || is_string($b->$field)) {
                // String fields.
                if ($cmp = strcoll($a->$field, $b->$field)) {
                    return $mult * $cmp;
                }
            } else {
                // Int fields.
                if ($a->$field > $b->$field) {
                    return $mult;
                }
                if ($a->$field < $b->$field) {
                    return -$mult;
                }
            }
        }
        return 0;
    }
385675
public static function GetSortField() {
      $SortField = C('Vanilla.Discussions.SortField', 'd.DateLastComment');
      if (C('Vanilla.Discussions.UserSortField'))
         $SortField = Gdn::Session()->GetPreference('Discussions.SortField', $SortField);
      
      return $SortField;  
   }
137416
public function order($field, $order = null, $intSort = true)
    {
        return $this->sort(function ($a, $b) use ($field, $order, $intSort) {
            $fieldA = isset($a[$field]) ? $a[$field] : null;
            $fieldB = isset($b[$field]) ? $b[$field] : null;

            if ($intSort) {
                return 'desc' == strtolower($order) ? $fieldB >= $fieldA : $fieldA >= $fieldB;
            } else {
                return 'desc' == strtolower($order) ? strcmp($fieldB, $fieldA) : strcmp($fieldA, $fieldB);
            }
        });
    }
933381
public function sort ()
    {
        usort($this->_fields,
              function (Field $fieldA, Field $fieldB) {
              return strcmp($fieldA->getShorthand(), $fieldB->getShorthand());
          });
    }
770328
def _transform_field(field):
    """"""
    if isinstance(field, bool):
        return TRUE if field else FALSE
    elif isinstance(field, (list, dict)):
        return json.dumps(field, sort_keys=True, ensure_ascii=False)
    else:
        return field
42103
def get_next_sort_string(self, field):
        
        # self.sort_field is the currect sort field
        if field == self.sort_field:
            next_sort = self.toggle_sort_order() + field
        else:
            default_order_for_field = \
                self._allowed_sort_fields[field]['default_direction']
            next_sort = default_order_for_field + field
        return self.get_sort_string(next_sort)
80416
def get_date_field(datetimes, field):
    """"""
    return np.array([getattr(date, field) for date in datetimes])
413117
public function getSortField()
    {
        if ($this->_sortField === false) {
            return [];
        }

        if ($this->_sortField) {
            // 
            if (is_array($this->_sortField)) {
                return [$this->name => $this->_sortField];
            } 

            return [$this->name => [
                'asc' => [$this->_sortField => SORT_ASC],
                'desc' => [$this->_sortField => SORT_DESC]
            ]];
        }
        
        return [$this->name];
    }
321875
def order_by(self, *orderings: str) -> "QuerySet":
        
        queryset = self._clone()
        new_ordering = []
        for ordering in orderings:
            order_type = Order.asc
            if ordering[0] == "-":
                field_name = ordering[1:]
                order_type = Order.desc
            else:
                field_name = ordering

            if not (
                field_name.split("__")[0] in self.model._meta.fields
                or field_name in self._annotations
            ):
                raise FieldError(
                    "Unknown field {} for model {}".format(field_name, self.model.__name__)
                )
            new_ordering.append((field_name, order_type))
        queryset._orderings = new_ordering
        return queryset
1245481
public static Sort sort(String field, boolean asc) {
        Sort s = new Sort(false);
        s.add(field, asc ? "$asc" : "$desc");
        return s;
    }
418101
def order_by(self, field, orientation='ASC'):
        
        if isinstance(field, list):
            self.raw_order_by.append(field)
        else:
            self.raw_order_by.append([field, orientation])

        return self
197240
def order_by(self, *field_names):
        
        if not self._search_ordered:
            self._search_ordered = len(self._search_terms) > 0
        return super(SearchableQuerySet, self).order_by(*field_names)
1143801
function sortFieldsByIndex(userFields, index) {
  var indexFields = index.def.fields.map(getKey);

  return userFields.slice().sort(function (a, b) {
    var aIdx = indexFields.indexOf(a);
    var bIdx = indexFields.indexOf(b);
    if (aIdx === -1) {
      aIdx = Number.MAX_VALUE;
    }
    if (bIdx === -1) {
      bIdx = Number.MAX_VALUE;
    }
    return utils.compare(aIdx, bIdx);
  });
}
881323
function sortBy(srcArr, field, isDesc) {
      return srcArr.slice().sort(function (row1, row2) {
        var rst1 = get(row1, field), rst2 = get(row2, field);
        if (rst1 !== 0 && !rst1) {
          return isDesc ? 1 : -1;
        } else if (rst2 !== 0 && !rst2) {
          return isDesc ? -1 : 1;
        } else if (rst1 === rst2) {
          return 0;
        } else {
          return (rst1 > rst2) ? (isDesc ? -1 : 1) : (isDesc ? 1 : -1);
        }
      });
    }
1037052
def _get_ordering_field_lookup(self, field_name):
        
        field = field_name
        get_field = getattr(self, "get_%s_ordering_field" % field_name, None)
        if get_field:
            field = get_field()
        return field