return a response_dict  with a list of search results in decending
    order based on a sort key
974605
def query_mongo_sort_decend(
        database_name,
        collection_name,
        query={},
        skip=0,
        limit=getattr(
            settings,
            'MONGO_LIMIT',
            200),
    return_keys=(),
        sortkey=None):
    

    l = []
    response_dict = {}

    try:
        mongodb_client_url = getattr(settings, 'MONGODB_CLIENT',
                                     'mongodb://localhost:27017/')
        mc = MongoClient(mongodb_client_url,document_class=OrderedDict)

        db = mc[str(database_name)]
        collection = db[str(collection_name)]

        if return_keys:
            return_dict = {}
            for k in return_keys:
                return_dict[k] = 1
            # print "returndict=",return_dict
            mysearchresult = collection.find(
                query, return_dict).skip(skip).limit(limit).sort(
                sortkey, DESCENDING)
        else:
            mysearchresult = collection.find(query).skip(
                skip).limit(limit).sort(sortkey, DESCENDING)

        # response_dict['num_results']=int(mysearchresult.count(with_limit_and_skip=False))
        response_dict['code'] = 200
        response_dict['type'] = "search-results"
        for d in mysearchresult:
            d['id'] = d['_id'].__str__()
            del d['_id']
            l.append(d)
        response_dict['results'] = l

    except:
        print("Error reading from Mongo")
        print(str(sys.exc_info()))
        response_dict['num_results'] = 0
        response_dict['code'] = 500
        response_dict['type'] = "Error"
        response_dict['results'] = []
        response_dict['message'] = str(sys.exc_info())
    return response_dict
476413
def csort(objs, key):
    """"""
    idxs = dict((obj, i) for (i, obj) in enumerate(objs))
    return sorted(objs, key=lambda obj: (key(obj), idxs[obj]))
960016
def search_order(self, limit=100, offset=0, common_name_pattern=None, status=None,
                     contact_handle=None):
        """"""

        response = self.request(E.searchOrderSslCertRequest(
            E.limit(limit),
            E.offset(offset),
            OE('commonNamePattern', common_name_pattern),
            OE('status', status, transform=_simple_array),
            OE('contactHandle', contact_handle),
        ))

        return response.as_models(SSLOrder)
1090394
def clean_query_Dict(cls, query_Dict):
    
    return {k: v for k, v in query_Dict.items() if v}
1021002
def list(self, request):
        """"""
        query = get_query_params(request).get("search", "")
        results = []
        base = self.model.get_base_class()
        doctypes = indexable_registry.families[base]
        for doctype, klass in doctypes.items():
            name = klass._meta.verbose_name.title()
            if query.lower() in name.lower():
                results.append(dict(
                    name=name,
                    doctype=doctype
                ))
                results.sort(key=lambda x: x["name"])
        return Response(dict(results=results))
943126
def sort(self, search):
        
        if self._sort:
            search = search.sort(*self._sort)
        return search
290761
def _do_search(self):
        
        if self._results_cache is None:
            response = self.raw()
            results = self.to_python(response.get('hits', {}).get('hits', []))
            self._results_cache = DictSearchResults(
                self.type, response, results, None)
        return self._results_cache
723191
def get_sorting(self, request, **resources):
        
        sorting = []

        if not request.GET:
            return sorting

        prefix = self._meta.dyn_prefix + 'sort'
        return request.GET.getlist(prefix)
1354473
def sort_func(self, key):
        """"""
        if key == self._KEYS.TIME:
            return 'aaa'
        if key == self._KEYS.DATA:
            return 'zzy'
        if key == self._KEYS.SOURCE:
            return 'zzz'
        return key
811513
def get_ordered_params(url):
        

        if url not in URLHelper.__cache:
            URLHelper.__cache[url] = urlparse(url)

        params = URLHelper.query_string_to_dict(URLHelper.__cache[url].query)

        return OrderedDict(sorted(params.items()))
129053
def _get_sorting_message(request, key):
        
        control_list = []
        reverse = request.url.query.get('reverse', None)
        if reverse is None:
            return control_list

        if reverse.lower() == "":
            control_list.append(client_list_control_pb2.ClientSortControls(
                reverse=True,
                keys=key.split(",")
            ))
        elif reverse.lower() != 'false':
            control_list.append(client_list_control_pb2.ClientSortControls(
                reverse=True,
                keys=reverse.split(",")
            ))

        return control_list
1063683
def sorted_key_list(self):
        """"""
        if not self.is_baked:
            self.bake()
        key_value_tuple = sorted(self.dct.items(),
                                 key=lambda x: x[1]['__abs_time__'])
        skl = [k[0] for k in key_value_tuple]
        return skl
1220376
def param_dict_to_list(dict,skeys=None):
    """"""
    #sort keys
    RV = SP.concatenate([dict[key].flatten() for key in skeys])
    return RV
    pass
114807
def get_order(self):
        
        return [dict(reverse=r[0], key=r[1]) for r in self.get_model()]
1102740
def keys(self):
        """"""

        keys = OrderedDict()

        def order_key(_):
            (k, v) = _
            cache_key = getattr(type(self), k)
            return cache_key.order

        items = [(k, getattr(type(self), k)) for k
            in dir(type(self))
        ]
        items = [(k, v) for (k, v)
            in items
            if isinstance(v, Key)
        ]

        for k, v in sorted(items, key=order_key):
            keys[k] = getattr(self, k)
        return keys
381983
def dict(self):
        
        SKIP_KEYS = ('_source_table', '_dest_table', 'd_vid', 't_vid', 'st_id',
                     'dataset', 'hash', 'process_records')
        return OrderedDict([(k, getattr(self, k)) for k in self.properties if k not in SKIP_KEYS])
921531
def nsorted(to_sort, key=None):
    """"""
    if key is None:
        key_callback = _natural_keys
    else:
        def key_callback(item):
            return _natural_keys(key(item))

    return sorted(to_sort, key=key_callback)