From b7a723866b0086e35d10dbd98c1ee1a0c9eeba9e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 30 Dec 2021 17:23:34 +0100 Subject: [PATCH] adding lot view --- ereuse_devicehub/inventory/views.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 3a75bae5..f6682969 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -28,6 +28,25 @@ class DeviceListView(View): return flask.render_template(self.template_name, **context) +class LotDeviceListView(View): + decorators = [login_required] + template_name = 'inventory/device_list.html' + + def dispatch_request(self, id): + # TODO @cayop adding filter + # import pdb; pdb.set_trace() + lots = Lot.query.filter(Lot.owner_id == current_user.id) + lot = lots.filter(Lot.id == id).one() + filter_types = ['Desktop', 'Laptop', 'Server'] + devices = [dev for dev in lot.devices if dev.type in filter_types] + + context = {'devices': devices, + 'lots': lots, + 'form_lot_device': LotDeviceAddForm(), + 'lot': lot} + return flask.render_template(self.template_name, **context) + + class LotDeviceAddView(View): methods = ['POST'] decorators = [login_required] @@ -49,4 +68,5 @@ class LotDeviceAddView(View): devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist')) +devices.add_url_rule('/lot//device/', view_func=LotDeviceListView.as_view('lotdevicelist')) devices.add_url_rule('/lot/devices/add', view_func=LotDeviceAddView.as_view('lot_devices_add'))