From 67cf797c6ce81d30668b7bea07e05aac516c6fc4 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 22 Nov 2022 11:58:56 +0100 Subject: [PATCH 01/40] fixing name hardDrive in filter --- 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 41505a8a..b86dca83 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -88,7 +88,7 @@ DEVICES = { ], "Drives & Storage": [ "All DataStorage", - "HardDrives", + "HardDrive", "SolidStageDrive", ], } From 7bf879bbcf608889095560df7f9eb462ac1f849f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 22 Nov 2022 11:59:31 +0100 Subject: [PATCH 02/40] add my_partner for get the partner of one device --- ereuse_devicehub/resources/device/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 0f398737..35e4d559 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -632,6 +632,14 @@ class Device(Thing): return self.binding.device.devicehub_id return self.devicehub_id + @property + def my_partner(self): + if self.placeholder and self.placeholder.binding: + return self.placeholder.binding + if self.binding: + return self.binding.device + return self + @property def get_updated(self): if self.placeholder and self.placeholder.binding: From 796f49f6cf17282ed71a93fa94ef61a8ec986509 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 22 Nov 2022 12:00:17 +0100 Subject: [PATCH 03/40] show correctly the ids in the templates --- ereuse_devicehub/templates/inventory/erasure_list.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ereuse_devicehub/templates/inventory/erasure_list.html b/ereuse_devicehub/templates/inventory/erasure_list.html index adaec94f..7573bb4b 100644 --- a/ereuse_devicehub/templates/inventory/erasure_list.html +++ b/ereuse_devicehub/templates/inventory/erasure_list.html @@ -128,7 +128,7 @@ {% for ac in erasure %} - 0 %} + {% if ac.device.my_partner.lots | length > 0 %}
- {% for lot in ac.device.get_lots_for_template() %} + {% for lot in ac.device.my_partner.get_lots_for_template() %} {{ lot }} {% endfor %}
From ac535cc9b5dedbf5dd301916ece94a5e5e92bb38 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 22 Nov 2022 15:44:44 +0100 Subject: [PATCH 04/40] add new fields in the filters --- ereuse_devicehub/inventory/forms.py | 17 + .../resources/device/definitions.py | 476 ++++++++++++++---- ereuse_devicehub/resources/device/schemas.py | 4 + .../templates/inventory/device_create.html | 8 +- 4 files changed, 419 insertions(+), 86 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 41505a8a..a46c4dd5 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -50,11 +50,14 @@ from ereuse_devicehub.resources.device.models import ( Keyboard, Laptop, MemoryCardReader, + Monitor, Mouse, Placeholder, + Projector, Server, Smartphone, Tablet, + TelevisionSet, ) from ereuse_devicehub.resources.documents.models import DataWipeDocument from ereuse_devicehub.resources.enums import Severity @@ -91,6 +94,13 @@ DEVICES = { "HardDrives", "SolidStageDrive", ], + "Accessories": [ + "All Accessories", + "Mouse", + "MemoryCardReader", + "SAI", + "Keyboard", + ], } COMPUTERS = ['Desktop', 'Laptop', 'Server', 'Computer'] @@ -98,6 +108,7 @@ COMPUTERS = ['Desktop', 'Laptop', 'Server', 'Computer'] MONITORS = ["ComputerMonitor", "Monitor", "TelevisionSet", "Projector"] MOBILE = ["Mobile", "Tablet", "Smartphone", "Cellphone"] STORAGE = ["HardDrive", "SolidStateDrive"] +ACCESSORIES = ["Mouse", "MemoryCardReader", "SAI", "Keyboard"] class AdvancedSearchForm(FlaskForm): @@ -184,6 +195,9 @@ class FilterForm(FlaskForm): elif "All DataStorage" == self.device_type: filter_type = STORAGE + elif "All Accessories" == self.device_type: + filter_type = ACCESSORIES + if filter_type: self.devices = self.devices.filter(Device.type.in_(filter_type)) @@ -371,6 +385,9 @@ class NewDeviceForm(FlaskForm): "Tablet": Tablet, "Cellphone": Cellphone, "ComputerMonitor": ComputerMonitor, + "Monitor": Monitor, + "TelevisionSet": TelevisionSet, + "Projector": Projector, "Mouse": Mouse, "Keyboard": Keyboard, "SAI": SAI, diff --git a/ereuse_devicehub/resources/device/definitions.py b/ereuse_devicehub/resources/device/definitions.py index cdc99c05..015d5040 100644 --- a/ereuse_devicehub/resources/device/definitions.py +++ b/ereuse_devicehub/resources/device/definitions.py @@ -4,7 +4,11 @@ from teal.resource import Converters, Resource from ereuse_devicehub.resources.device import schemas from ereuse_devicehub.resources.device.models import Manufacturer -from ereuse_devicehub.resources.device.views import DeviceView, DeviceMergeView, ManufacturerView +from ereuse_devicehub.resources.device.views import ( + DeviceMergeView, + DeviceView, + ManufacturerView, +) class DeviceDef(Resource): @@ -13,25 +17,42 @@ class DeviceDef(Resource): ID_CONVERTER = Converters.string AUTH = False # We manage this at each view - def __init__(self, app, - import_name=__name__, - static_folder='static', - static_url_path=None, - template_folder='templates', - url_prefix=None, - subdomain=None, - url_defaults=None, - root_path=None, - cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder='static', + static_url_path=None, + template_folder='templates', + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) - device_merge = DeviceMergeView.as_view('merge-devices', definition=self, auth=app.auth) + device_merge = DeviceMergeView.as_view( + 'merge-devices', definition=self, auth=app.auth + ) if self.AUTH: device_merge = app.auth.requires_auth(device_merge) - path = '/<{value}:dev1_id>/merge/<{value}:dev2_id>'.format(value=self.ID_CONVERTER.value) + path = '/<{value}:dev1_id>/merge/<{value}:dev2_id>'.format( + value=self.ID_CONVERTER.value + ) # self.add_url_rule(path, view_func=device_merge, methods={'POST'}) @@ -40,11 +61,31 @@ class ComputerDef(DeviceDef): VIEW = None SCHEMA = schemas.Computer - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class DesktopDef(ComputerDef): @@ -66,11 +107,31 @@ class MonitorDef(DeviceDef): VIEW = None SCHEMA = schemas.Monitor - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class ComputerMonitorDef(MonitorDef): @@ -83,15 +144,40 @@ class TelevisionSetDef(MonitorDef): SCHEMA = schemas.TelevisionSet +class ProjectorDef(MonitorDef): + VIEW = None + SCHEMA = schemas.Projector + + class MobileDef(DeviceDef): VIEW = None SCHEMA = schemas.Mobile - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class SmartphoneDef(MobileDef): @@ -113,11 +199,31 @@ class ComponentDef(DeviceDef): VIEW = None SCHEMA = schemas.Component - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class GraphicCardDef(ComponentDef): @@ -184,11 +290,31 @@ class ComputerAccessoryDef(DeviceDef): VIEW = None SCHEMA = schemas.ComputerAccessory - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class MouseDef(ComputerAccessoryDef): @@ -215,11 +341,31 @@ class NetworkingDef(DeviceDef): VIEW = None SCHEMA = schemas.Networking - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class RouterDef(NetworkingDef): @@ -246,11 +392,31 @@ class PrinterDef(DeviceDef): VIEW = None SCHEMA = schemas.Printer - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class LabelPrinterDef(PrinterDef): @@ -262,11 +428,31 @@ class SoundDef(DeviceDef): VIEW = None SCHEMA = schemas.Sound - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class MicrophoneDef(SoundDef): @@ -278,11 +464,31 @@ class VideoDef(DeviceDef): VIEW = None SCHEMA = schemas.Video - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class VideoScalerDef(VideoDef): @@ -299,11 +505,31 @@ class CookingDef(DeviceDef): VIEW = None SCHEMA = schemas.Cooking - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class Mixer(CookingDef): @@ -315,11 +541,31 @@ class DIYAndGardeningDef(DeviceDef): VIEW = None SCHEMA = schemas.DIYAndGardening - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class DrillDef(DIYAndGardeningDef): @@ -331,22 +577,62 @@ class PackOfScrewdriversDef(DIYAndGardeningDef): VIEW = None SCHEMA = schemas.PackOfScrewdrivers - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class HomeDef(DeviceDef): VIEW = None SCHEMA = schemas.Home - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class DehumidifierDef(HomeDef): @@ -363,11 +649,31 @@ class RecreationDef(DeviceDef): VIEW = None SCHEMA = schemas.Recreation - def __init__(self, app, import_name=__name__, static_folder=None, static_url_path=None, - template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, - root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): - super().__init__(app, import_name, static_folder, static_url_path, template_folder, - url_prefix, subdomain, url_defaults, root_path, cli_commands) + def __init__( + self, + app, + import_name=__name__, + static_folder=None, + static_url_path=None, + template_folder=None, + url_prefix=None, + subdomain=None, + url_defaults=None, + root_path=None, + cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(), + ): + super().__init__( + app, + import_name, + static_folder, + static_url_path, + template_folder, + url_prefix, + subdomain, + url_defaults, + root_path, + cli_commands, + ) class BikeDef(RecreationDef): diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index 890dd287..b689a968 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -269,6 +269,10 @@ class TelevisionSet(Monitor): __doc__ = m.TelevisionSet.__doc__ +class Projector(Monitor): + __doc__ = m.Projector.__doc__ + + class Mobile(Device): __doc__ = m.Mobile.__doc__ diff --git a/ereuse_devicehub/templates/inventory/device_create.html b/ereuse_devicehub/templates/inventory/device_create.html index 6acf564f..603aee38 100644 --- a/ereuse_devicehub/templates/inventory/device_create.html +++ b/ereuse_devicehub/templates/inventory/device_create.html @@ -46,7 +46,13 @@ + {% if form.type.data == 'ComputerMonitor' %} selected="selected"{% endif %}>Computer Monitor + + +