Merge pull request #461 from eReuse/bugfix/4464-export-hdd

Bugfix/4464 export hdd
This commit is contained in:
cayop 2023-08-01 17:58:03 +02:00 committed by GitHub
commit 4b7bf24d86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 19 deletions

View File

@ -92,10 +92,21 @@ class Sync:
# We only want to perform Add/Remove to not new components # We only want to perform Add/Remove to not new components
actions = self.add_remove(db_device, not_new_components) actions = self.add_remove(db_device, not_new_components)
db_device.components = db_components db_device.components = db_components
self.clean_parent_orphans_components(db_device)
self.create_placeholder(db_device) self.create_placeholder(db_device)
return db_device, actions return db_device, actions
def clean_parent_orphans_components(self, device):
all_components = Component.query.filter_by(parent_id=device.id)
for _c in all_components:
if _c not in device.components:
_c.parent = None
if _c.binding:
_c.binding.device.parent = None
if _c.placeholder and _c.placeholder.binding:
_c.placeholder.binding.parent = None
def execute_register_component(self, component: Component): def execute_register_component(self, component: Component):
"""Synchronizes one component to the DB. """Synchronizes one component to the DB.

View File

@ -422,30 +422,37 @@ class DeviceRow(BaseDeviceRow):
self['{} {} Speed (MHz)'.format(ctype, i)] = none2str(component.speed) self['{} {} Speed (MHz)'.format(ctype, i)] = none2str(component.speed)
def get_erasure_datawipe_mobile(self, device): def get_erasure_datawipe_mobile(self, device):
if isinstance(device, d.DataStorage):
if device.placeholder and device.placeholder.binding:
binding = device.placeholder.binding
return self.get_datastorage('DataStorage', 1, binding)
return self.get_datastorage('DataStorage', 1, device)
if not isinstance(device, d.Mobile):
return
actions = sorted(device.actions) actions = sorted(device.actions)
erasures = [a for a in actions if a.type == 'EraseDataWipe'] erasures = [a for a in actions if a.type == 'EraseDataWipe']
erasure = erasures[-1] if erasures else None erasure = erasures[-1] if erasures else None
if erasure:
self['Erasure DataStorage 1'] = none2str(device.chid)
if isinstance(device, d.Mobile):
serial_number = none2str(device.imei)
size = device.data_storage_size
size = size * 1000 if size else 0
storage_size = none2str(size)
if isinstance(device, d.DataStorage): if not erasure:
serial_number = none2str(device.serial_number) return
storage_size = none2str(device.size)
self['Erasure DataStorage 1 Serial Number'] = serial_number self['Erasure DataStorage 1'] = none2str(device.chid)
self['Erasure DataStorage 1 Size (MB)'] = storage_size serial_number = none2str(device.imei)
self['Erasure DataStorage 1 Software'] = erasure.document.software size = device.data_storage_size
self['Erasure DataStorage 1 Result'] = get_result(erasure) size = size * 1000 if size else 0
self['Erasure DataStorage 1 Type'] = erasure.type storage_size = none2str(size)
self['Erasure DataStorage 1 Date'] = format(erasure.document.date or '')
self['Erasure DataStorage 1 Certificate URL'] = ( self['Erasure DataStorage 1 Serial Number'] = serial_number
erasure.document.url and erasure.document.url.to_text() or '' self['Erasure DataStorage 1 Size (MB)'] = storage_size
) self['Erasure DataStorage 1 Result'] = get_result(erasure)
self['Erasure DataStorage 1 Type'] = erasure.type
self['Erasure DataStorage 1 Software'] = erasure.document.software
self['Erasure DataStorage 1 Date'] = format(erasure.document.date or '')
self['Erasure DataStorage 1 Certificate URL'] = (
erasure.document.url and erasure.document.url.to_text() or ''
)
def get_datastorage(self, ctype, i, component): def get_datastorage(self, ctype, i, component):
"""Particular fields for component DataStorage. """Particular fields for component DataStorage.