refactoring DeviceListView
This commit is contained in:
parent
d3dc5c8986
commit
0f5ab17a3f
|
@ -14,30 +14,19 @@ class DeviceListView(View):
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'inventory/device_list.html'
|
template_name = 'inventory/device_list.html'
|
||||||
|
|
||||||
def dispatch_request(self):
|
def dispatch_request(self, id=None):
|
||||||
# TODO @cayop adding filter
|
# TODO @cayop adding filter
|
||||||
filter_types = ['Desktop', 'Laptop', 'Server']
|
filter_types = ['Desktop', 'Laptop', 'Server']
|
||||||
|
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
||||||
|
lot = None
|
||||||
|
if id:
|
||||||
|
lot = lots.filter(Lot.id == id).one()
|
||||||
|
devices = [dev for dev in lot.devices if dev.type in filter_types]
|
||||||
|
else:
|
||||||
devices = Device.query.filter(
|
devices = Device.query.filter(
|
||||||
Device.owner_id == current_user.id).filter(
|
Device.owner_id == current_user.id).filter(
|
||||||
Device.type.in_(filter_types))
|
Device.type.in_(filter_types))
|
||||||
|
|
||||||
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
|
||||||
|
|
||||||
context = {'devices': devices, 'lots': lots, 'form_lot_device': LotDeviceAddForm()}
|
|
||||||
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
|
|
||||||
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,
|
context = {'devices': devices,
|
||||||
'lots': lots,
|
'lots': lots,
|
||||||
'form_lot_device': LotDeviceAddForm(),
|
'form_lot_device': LotDeviceAddForm(),
|
||||||
|
@ -78,7 +67,7 @@ class LotView(View):
|
||||||
|
|
||||||
|
|
||||||
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
|
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
|
||||||
devices.add_url_rule('/lot/<string:id>/device/', view_func=LotDeviceListView.as_view('lotdevicelist'))
|
devices.add_url_rule('/lot/<string:id>/device/', view_func=DeviceListView.as_view('lotdevicelist'))
|
||||||
devices.add_url_rule('/lot/devices/add/', view_func=LotDeviceAddView.as_view('lot_devices_add'))
|
devices.add_url_rule('/lot/devices/add/', view_func=LotDeviceAddView.as_view('lot_devices_add'))
|
||||||
devices.add_url_rule('/lot/add', view_func=LotView.as_view('lot_add'))
|
devices.add_url_rule('/lot/add', view_func=LotView.as_view('lot_add'))
|
||||||
devices.add_url_rule('/lot/<string:id>/', view_func=LotView.as_view('lot_edit'))
|
devices.add_url_rule('/lot/<string:id>/', view_func=LotView.as_view('lot_edit'))
|
||||||
|
|
Reference in a new issue