From 1c9e6fd448e7c7ae8505c2cc106af2448b06db69 Mon Sep 17 00:00:00 2001 From: Nico Vermaas <vermaas@astron.nl> Date: Tue, 2 Jul 2024 13:47:06 +0000 Subject: [PATCH] add sort direction --- spaceweather_processing/app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spaceweather_processing/app.py b/spaceweather_processing/app.py index 93fde0b..b8c3a22 100644 --- a/spaceweather_processing/app.py +++ b/spaceweather_processing/app.py @@ -136,8 +136,14 @@ class DataProductDB: # if a &sort=<field> url parameter is given then use sort, otherwise omit it (backward compatibility) if sort: + if sort.startswith('-'): + direction = -1 + sort = sort.lstrip('-') + else: + direction = 1 + results = [augment_item(item) for item in - self.db[collection_name].find(query, selected_fields).skip(skip).limit(limit).sort(sort)] + self.db[collection_name].find(query, selected_fields).skip(skip).limit(limit).sort(sort,direction)] else: results = [augment_item(item) for item in self.db[collection_name].find(query, selected_fields).skip(skip).limit(limit)] -- GitLab