Add generic export computer
This commit is contained in:
parent
c299656f05
commit
e17352879a
|
@ -19,7 +19,7 @@ from ereuse_devicehub.db import db
|
|||
from ereuse_devicehub.resources import search
|
||||
# from ereuse_devicehub.resources.device.definitions import ComponentDef
|
||||
from ereuse_devicehub.resources.device.models import Component, Computer, Device, Manufacturer, \
|
||||
RamModule, Processor, DataStorage
|
||||
RamModule, Processor, DataStorage, GraphicCard, Motherboard, Display, NetworkAdapter, SoundCard
|
||||
from ereuse_devicehub.resources.device.search import DeviceSearch
|
||||
from ereuse_devicehub.resources.event.models import Rate, Event
|
||||
from ereuse_devicehub.resources.lot.models import Lot, LotDevice
|
||||
|
@ -154,18 +154,25 @@ class DeviceView(View):
|
|||
data = StringIO()
|
||||
cw = csv.writer(data)
|
||||
first = True
|
||||
# todo fix if only export components
|
||||
for device in query:
|
||||
# if not isinstance(device, Component):
|
||||
d = DeviceRow(device)
|
||||
if first:
|
||||
cw.writerow(name for name in d.keys())
|
||||
cw.writerow(v for v in d.values())
|
||||
first = False
|
||||
elif isinstance(device, Computer):
|
||||
cw.writerow(v for v in d.values())
|
||||
output = make_response(data.getvalue())
|
||||
output.headers['Content-Disposition'] = 'attachment; filename=export.csv'
|
||||
output.headers['Content-type'] = 'text/csv'
|
||||
return output
|
||||
|
||||
def generate_erase_certificate(self, query):
|
||||
|
||||
""" Export Erased Certificate Code
|
||||
|
||||
def generate_erased_certificate(self, query):
|
||||
data = StringIO()
|
||||
cw = csv.writer(data)
|
||||
first = True
|
||||
|
@ -187,7 +194,6 @@ class EraseDataStorage(OrderedDict):
|
|||
super().__init__()
|
||||
self.device = device
|
||||
|
||||
|
||||
# General Information
|
||||
self['Organization'] = device.org
|
||||
self['Date report'] = datetime.time()
|
||||
|
@ -216,30 +222,39 @@ class EraseDataStorage(OrderedDict):
|
|||
self['Computer Model'] = device.model
|
||||
self['Computer Manufacturer'] = device.manufacturer
|
||||
self['Computer Tag'] = device.tags
|
||||
"""
|
||||
|
||||
|
||||
class DeviceRow(OrderedDict):
|
||||
NUMS = {
|
||||
Processor.t: 1
|
||||
Display.t: 2,
|
||||
Processor.t: 2,
|
||||
GraphicCard.t: 2,
|
||||
Motherboard.t: 1,
|
||||
NetworkAdapter.t: 2,
|
||||
SoundCard.t: 2
|
||||
}
|
||||
|
||||
def __init__(self, device: Device) -> None:
|
||||
super().__init__()
|
||||
self.device = device
|
||||
# General information about device
|
||||
self['Type'] = device.t
|
||||
if isinstance(device, Computer):
|
||||
self['Chassis'] = device.chassis.
|
||||
self['Chassis'] = device.chassis
|
||||
self['Tag 1'] = self['Tag 2'] = self['Tag 3'] = ''
|
||||
for i, tag in zip(range(1, 3), device.tags):
|
||||
self['Tag {}'.format(i)] = format(tag)
|
||||
self['Serial Number'] = device.serial_number
|
||||
self['Price'] = device.price
|
||||
self['Model'] = device.model
|
||||
self['Manufacturer'] = device.manufacturer
|
||||
self['Registered in '] = device.created
|
||||
# self['State'] = device.last_event_of()
|
||||
self['Price'] = device.price
|
||||
self['Registered in'] = format(device.created, '%c')
|
||||
if isinstance(device, Computer):
|
||||
self['Processor'] = device.processor_model
|
||||
self['RAM (GB)'] = device.ram_size
|
||||
self['Size (MB)'] = device.data_storage_size
|
||||
self['Storage Size (MB)'] = device.data_storage_size
|
||||
rate = device.rate
|
||||
if rate:
|
||||
self['Rate'] = rate.rating
|
||||
|
@ -250,27 +265,69 @@ class DeviceRow(OrderedDict):
|
|||
self['RAM Range'] = rate.workbench.ram_range
|
||||
self['Data Storage Rate'] = rate.data_storage
|
||||
self['Data Storage Range'] = rate.workbench.data_storage_range
|
||||
# More specific information about components
|
||||
if isinstance(device, Computer):
|
||||
self.components()
|
||||
|
||||
|
||||
def components(self):
|
||||
"""
|
||||
Function to get all components information of a device
|
||||
"""
|
||||
assert isinstance(self.device, Computer)
|
||||
for type in app.resources[Component.t].subresources_types: # type: str
|
||||
# todo put an input specific order (non alphabetic)
|
||||
for type in sorted(app.resources[Component.t].subresources_types): # type: str
|
||||
max = self.NUMS.get(type, 4)
|
||||
if type not in ['Component', 'HardDrive', 'SolidStateDrive']:
|
||||
i = 1
|
||||
for component in (r for r in self.device.components if r.type == type):
|
||||
self.fill_component(type, i, component)
|
||||
i += 1
|
||||
if i >= max:
|
||||
if i > max:
|
||||
break
|
||||
while i < max:
|
||||
while i <= max:
|
||||
self.fill_component(type, i)
|
||||
i += 1
|
||||
|
||||
def fill_component(self, type, i, component = None):
|
||||
def fill_component(self, type, i, component=None):
|
||||
"""
|
||||
Function to put specific information of components in OrderedDict (csv)
|
||||
:param type: type of component
|
||||
:param component: device.components
|
||||
"""
|
||||
self['{} {}'.format(type, i)] = format(component) if component else ''
|
||||
self['{} {} Manufacturer'.format(type, i)] = component.serial_number if component else ''
|
||||
self['{} {} Model'.format(type, i)] = component.serial_number if component else ''
|
||||
self['{} {} Serial Number'.format(type, i)] = component.serial_number if component else ''
|
||||
|
||||
""" Particular fields for component GraphicCard """
|
||||
if isinstance(component, GraphicCard):
|
||||
self['{} {} Memory (MB)'.format(type, i)] = component.memory
|
||||
|
||||
""" Particular fields for component DataStorage.t -> (HardDrive, SolidStateDrive) """
|
||||
if isinstance(component, DataStorage):
|
||||
self['{} {} Compliance'.format()] = component.compliance
|
||||
self['{} {} Size (MB)'.format(type, i)] = component.size
|
||||
self['{} {} Privacy'.format(type, i)] = component.privacy
|
||||
|
||||
# todo decide if is relevant more info about Motherboard
|
||||
""" Particular fields for component Motherboard """
|
||||
if isinstance(component, Motherboard):
|
||||
self['{} {} Slots'.format(type, i)] = component.slots
|
||||
|
||||
""" Particular fields for component Processor """
|
||||
if isinstance(component, Processor):
|
||||
self['{} {} Number of cores'.format(type, i)] = component.cores
|
||||
self['{} {} Speed (GHz)'.format(type, i)] = component.speed
|
||||
|
||||
""" Particular fields for component RamModule """
|
||||
if isinstance(component, RamModule):
|
||||
self['{} {} Size (MB)'.format(type, i)] = component.size
|
||||
self['{} {} Speed (MHz)'.format(type, i)] = component.speed
|
||||
self['{} {} Size'.format(type, i)] = component.size
|
||||
|
||||
# todo add Display size, ...
|
||||
# todo add NetworkAdapter speedLink?
|
||||
# todo add some ComputerAccessories
|
||||
|
||||
|
||||
class ManufacturerView(View):
|
||||
|
|
Reference in New Issue