From e53c5eb2e466b200e02a89eff7a1ac2a3ed18d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20M=C3=A4gi?= Date: Tue, 24 Dec 2024 04:33:43 +0200 Subject: [PATCH] Pin K-SPACE to user fields top --- inventory-app/common.py | 4 ++++ inventory-app/inventory.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/inventory-app/common.py b/inventory-app/common.py index e029365..65ad9b6 100644 --- a/inventory-app/common.py +++ b/inventory-app/common.py @@ -106,6 +106,7 @@ def slack_post(msg, channel): requests.post(url, json={"text": msg }) def build_query(base_query, fields=[], sort_fields={}): + top_usernames= ['k-space'] selectors = [] q = base_query.copy() for attr, title, tp in fields: @@ -119,6 +120,9 @@ def build_query(base_query, fields=[], sort_fields={}): if key in ("inventory_owner_username", "inventory_user_username"): results = [{"username": u, "display_name": g.users_lookup.get(u, User()).display_name or u} for u in results] results = sorted(results, key = lambda k: k["display_name"]) + top = [k for k in results if k["username"] in top_usernames] + rest = [k for k in results if k["username"] not in top_usernames] + results = top + rest elif tp != list: results = sorted(results) results = list(map(tp, results)) diff --git a/inventory-app/inventory.py b/inventory-app/inventory.py index db03ac7..6270c64 100644 --- a/inventory-app/inventory.py +++ b/inventory-app/inventory.py @@ -68,12 +68,15 @@ def get_image_url(item_id): return None def fetch_members_select(): + top_usernames= ['k-space', None] choices = [(None, None)] for username, user in g.users_lookup.items(): choices.append((username, user.display_name or username)) choices = list(set(choices)) choices = sorted(choices, key = lambda k: k[1] or "") - return choices + top = [k for k in choices if k[0] in top_usernames] + rest = [k for k in choices if k[0] not in top_usernames] + return top + rest def fetch_type_select(): objs = db.inventory.distinct("type")