From c8be2bb6404a069ea50d635f5c24507413ceba57 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 28 Dec 2021 13:55:56 +0100 Subject: [PATCH] adding rendering list --- ereuse_devicehub/inventory/devices/views.py | 19 +++++--- .../templates/ereuse_devicehub/base_site.html | 2 +- .../templates/inventory/device_list.html | 44 +++++++------------ 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/ereuse_devicehub/inventory/devices/views.py b/ereuse_devicehub/inventory/devices/views.py index 8646f09c..7b028145 100644 --- a/ereuse_devicehub/inventory/devices/views.py +++ b/ereuse_devicehub/inventory/devices/views.py @@ -1,22 +1,27 @@ import flask from flask import Blueprint from flask.views import View -from flask_login import login_required, login_user +from flask_login import login_required, current_user -from ereuse_devicehub.forms import LoginForm -from ereuse_devicehub.resources.user.models import User +from ereuse_devicehub.resources.device.models import Device from ereuse_devicehub.utils import is_safe_url -devices = Blueprint('devices', __name__) +devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory') class DeviceListView(View): - # decorators = [login_required] + decorators = [login_required] template_name = 'inventory/device_list.html' def dispatch_request(self): - context = {} + # import pdb; pdb.set_trace() + filter_types = ['Desktop', 'Laptop', 'Server'] + devices = Device.query.filter( + Device.owner_id==current_user.id).filter( + Device.type.in_(filter_types)) + + context = {'devices': devices} return flask.render_template(self.template_name, **context) -devices.add_url_rule('/inventory/device/list/', view_func=DeviceListView.as_view('devicelist')) +devices.add_url_rule('/device/list/', view_func=DeviceListView.as_view('devicelist')) diff --git a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html index b68d5635..f233903d 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html @@ -242,7 +242,7 @@