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/templates/inventory/erasure_list.html b/ereuse_devicehub/templates/inventory/erasure_list.html index 29a53d8b..1b55ba97 100644 --- a/ereuse_devicehub/templates/inventory/erasure_list.html +++ b/ereuse_devicehub/templates/inventory/erasure_list.html @@ -21,33 +21,51 @@
+ {% if orphans %} + + {% endif %} + {% if orphans %} + + {% endif %}