MCPcopy Index your code
hub / github.com/MongoEngine/mongoengine / _get_order_by

Method _get_order_by

mongoengine/queryset/base.py:1946–1979  ·  view source on GitHub ↗

Given a list of MongoEngine-style sort keys, return a list of sorting tuples that can be applied to a PyMongo cursor. For example: >>> qs._get_order_by(['-last_name', 'first_name']) [('last_name', -1), ('first_name', 1)]

(self, keys)

Source from the content-addressed store, hash-verified

1944 return db_field_paths
1945
1946 def _get_order_by(self, keys):
1947 """Given a list of MongoEngine-style sort keys, return a list
1948 of sorting tuples that can be applied to a PyMongo cursor. For
1949 example:
1950
1951 >>> qs._get_order_by(['-last_name', 'first_name'])
1952 [('last_name', -1), ('first_name', 1)]
1953 """
1954 key_list = []
1955 for key in keys:
1956 if not key:
1957 continue
1958
1959 if key == "$text_score":
1960 key_list.append(("_text_score", {"$meta": "textScore"}))
1961 continue
1962
1963 direction = pymongo.ASCENDING
1964 if key[0] == "-":
1965 direction = pymongo.DESCENDING
1966
1967 if key[0] in ("-", "+"):
1968 key = key[1:]
1969
1970 key = key.replace("__", ".")
1971 try:
1972 key = self._document._translate_field_name(key)
1973 except Exception:
1974 # TODO this exception should be more specific
1975 pass
1976
1977 key_list.append((key, direction))
1978
1979 return key_list
1980
1981 def _get_scalar(self, doc):
1982 def lookup(obj, name):

Callers 2

_cursorMethod · 0.95
order_byMethod · 0.80

Calls 2

replaceMethod · 0.80
_translate_field_nameMethod · 0.80

Tested by

no test coverage detected