From ae310ece6d59d71f0a94a5474b45227680024381 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 19 Jun 2023 11:31:40 +0200 Subject: [PATCH 1/6] edit appearance and functionality in placeholder --- ereuse_devicehub/inventory/forms.py | 34 +++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index f9b10aa2..3eb12562 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -41,7 +41,7 @@ from ereuse_devicehub.inventory.models import ( from ereuse_devicehub.parser.models import PlaceholdersLog, SnapshotsLog from ereuse_devicehub.parser.parser import ParseSnapshotLsHw from ereuse_devicehub.parser.schemas import Snapshot_lite -from ereuse_devicehub.resources.action.models import Snapshot, Trade +from ereuse_devicehub.resources.action.models import Snapshot, Trade, VisualTest from ereuse_devicehub.resources.action.schemas import Snapshot as SnapshotSchema from ereuse_devicehub.resources.action.views.snapshot import ( SnapshotMixin, @@ -480,6 +480,10 @@ class NewDeviceForm(FlaskForm): if self._obj.type in ['HardDrive', 'SolidStateDrive']: if self._obj.size: self.data_storage_size.data = self._obj.size / 1000 + if self._obj.appearance(): + self.appearance.data = self._obj.appearance().name + if self._obj.functionality(): + self.functionality.data = self._obj.functionality().name if self._obj.placeholder.is_abstract: self.type.render_kw = disabled @@ -698,17 +702,25 @@ class NewDeviceForm(FlaskForm): if self.data_storage_size.data: self._obj.size = self.data_storage_size.data * 1000 - if ( - self.appearance.data - and self.appearance.data != self._obj.appearance().name - ): - self._obj.set_appearance(self.appearance.data) + if not self._obj.appearance() or not self._obj.functionality(): + visual_test = VisualTest( + appearance_range=self.appearance.data, + functionality_range=self.functionality.data, + device=self._obj, + ) + db.session.add(visual_test) + else: + if ( + self.appearance.data + and self.appearance.data != self._obj.appearance().name + ): + self._obj.set_appearance(self.appearance.data) - if ( - self.functionality.data - and self.functionality.data != self._obj.functionality().name - ): - self._obj.set_functionality(self.functionality.data) + if ( + self.functionality.data + and self.functionality.data != self._obj.functionality().name + ): + self._obj.set_functionality(self.functionality.data) else: self._obj.placeholder.id_device_supplier = ( From c79cfd05fa27d6ea3052f8a355e014303d09545a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 19 Jun 2023 12:24:06 +0200 Subject: [PATCH 2/6] fix appearance in snapshots device --- ereuse_devicehub/inventory/forms.py | 42 ++++++++++++++++------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 3eb12562..4bb4d093 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -702,25 +702,7 @@ class NewDeviceForm(FlaskForm): if self.data_storage_size.data: self._obj.size = self.data_storage_size.data * 1000 - if not self._obj.appearance() or not self._obj.functionality(): - visual_test = VisualTest( - appearance_range=self.appearance.data, - functionality_range=self.functionality.data, - device=self._obj, - ) - db.session.add(visual_test) - else: - if ( - self.appearance.data - and self.appearance.data != self._obj.appearance().name - ): - self._obj.set_appearance(self.appearance.data) - - if ( - self.functionality.data - and self.functionality.data != self._obj.functionality().name - ): - self._obj.set_functionality(self.functionality.data) + self.edit_visual_test(self._obj) else: self._obj.placeholder.id_device_supplier = ( @@ -730,11 +712,33 @@ class NewDeviceForm(FlaskForm): self.id_device_internal.data or None ) self._obj.placeholder.pallet = self.pallet.data or None + + pl_dev = self._obj.placeholder.device + self.edit_visual_test(pl_dev) + placeholder_log = PlaceholdersLog( type="Update", source='Web form', placeholder=self._obj.placeholder ) db.session.add(placeholder_log) + def edit_visual_test(self, dev): + if not dev.appearance() or not dev.functionality(): + visual_test = VisualTest( + appearance_range=self.appearance.data, + functionality_range=self.functionality.data, + device=dev, + ) + db.session.add(visual_test) + else: + if self.appearance.data and self.appearance.data != dev.appearance().name: + dev.set_appearance(self.appearance.data) + + if ( + self.functionality.data + and self.functionality.data != dev.functionality().name + ): + dev.set_functionality(self.functionality.data) + class TagDeviceForm(FlaskForm): tag = SelectField( From b405f715e0687ff1cbca7992233bf61c8631b997 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 19 Jun 2023 17:54:35 +0200 Subject: [PATCH 3/6] fix devices per page --- ereuse_devicehub/resources/device/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index a8d0e88d..6e0f3f86 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -176,7 +176,7 @@ class DeviceView(View): """Gets many devices.""" # Compute query query = self.query(args) - devices = query.paginate(page=args['page'], per_page=30) # type: Pagination + devices = query.paginate(page=args['page'], per_page=100) # type: Pagination return things_response( self.schema.dump(devices.items, many=True, nested=1), devices.page, From d5e93f3a52d76251cbce6767c74184646b9e422b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 26 Jul 2023 09:36:33 +0200 Subject: [PATCH 4/6] add solar panel module and migration --- .../versions/8ccba3cb37c2_add_solar_panel.py | 41 +++++++++++++++++++ ereuse_devicehub/resources/device/models.py | 11 ++++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 ereuse_devicehub/migrations/versions/8ccba3cb37c2_add_solar_panel.py diff --git a/ereuse_devicehub/migrations/versions/8ccba3cb37c2_add_solar_panel.py b/ereuse_devicehub/migrations/versions/8ccba3cb37c2_add_solar_panel.py new file mode 100644 index 00000000..f5dc87df --- /dev/null +++ b/ereuse_devicehub/migrations/versions/8ccba3cb37c2_add_solar_panel.py @@ -0,0 +1,41 @@ +"""add solar panel + +Revision ID: 8ccba3cb37c2 +Revises: 5169765e2653 +Create Date: 2023-07-26 09:23:21.326465 + +""" +import sqlalchemy as sa +from alembic import context, op + +# revision identifiers, used by Alembic. +revision = '8ccba3cb37c2' +down_revision = '5169765e2653' +branch_labels = None +depends_on = None + + +def get_inv(): + INV = context.get_x_argument(as_dictionary=True).get('inventory') + if not INV: + raise ValueError("Inventory value is not specified") + return INV + + +def upgrade(): + # creating Solar panel device. + + op.create_table( + 'solar_panel', + sa.Column('id', sa.BigInteger(), nullable=False), + sa.ForeignKeyConstraint( + ['id'], + [f'{get_inv()}.device.id'], + ), + sa.PrimaryKeyConstraint('id'), + schema=f'{get_inv()}', + ) + + +def downgrade(): + op.drop_table('solar_panel', schema=f'{get_inv()}') diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index ca7ea9be..593ce4e3 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -476,7 +476,8 @@ class Device(Thing): """The trading state, or None if no Trade action has ever been performed to this device. This extract the posibilities for to do. This method is performed for show in the web. - If you need to do one simple and generic response you can put simple=True for that.""" + If you need to do one simple and generic response you can put simple=True for that. + """ if not hasattr(lot, 'trade'): return @@ -1986,3 +1987,11 @@ class Other(Device): """ id = Column(BigInteger, ForeignKey(Device.id), primary_key=True) + + +class SolarPanel(Device): + """ + Used solar panels devices. + """ + + id = Column(BigInteger, ForeignKey(Device.id), primary_key=True) From 3408af33a8e2ad095f00bfdc458443c2beee7f60 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 26 Jul 2023 12:58:07 +0200 Subject: [PATCH 5/6] 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 %} From 72e4481b5d0c5c6f30a7c5336b83711fc9bc80a3 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 26 Jul 2023 13:39:24 +0200 Subject: [PATCH 6/6] fix test --- tests/test_basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_basic.py b/tests/test_basic.py index 3922e959..847521bc 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -125,4 +125,4 @@ def test_api_docs(client: Client): 'scheme': 'basic', 'name': 'Authorization', } - assert len(docs['definitions']) == 135 + assert len(docs['definitions']) == 136