2021-12-28 11:36:02 +00:00
|
|
|
import flask
|
|
|
|
from flask import Blueprint
|
|
|
|
from flask.views import View
|
2021-12-28 12:55:56 +00:00
|
|
|
from flask_login import login_required, current_user
|
2021-12-28 11:36:02 +00:00
|
|
|
|
2021-12-28 12:55:56 +00:00
|
|
|
from ereuse_devicehub.resources.device.models import Device
|
2021-12-29 12:44:28 +00:00
|
|
|
from ereuse_devicehub.resources.lot.models import Lot
|
2021-12-28 11:36:02 +00:00
|
|
|
|
2021-12-28 12:55:56 +00:00
|
|
|
devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory')
|
2021-12-28 11:36:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DeviceListView(View):
|
2021-12-28 12:55:56 +00:00
|
|
|
decorators = [login_required]
|
2021-12-28 11:36:02 +00:00
|
|
|
template_name = 'inventory/device_list.html'
|
|
|
|
|
|
|
|
def dispatch_request(self):
|
2021-12-29 09:13:34 +00:00
|
|
|
# TODO @cayop adding filter
|
2021-12-28 12:55:56 +00:00
|
|
|
filter_types = ['Desktop', 'Laptop', 'Server']
|
|
|
|
devices = Device.query.filter(
|
2021-12-29 09:13:34 +00:00
|
|
|
Device.owner_id == current_user.id).filter(
|
2021-12-28 12:55:56 +00:00
|
|
|
Device.type.in_(filter_types))
|
|
|
|
|
2021-12-29 12:44:28 +00:00
|
|
|
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
|
|
|
|
|
|
|
context = {'devices': devices, 'lots': lots}
|
2021-12-28 11:36:02 +00:00
|
|
|
return flask.render_template(self.template_name, **context)
|
|
|
|
|
|
|
|
|
2021-12-29 09:13:34 +00:00
|
|
|
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
|