From 10a1e23a5dbb4530a0bfb2e50b97cf5f527060ac Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 7 Dec 2021 13:20:16 +0100 Subject: [PATCH] Metrics only lot --- ereuse_devicehub/resources/documents/documents.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 11a589df..6eb9f5f0 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -1,4 +1,5 @@ import csv +import json import enum import uuid import time @@ -150,12 +151,13 @@ class DevicesDocumentView(DeviceView): class ActionsDocumentView(DeviceView): @cache(datetime.timedelta(minutes=1)) def find(self, args: dict): - query = (x for x in self.query(args)) + filters = json.loads(request.args.get('filter', {})) + ids = filters.get('ids', []) + query = self.query(args).filter(Device.id.in_(ids)) return self.generate_post_csv(query) def generate_post_csv(self, query): """Get device query and put information in csv format.""" - # import pdb; pdb.set_trace() data = StringIO() cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"') first = True @@ -170,6 +172,13 @@ class ActionsDocumentView(DeviceView): cw.writerow(d.values()) query_trade = Trade.query.filter(Trade.devices.any(Device.id.in_(devs_id))).all() + lot_id = request.args.get('lot') + if lot_id and not query_trade: + lot = Lot.query.filter_by(id=lot_id).one() + if hasattr(lot, "trade") and lot.trade: + if g.user in [lot.trade.user_from, lot.trade.user_to]: + query_trade = [lot.trade] + for trade in query_trade: data_rows = trade.get_metrics() for row in data_rows: