From 95a8b13a6b3f012ad9b64dc87f25f36a94ee3bc4 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 4 Mar 2022 13:00:51 +0100 Subject: [PATCH 01/12] form select type of device in the list of device. Step 1 --- ereuse_devicehub/inventory/views.py | 8 +++++++- ereuse_devicehub/templates/inventory/device_list.html | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 62cd97cb..2329fa22 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -42,7 +42,13 @@ class DeviceListMix(View): def get_context(self, lot_id): # TODO @cayop adding filter # https://github.com/eReuse/devicehub-teal/blob/testing/ereuse_devicehub/resources/device/views.py#L56 - filter_types = ['Desktop', 'Laptop', 'Server'] + import pdb; pdb.set_trace() + type_device = { + None: ['Desktop', 'Laptop', 'Server'], + 'Computer': ['Computer'], + 'Monitor': ['Monitor'], + } + filter_types = type_device[request.get('filter')] lots = Lot.query.outerjoin(Trade) \ .filter(or_(Trade.user_from == g.user, Trade.user_to == g.user, diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 63395f5a..4170318d 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -279,10 +279,17 @@
Computers
+
+ + +
- + From 598b91e22b78f40e0589462145cae9c272a67547 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 7 Mar 2022 13:07:26 +0100 Subject: [PATCH 02/12] filter search in lists --- ereuse_devicehub/inventory/forms.py | 20 +++++++++++++++++++ ereuse_devicehub/inventory/views.py | 15 +++++--------- .../templates/inventory/device_list.html | 16 ++++++++++----- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 7702be79..945270b4 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -35,6 +35,26 @@ from ereuse_devicehub.resources.action.models import Trade from sqlalchemy import or_ +DEVICES = [ + ("Computer", "Computer"), + ("Monitor", "Monitor"), +] + + +class FilterForm(FlaskForm): + filter = SelectField('', choices=DEVICES, default="Comupter", + render_kw={'class': "form-select"}) + + def search(self): + + type_device = { + None: ['Desktop', 'Laptop', 'Server'], + 'Computer': ['Computer'], + 'Monitor': ['Monitor'], + } + return type_device.get(request.args.get('filter')) or type_device[None] + + class LotDeviceForm(FlaskForm): lot = StringField('Lot', [validators.UUID()]) devices = StringField('Devices', [validators.length(min=1)]) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 2329fa22..9c4d2e10 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -13,6 +13,7 @@ from ereuse_devicehub import messages from ereuse_devicehub.inventory.forms import ( AllocateForm, DataWipeForm, + FilterForm, LotDeviceForm, LotForm, NewActionForm, @@ -40,15 +41,9 @@ class DeviceListMix(View): template_name = 'inventory/device_list.html' def get_context(self, lot_id): - # TODO @cayop adding filter - # https://github.com/eReuse/devicehub-teal/blob/testing/ereuse_devicehub/resources/device/views.py#L56 - import pdb; pdb.set_trace() - type_device = { - None: ['Desktop', 'Laptop', 'Server'], - 'Computer': ['Computer'], - 'Monitor': ['Monitor'], - } - filter_types = type_device[request.get('filter')] + form_filter = FilterForm() + filter_types = form_filter.search() + lots = Lot.query.outerjoin(Trade) \ .filter(or_(Trade.user_from == g.user, Trade.user_to == g.user, @@ -61,7 +56,6 @@ class DeviceListMix(View): ) if lot_id: - # import pdb; pdb.set_trace() lot = lots.filter(Lot.id == lot_id).one() devices = [dev for dev in lot.devices if dev.type in filter_types] devices = sorted(devices, key=lambda x: x.updated, reverse=True) @@ -98,6 +92,7 @@ class DeviceListMix(View): 'form_new_allocate': form_new_allocate, 'form_new_datawipe': form_new_datawipe, 'form_new_trade': form_new_trade, + 'form_filter': form_filter, 'lot': lot, 'tags': tags, 'list_devices': list_devices, diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 4170318d..ae545734 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -280,11 +280,17 @@
Computers
- - +
+
+ {% for f in form_filter %} + {{ f }} + {% endfor %} +
+
+ +
+
+
Select allSelect Title DHID Tags
From 34aab019b9db7897311447eb394138544c1e2d85 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 7 Mar 2022 13:09:11 +0100 Subject: [PATCH 03/12] fix computer option --- ereuse_devicehub/inventory/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 945270b4..1c0981ff 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -49,7 +49,7 @@ class FilterForm(FlaskForm): type_device = { None: ['Desktop', 'Laptop', 'Server'], - 'Computer': ['Computer'], + 'Computer': ['Desktop', 'Laptop', 'Server'], 'Monitor': ['Monitor'], } return type_device.get(request.args.get('filter')) or type_device[None] From bd716e2ef881a45dea66c876491b7f13cea7c505 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 7 Mar 2022 15:17:03 +0100 Subject: [PATCH 04/12] add more devices to the filter --- ereuse_devicehub/inventory/forms.py | 67 ++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 1c0981ff..e2499f0f 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -37,7 +37,60 @@ from sqlalchemy import or_ DEVICES = [ ("Computer", "Computer"), + ("Desktop", "Desktop"), + ("Laptop", "Laptop"), + ("Server", "Server"), ("Monitor", "Monitor"), + ("ComputerMonitor", "ComputerMonitor"), + ("TelevisionSet", "TelevisionSet"), + ("Projector", "Projector"), + ("Mobile", "Mobile"), + ("Smartphone", "Smartphone"), + ("Tablet", "Tablet"), + ("Cellphone", "Cellphone"), + ("JoinedComponentTableMixin", "JoinedComponentTableMixin"), + ("GraphicCard", "GraphicCard"), + ("DataStorage", "DataStorage"), + ("HardDrive", "HardDrive"), + ("SolidStateDrive", "SolidStateDrive"), + ("Motherboard", "Motherboard"), + ("NetworkMixin", "NetworkMixin"), + ("NetworkAdapter", "NetworkAdapter"), + ("Processor", "Processor"), + ("RamModule", "RamModule"), + ("SoundCard", "SoundCard"), + ("Display", "Display"), + ("Battery", "Battery"), + ("Camera", "Camera"), + ("ComputerAccessory", "ComputerAccessory"), + ("SAI", "SAI"), + ("Keyboard", "Keyboard"), + ("Mouse", "Mouse"), + ("MemoryCardReader", "MemoryCardReader"), + ("Networking", "Networking"), + ("Router", "Router"), + ("Switch", "Switch"), + ("Hub", "Hub"), + ("WirelessAccessPoint", "WirelessAccessPoint"), + ("Printer", "Printer"), + ("LabelPrinter", "LabelPrinter"), + ("Sound", "Sound"), + ("Microphone", "Microphone"), + ("Video", "Video"), + ("VideoScaler", "VideoScaler"), + ("Videoconference", "Videoconference"), + ("Cooking", "Cooking"), + ("Mixer", "Mixer"), + ("DIYAndGardening", "DIYAndGardening"), + ("Drill", "Drill"), + ("PackOfScrewdrivers", "PackOfScrewdrivers"), + ("Home", "Home"), + ("Dehumidifier", "Dehumidifier"), + ("Stairs", "Stairs"), + ("Recreation", "Recreation"), + ("Bike", "Bike"), + ("Racket", "Racket"), + ("Manufacturer", "Manufacturer") ] @@ -46,13 +99,15 @@ class FilterForm(FlaskForm): render_kw={'class': "form-select"}) def search(self): + device = dict(DEVICES).get(request.args.get('filter')) - type_device = { - None: ['Desktop', 'Laptop', 'Server'], - 'Computer': ['Desktop', 'Laptop', 'Server'], - 'Monitor': ['Monitor'], - } - return type_device.get(request.args.get('filter')) or type_device[None] + if device == "Computer": + return ['Desktop', 'Laptop', 'Server'] + + if device: + return [device] + + return ['Desktop', 'Laptop', 'Server'] class LotDeviceForm(FlaskForm): From 62f42e9e0562aec53a71427e180d8516affa2e98 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 8 Mar 2022 10:15:21 +0100 Subject: [PATCH 05/12] fix bug --- ereuse_devicehub/inventory/forms.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index e2499f0f..6b3955de 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -36,6 +36,7 @@ from sqlalchemy import or_ DEVICES = [ + ("All", "All"), ("Computer", "Computer"), ("Desktop", "Desktop"), ("Laptop", "Laptop"), @@ -95,7 +96,7 @@ DEVICES = [ class FilterForm(FlaskForm): - filter = SelectField('', choices=DEVICES, default="Comupter", + filter = SelectField('', choices=DEVICES, default="Computer", render_kw={'class': "form-select"}) def search(self): From a983ebd6cf111e82116456f1501580bee455614b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 8 Mar 2022 10:15:53 +0100 Subject: [PATCH 06/12] add all devices as option in the select of filter --- ereuse_devicehub/inventory/views.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 9c4d2e10..f9629e59 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -57,7 +57,9 @@ class DeviceListMix(View): if lot_id: lot = lots.filter(Lot.id == lot_id).one() - devices = [dev for dev in lot.devices if dev.type in filter_types] + devices = lot.devices + if filter_types: + devices = [dev for dev in lot.devices if dev.type in filter_types] devices = sorted(devices, key=lambda x: x.updated, reverse=True) form_new_action = NewActionForm(lot=lot.id) form_new_allocate = AllocateForm(lot=lot.id) @@ -68,12 +70,20 @@ class DeviceListMix(View): user_from=g.user.email, ) else: - devices = ( - Device.query.filter(Device.owner_id == current_user.id) - .filter(Device.type.in_(filter_types)) - .filter_by(lots=None) - .order_by(Device.updated.desc()) - ) + if "All" in filter_types: + devices = ( + Device.query.filter(Device.owner_id == current_user.id) + .filter_by(lots=None) + .order_by(Device.updated.desc()) + ) + else: + devices = ( + Device.query.filter(Device.owner_id == current_user.id) + .filter_by(lots=None) + .filter(Device.type.in_(filter_types)) + .order_by(Device.updated.desc()) + ) + form_new_action = NewActionForm() form_new_allocate = AllocateForm() form_new_datawipe = DataWipeForm() From ea66c31a079cbaaf3ea43c8055bfe3f3028c06f5 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 8 Mar 2022 10:30:53 +0100 Subject: [PATCH 07/12] fix bug --- ereuse_devicehub/inventory/forms.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 91b80305..fae58678 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -98,14 +98,22 @@ class FilterForm(FlaskForm): filter = SelectField('', choices=DEVICES, default="Computer", render_kw={'class': "form-select"}) - def search(self): - device = dict(DEVICES).get(request.args.get('filter')) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.device = dict(DEVICES).get(request.args.get('filter')) + if self.device: + self.filter.data = self.device - if device == "Computer": + def search(self): + + if self.device == "Computer": return ['Desktop', 'Laptop', 'Server'] - if device: - return [device] + if self.device == "DataStorage": + return ['HardDrive', 'SolidStateDrive'] + + if self.device: + return [self.device] return ['Desktop', 'Laptop', 'Server'] From b16fdd59f97d49f1a3d007caa255501bba86e67c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 8 Mar 2022 11:01:10 +0100 Subject: [PATCH 08/12] precommit --- ereuse_devicehub/inventory/forms.py | 86 ++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 26 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index fae58678..82a1b639 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -1,26 +1,46 @@ import copy import json from json.decoder import JSONDecodeError + from boltons.urlutils import URL from flask import g, request from flask_wtf import FlaskForm +from sqlalchemy import or_ from sqlalchemy.util import OrderedSet from wtforms import ( - BooleanField, DateField, FileField, FloatField, Form, HiddenField, - IntegerField, MultipleFileField, SelectField, StringField, TextAreaField, - URLField, validators) + BooleanField, + DateField, + FileField, + FloatField, + Form, + HiddenField, + IntegerField, + MultipleFileField, + SelectField, + StringField, + TextAreaField, + URLField, + validators, +) from wtforms.fields import FormField from ereuse_devicehub.db import db -from ereuse_devicehub.resources.action.models import RateComputer, Snapshot +from ereuse_devicehub.resources.action.models import RateComputer, Snapshot, Trade from ereuse_devicehub.resources.action.rate.v1_0 import CannotRate -from ereuse_devicehub.resources.action.schemas import \ - Snapshot as SnapshotSchema -from ereuse_devicehub.resources.action.views.snapshot import ( - move_json, save_json) +from ereuse_devicehub.resources.action.schemas import Snapshot as SnapshotSchema +from ereuse_devicehub.resources.action.views.snapshot import move_json, save_json from ereuse_devicehub.resources.device.models import ( - SAI, Cellphone, Computer, Device, Keyboard, MemoryCardReader, Monitor, - Mouse, Smartphone, Tablet) + SAI, + Cellphone, + Computer, + Device, + Keyboard, + MemoryCardReader, + Monitor, + Mouse, + Smartphone, + Tablet, +) from ereuse_devicehub.resources.device.sync import Sync from ereuse_devicehub.resources.documents.models import DataWipeDocument from ereuse_devicehub.resources.enums import Severity, SnapshotSoftware @@ -30,9 +50,6 @@ from ereuse_devicehub.resources.tag.model import Tag from ereuse_devicehub.resources.tradedocument.models import TradeDocument from ereuse_devicehub.resources.user.exceptions import InsufficientPermission from ereuse_devicehub.resources.user.models import User -from ereuse_devicehub.resources.action.models import Trade -from sqlalchemy import or_ - DEVICES = [ ("All", "All"), @@ -90,13 +107,14 @@ DEVICES = [ ("Recreation", "Recreation"), ("Bike", "Bike"), ("Racket", "Racket"), - ("Manufacturer", "Manufacturer") + ("Manufacturer", "Manufacturer"), ] class FilterForm(FlaskForm): - filter = SelectField('', choices=DEVICES, default="Computer", - render_kw={'class': "form-select"}) + filter = SelectField( + '', choices=DEVICES, default="Computer", render_kw={'class': "form-select"} + ) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -131,9 +149,14 @@ class LotDeviceForm(FlaskForm): self._lot = ( Lot.query.outerjoin(Trade) .filter(Lot.id == self.lot.data) - .filter(or_(Trade.user_from == g.user, - Trade.user_to == g.user, - Lot.owner_id == g.user.id)).one() + .filter( + or_( + Trade.user_from == g.user, + Trade.user_to == g.user, + Lot.owner_id == g.user.id, + ) + ) + .one() ) devices = set(self.devices.data.split(",")) @@ -550,11 +573,17 @@ class TagDeviceForm(FlaskForm): super().__init__(*args, **kwargs) if self.delete: - tags = Tag.query.filter(Tag.owner_id == g.user.id).filter_by( - device_id=self.device_id - ).order_by(Tag.id) + tags = ( + Tag.query.filter(Tag.owner_id == g.user.id) + .filter_by(device_id=self.device_id) + .order_by(Tag.id) + ) else: - tags = Tag.query.filter(Tag.owner_id == g.user.id).filter_by(device_id=None).order_by(Tag.id) + tags = ( + Tag.query.filter(Tag.owner_id == g.user.id) + .filter_by(device_id=None) + .order_by(Tag.id) + ) self.tag.choices = [(tag.id, tag.id) for tag in tags] @@ -813,9 +842,14 @@ class TradeForm(NewActionForm): self._lot = ( Lot.query.outerjoin(Trade) .filter(Lot.id == self.lot.data) - .filter(or_(Trade.user_from == g.user, - Trade.user_to == g.user, - Lot.owner_id == g.user.id)).one() + .filter( + or_( + Trade.user_from == g.user, + Trade.user_to == g.user, + Lot.owner_id == g.user.id, + ) + ) + .one() ) def validate(self, extra_validators=None): From 2f84aac7efe9146a7b7a6af8c355cb58a0a11e86 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 8 Mar 2022 17:59:33 +0100 Subject: [PATCH 09/12] change the title of list when there are a select data in the filter --- ereuse_devicehub/templates/inventory/device_list.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 9a08b4f6..8ed8de70 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -279,7 +279,11 @@
-
Computers
+ {% if form_filter.filter.data %} +
{{ form_filter.filter.data }}
+ {% else %} +
Computer
+ {% endif %}
From 71926f01c0f939af41c3230d0a7d2d931ce9c109 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 15 Mar 2022 09:16:01 +0100 Subject: [PATCH 10/12] new list of device for filter --- ereuse_devicehub/inventory/forms.py | 45 +++++-------------- .../templates/inventory/device_list.html | 39 ++++++++++++++++ 2 files changed, 51 insertions(+), 33 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index ae827195..6861947b 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -53,11 +53,9 @@ from ereuse_devicehub.resources.user.models import User DEVICES = [ ("All", "All"), - ("Computer", "Computer"), ("Desktop", "Desktop"), ("Laptop", "Laptop"), ("Server", "Server"), - ("Monitor", "Monitor"), ("ComputerMonitor", "ComputerMonitor"), ("TelevisionSet", "TelevisionSet"), ("Projector", "Projector"), @@ -65,49 +63,30 @@ DEVICES = [ ("Smartphone", "Smartphone"), ("Tablet", "Tablet"), ("Cellphone", "Cellphone"), - ("JoinedComponentTableMixin", "JoinedComponentTableMixin"), ("GraphicCard", "GraphicCard"), - ("DataStorage", "DataStorage"), ("HardDrive", "HardDrive"), ("SolidStateDrive", "SolidStateDrive"), ("Motherboard", "Motherboard"), - ("NetworkMixin", "NetworkMixin"), ("NetworkAdapter", "NetworkAdapter"), ("Processor", "Processor"), ("RamModule", "RamModule"), ("SoundCard", "SoundCard"), - ("Display", "Display"), ("Battery", "Battery"), - ("Camera", "Camera"), - ("ComputerAccessory", "ComputerAccessory"), - ("SAI", "SAI"), ("Keyboard", "Keyboard"), ("Mouse", "Mouse"), ("MemoryCardReader", "MemoryCardReader"), - ("Networking", "Networking"), - ("Router", "Router"), - ("Switch", "Switch"), - ("Hub", "Hub"), - ("WirelessAccessPoint", "WirelessAccessPoint"), - ("Printer", "Printer"), - ("LabelPrinter", "LabelPrinter"), - ("Sound", "Sound"), - ("Microphone", "Microphone"), - ("Video", "Video"), - ("VideoScaler", "VideoScaler"), - ("Videoconference", "Videoconference"), - ("Cooking", "Cooking"), - ("Mixer", "Mixer"), - ("DIYAndGardening", "DIYAndGardening"), - ("Drill", "Drill"), - ("PackOfScrewdrivers", "PackOfScrewdrivers"), - ("Home", "Home"), - ("Dehumidifier", "Dehumidifier"), - ("Stairs", "Stairs"), - ("Recreation", "Recreation"), - ("Bike", "Bike"), - ("Racket", "Racket"), - ("Manufacturer", "Manufacturer"), + ("GraphicCard", "GraphicCard"), + ("HardDrive", "HardDrive"), + ("SolidStateDrive", "SolidStateDrive"), + ("Motherboard", "Motherboard"), + ("NetworkAdapter", "NetworkAdapter"), + ("Processor", "Processor"), + ("RamModule", "RamModule"), + ("SoundCard", "SoundCard"), + ("Battery", "Battery"), + ("Keyboard", "Keyboard"), + ("Mouse", "Mouse"), + ("MemoryCardReader", "MemoryCardReader"), ] diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index eacbda29..08cb18ea 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -296,7 +296,46 @@
{% for f in form_filter %} + {% if f == form_filter.filter %} + + {% else %} {{ f }} + {% endif %} {% endfor %}
From d20bd63caedbacbb066c4b43749a7596a9a1748c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 15 Mar 2022 10:02:30 +0100 Subject: [PATCH 11/12] precommit --- ereuse_devicehub/inventory/forms.py | 70 +++++++------------ .../templates/inventory/device_list.html | 39 ----------- 2 files changed, 26 insertions(+), 83 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 6861947b..5eab3236 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -51,43 +51,29 @@ from ereuse_devicehub.resources.tradedocument.models import TradeDocument from ereuse_devicehub.resources.user.exceptions import InsufficientPermission from ereuse_devicehub.resources.user.models import User -DEVICES = [ - ("All", "All"), - ("Desktop", "Desktop"), - ("Laptop", "Laptop"), - ("Server", "Server"), - ("ComputerMonitor", "ComputerMonitor"), - ("TelevisionSet", "TelevisionSet"), - ("Projector", "Projector"), - ("Mobile", "Mobile"), - ("Smartphone", "Smartphone"), - ("Tablet", "Tablet"), - ("Cellphone", "Cellphone"), - ("GraphicCard", "GraphicCard"), - ("HardDrive", "HardDrive"), - ("SolidStateDrive", "SolidStateDrive"), - ("Motherboard", "Motherboard"), - ("NetworkAdapter", "NetworkAdapter"), - ("Processor", "Processor"), - ("RamModule", "RamModule"), - ("SoundCard", "SoundCard"), - ("Battery", "Battery"), - ("Keyboard", "Keyboard"), - ("Mouse", "Mouse"), - ("MemoryCardReader", "MemoryCardReader"), - ("GraphicCard", "GraphicCard"), - ("HardDrive", "HardDrive"), - ("SolidStateDrive", "SolidStateDrive"), - ("Motherboard", "Motherboard"), - ("NetworkAdapter", "NetworkAdapter"), - ("Processor", "Processor"), - ("RamModule", "RamModule"), - ("SoundCard", "SoundCard"), - ("Battery", "Battery"), - ("Keyboard", "Keyboard"), - ("Mouse", "Mouse"), - ("MemoryCardReader", "MemoryCardReader"), -] +DEVICES = { + "All": ["All"], + "Computer": [ + "Desktop", + "Laptop", + "Server", + ], + "Monitor": ["ComputerMonitor", "Monitor", "TelevisionSet", "Projector"], + "Mobile, tablet & smartphone": ["Mobile", "Tablet", "Smartphone", "Cellphone"], + "DataStorage": ["HardDrive", "SolidStateDrive"], + "Accessories & Peripherals": [ + "GraphicCard", + "Motherboard", + "NetworkAdapter", + "Processor", + "RamModule", + "SoundCard", + "Battery", + "Keyboard", + "Mouse", + "MemoryCardReader", + ], +} class FilterForm(FlaskForm): @@ -97,18 +83,14 @@ class FilterForm(FlaskForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.device = dict(DEVICES).get(request.args.get('filter')) + types_of_devices = [item for sublist in DEVICES.values() for item in sublist] + dev = request.args.get('filter') + self.device = dev if dev in types_of_devices else None if self.device: self.filter.data = self.device def search(self): - if self.device == "Computer": - return ['Desktop', 'Laptop', 'Server'] - - if self.device == "DataStorage": - return ['HardDrive', 'SolidStateDrive'] - if self.device: return [self.device] diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 08cb18ea..eacbda29 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -296,46 +296,7 @@
{% for f in form_filter %} - {% if f == form_filter.filter %} - - {% else %} {{ f }} - {% endif %} {% endfor %}
From 678dfb0ea95f33623a874a6c46b01a6a5ec9cb86 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 15 Mar 2022 10:59:55 +0100 Subject: [PATCH 12/12] Refactor filter form HTML markup Avoid using row & col --- .../templates/inventory/device_list.html | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index eacbda29..bce1cd23 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -286,25 +286,20 @@ {% endif %}
- - {% if form_filter.filter.data %} -
{{ form_filter.filter.data }}
- {% else %} -
Computer
- {% endif %} -
-
- {% for f in form_filter %} - {{ f }} - {% endfor %} -
-
- -
-
+
+ {% for f in form_filter %} + {{ f }} + {% endfor %} +
+ +

+ Displaying devices of type + {{ form_filter.filter.data or "Computer" }} +

+