diff --git a/CHANGELOG.md b/CHANGELOG.md index 044b40bd..3d6b36a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ml). - [added] #387 add template settings for Secure Erasure. - [added] #397 add obada standard export. - [added] #402 add reset password module. +- [added] #406 add orphans disks page. - [changed] #391 add dhid in table and export of Erasure section. - [changed] #395 change response for the new api to workbench. - [changed] #396 modularize commands. diff --git a/ereuse_devicehub/__init__.py b/ereuse_devicehub/__init__.py index 60be088d..5a8e0983 100644 --- a/ereuse_devicehub/__init__.py +++ b/ereuse_devicehub/__init__.py @@ -1 +1 @@ -__version__ = "2.4.2" +__version__ = "2.4.3" diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 93740af5..1d34a7b3 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -115,15 +115,19 @@ class DeviceListMixin(GenericMixin): class ErasureListView(DeviceListMixin): template_name = 'inventory/erasure_list.html' - def dispatch_request(self): + def dispatch_request(self, orphans=0): self.get_context() - self.get_devices() + self.get_devices(orphans) + if orphans: + self.context['orphans'] = True return flask.render_template(self.template_name, **self.context) - def get_devices(self): + def get_devices(self, orphans): erasure = EraseBasic.query.filter_by(author=g.user).order_by( EraseBasic.created.desc() ) + if orphans: + erasure = [e for e in erasure if e.device.orphan] self.context['erasure'] = erasure @@ -1452,3 +1456,7 @@ devices.add_url_rule( devices.add_url_rule( '/device/erasure/', view_func=ErasureListView.as_view('device_erasure_list') ) +devices.add_url_rule( + '/device/erasure//', + view_func=ErasureListView.as_view('device_erasure_list_orphans'), +) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 86d8c834..0f398737 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -1326,6 +1326,19 @@ class DataStorage(JoinedComponentTableMixin, Component): except LookupError: return None + @property + def orphan(self): + if not self.parent: + return True + + if self.parent.placeholder and self.parent.placeholder.kangaroo: + return True + + if self.parent.binding and self.parent.binding.kangaroo: + return True + + return False + class HardDrive(DataStorage): pass diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index c3416db2..80922e47 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -306,7 +306,7 @@ class LotDeviceView(LotBaseChildrenView): dev_qry = Device.query.filter(Device.id.in_(ids)).filter(Device.owner == g.user) for dev in dev_qry: - if isinstance(dev, DataStorage) and dev.parent: + if isinstance(dev, DataStorage) and not dev.orphan: continue devices.add(dev) diff --git a/ereuse_devicehub/templates/inventory/erasure_list.html b/ereuse_devicehub/templates/inventory/erasure_list.html index e33bed45..adaec94f 100644 --- a/ereuse_devicehub/templates/inventory/erasure_list.html +++ b/ereuse_devicehub/templates/inventory/erasure_list.html @@ -18,9 +18,54 @@
-
+ +
+ {% if orphans %} + + {% endif %} + {% if orphans %} + + {% endif %}
@@ -74,11 +140,24 @@
{% if ac.device.phid() %} + {% if ac.device.get_type_logo() %} + + {% endif %} {{ ac.device.serial_number.upper() }} {% else %} + {% if ac.device.get_type_logo() %} + + {% endif %} {{ ac.device.serial_number.upper() }} {% endif %} + {% if ac.device.lots | length > 0 %} +
+ {% for lot in ac.device.get_lots_for_template() %} + {{ lot }} + {% endfor %} +
+ {% endif %}
{% if ac.device.phid() %} diff --git a/ereuse_devicehub/templates/labels/print_labels.html b/ereuse_devicehub/templates/labels/print_labels.html index 0e36d68d..e8db7d0c 100644 --- a/ereuse_devicehub/templates/labels/print_labels.html +++ b/ereuse_devicehub/templates/labels/print_labels.html @@ -32,7 +32,7 @@
-
+
@@ -41,7 +41,7 @@ data-model="{{ dev.model or '' }}" data-tags="{{ dev.list_tags() }}" data-phid="{{ dev.phid() }}" - data-sid="{{ dev.sid or '' }}">{{ dev.devicehub_id }} + data-sid="{{ dev.sid or '' }}">{{ dev.dhid }}
@@ -192,7 +192,7 @@ {% endblock main %} diff --git a/tests/test_basic.py b/tests/test_basic.py index 3d7a0ad8..68c7d696 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -56,6 +56,7 @@ def test_api_docs(client: Client): '/inventory/device/{id}/', '/inventory/device/{dhid}/binding/', '/inventory/device/erasure/', + '/inventory/device/erasure/{orphans}/', '/inventory/all/device/', '/inventory/export/{export_id}/', '/inventory/lot/add/', diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index f9f82928..0a95eee1 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -2393,6 +2393,19 @@ def test_list_erasures(user3: UserClientFlask): assert status == '200 OK' assert txt in body + uri = '/inventory/device/erasure/1/' + body, status = user3.get(uri) + assert status == '200 OK' + assert txt not in body + + dev = Device.query.first() + dev.binding.kangaroo = True + db.session.commit() + + body, status = user3.get(uri) + assert status == '200 OK' + assert txt in body + @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__)