From 3408af33a8e2ad095f00bfdc458443c2beee7f60 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 26 Jul 2023 12:58:07 +0200 Subject: [PATCH] add solar panel to the interface --- ereuse_devicehub/inventory/forms.py | 9 +++--- .../resources/device/definitions.py | 31 +++++++++++++++++++ ereuse_devicehub/resources/device/schemas.py | 4 +++ .../templates/inventory/device_create.html | 2 ++ .../inventory/upload_placeholder.html | 6 ++++ 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 4bb4d093..5235c78e 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -68,6 +68,7 @@ from ereuse_devicehub.resources.device.models import ( Projector, Server, Smartphone, + SolarPanel, SolidStateDrive, Tablet, TelevisionSet, @@ -113,7 +114,7 @@ DEVICES = { "SAI", "Keyboard", ], - "Other Devices": ["Other"], + "Other Devices": ["SolarPanel", "Other"], } TYPES_DOCUMENTS = [ @@ -131,7 +132,7 @@ MONITORS = ["ComputerMonitor", "Monitor", "TelevisionSet", "Projector"] MOBILE = ["Mobile", "Tablet", "Smartphone", "Cellphone"] STORAGE = ["HardDrive", "SolidStateDrive"] ACCESSORIES = ["Mouse", "MemoryCardReader", "SAI", "Keyboard"] -OTHERS = ["Other"] +OTHERS = ["Other", "SolarPanel"] DATASTORAGE = ['HardDrive', 'SolidStateDrive'] @@ -433,6 +434,7 @@ class NewDeviceForm(FlaskForm): "Keyboard": Keyboard, "SAI": SAI, "MemoryCardReader": MemoryCardReader, + "SolarPanel": SolarPanel, "Other": Other, } @@ -1227,7 +1229,6 @@ class TradeForm(ActionFormMixin): or email_to == email_from or g.user.email not in [email_from, email_to] ): - errors = ["If you want confirm, you need a correct email"] self.user_to.errors = errors self.user_from.errors = errors @@ -1933,7 +1934,6 @@ class UploadPlaceholderForm(FlaskForm): return True def save(self, commit=True): - for device, placeholder_log in self.placeholders: db.session.add(device) db.session.add(placeholder_log) @@ -1962,7 +1962,6 @@ class EditPlaceholderForm(FlaskForm): return True def save(self, commit=True): - for device in self.placeholders: db.session.add(device) diff --git a/ereuse_devicehub/resources/device/definitions.py b/ereuse_devicehub/resources/device/definitions.py index febacf38..c9ac1142 100644 --- a/ereuse_devicehub/resources/device/definitions.py +++ b/ereuse_devicehub/resources/device/definitions.py @@ -726,3 +726,34 @@ class OtherDef(DeviceDef): root_path, cli_commands, ) + + +class SolarPanelDef(DeviceDef): + VIEW = None + SCHEMA = schemas.SolarPanel + + 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, + ) diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index 59f6afd5..7d168a03 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -590,5 +590,9 @@ class Racket(Recreation): pass +class SolarPanel(Device): + pass + + class Other(Device): pass diff --git a/ereuse_devicehub/templates/inventory/device_create.html b/ereuse_devicehub/templates/inventory/device_create.html index 3de677c9..82f0d7f2 100644 --- a/ereuse_devicehub/templates/inventory/device_create.html +++ b/ereuse_devicehub/templates/inventory/device_create.html @@ -79,6 +79,8 @@ {% if form.type.data == 'Keyboard' %} selected="selected"{% endif %}>Keyboard + diff --git a/ereuse_devicehub/templates/inventory/upload_placeholder.html b/ereuse_devicehub/templates/inventory/upload_placeholder.html index 7763cd43..141345ac 100644 --- a/ereuse_devicehub/templates/inventory/upload_placeholder.html +++ b/ereuse_devicehub/templates/inventory/upload_placeholder.html @@ -72,6 +72,12 @@ + + + + Type of devices {% if form.type.errors %}