Adding exceptions to device_row.py file
This commit is contained in:
parent
f97b239abe
commit
59932ba00d
|
@ -30,27 +30,23 @@ class DeviceRow(OrderedDict):
|
||||||
self['Tag 1'] = self['Tag 2'] = self['Tag 3'] = ''
|
self['Tag 1'] = self['Tag 2'] = self['Tag 3'] = ''
|
||||||
for i, tag in zip(range(1, 3), device.tags):
|
for i, tag in zip(range(1, 3), device.tags):
|
||||||
self['Tag {}'.format(i)] = format(tag)
|
self['Tag {}'.format(i)] = format(tag)
|
||||||
self['Serial Number'] = device.serial_number
|
self['Serial Number'] = convert_none_to_empty_str(device.serial_number)
|
||||||
self['Model'] = device.model
|
self['Model'] = convert_none_to_empty_str(device.model)
|
||||||
self['Manufacturer'] = device.manufacturer
|
self['Manufacturer'] = convert_none_to_empty_str(device.manufacturer)
|
||||||
# self['State'] = device.last_action_of()
|
|
||||||
self['Registered in'] = format(device.created, '%c')
|
self['Registered in'] = format(device.created, '%c')
|
||||||
try:
|
try:
|
||||||
self['Physical state'] = device.last_action_of(*states.Physical.actions()).t
|
self['Physical state'] = device.last_action_of(*states.Physical.actions()).t
|
||||||
except:
|
except LookupError:
|
||||||
self['Physical state'] = ''
|
self['Physical state'] = ''
|
||||||
try:
|
try:
|
||||||
self['Trading state'] = device.last_action_of(*states.Trading.actions()).t
|
self['Trading state'] = device.last_action_of(*states.Trading.actions()).t
|
||||||
except:
|
except LookupError:
|
||||||
self['Trading state'] = ''
|
self['Trading state'] = ''
|
||||||
try:
|
self['Price'] = convert_none_to_empty_str(device.price)
|
||||||
self['Price'] = device.price
|
|
||||||
except:
|
|
||||||
self['Price'] = ''
|
|
||||||
if isinstance(device, d.Computer):
|
if isinstance(device, d.Computer):
|
||||||
self['Processor'] = device.processor_model
|
self['Processor'] = convert_none_to_empty_str(device.processor_model)
|
||||||
self['RAM (MB)'] = device.ram_size
|
self['RAM (MB)'] = convert_none_to_empty_str(device.ram_size)
|
||||||
self['Data Storage Size (MB)'] = device.data_storage_size
|
self['Data Storage Size (MB)'] = convert_none_to_empty_str(device.data_storage_size)
|
||||||
rate = device.rate
|
rate = device.rate
|
||||||
if rate:
|
if rate:
|
||||||
self['Rate'] = rate.rating
|
self['Rate'] = rate.rating
|
||||||
|
@ -137,35 +133,27 @@ class StockRow(OrderedDict):
|
||||||
def __init__(self, device: d.Device) -> None:
|
def __init__(self, device: d.Device) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.device = device
|
self.device = device
|
||||||
self['Type'] = device.t
|
self['Type'] = convert_none_to_empty_str(device.t)
|
||||||
if isinstance(device, d.Computer):
|
if isinstance(device, d.Computer):
|
||||||
self['Chassis'] = device.chassis
|
self['Chassis'] = device.chassis
|
||||||
else:
|
else:
|
||||||
self['Chassis'] = ''
|
self['Chassis'] = ''
|
||||||
self['Serial Number'] = device.serial_number
|
self['Serial Number'] = convert_none_to_empty_str(device.serial_number)
|
||||||
self['Model'] = device.model
|
self['Model'] = convert_none_to_empty_str(device.model)
|
||||||
self['Manufacturer'] = device.manufacturer
|
self['Manufacturer'] = convert_none_to_empty_str(device.manufacturer)
|
||||||
self['Registered in'] = format(device.created, '%c')
|
self['Registered in'] = format(device.created, '%c')
|
||||||
try:
|
try:
|
||||||
self['Physical state'] = device.last_action_of(*states.Physical.actions()).t
|
self['Physical state'] = device.last_action_of(*states.Physical.actions()).t
|
||||||
except:
|
except LookupError:
|
||||||
self['Physical state'] = ''
|
self['Physical state'] = ''
|
||||||
try:
|
try:
|
||||||
self['Trading state'] = device.last_action_of(*states.Trading.actions()).t
|
self['Trading state'] = device.last_action_of(*states.Trading.actions()).t
|
||||||
except:
|
except LookupError:
|
||||||
self['Trading state'] = ''
|
self['Trading state'] = ''
|
||||||
try:
|
self['Price'] = convert_none_to_empty_str(device.price)
|
||||||
self['Price'] = device.price
|
self['Processor'] = convert_none_to_empty_str(device.processor_model)
|
||||||
except:
|
self['RAM (MB)'] = convert_none_to_empty_str(device.ram_size)
|
||||||
self['Price'] = ''
|
self['Data Storage Size (MB)'] = convert_none_to_empty_str(device.data_storage_size)
|
||||||
try:
|
|
||||||
self['Processor'] = device.processor_model
|
|
||||||
self['RAM (MB)'] = device.ram_size
|
|
||||||
self['Data Storage Size (MB)'] = device.data_storage_size
|
|
||||||
except:
|
|
||||||
self['Processor'] = ''
|
|
||||||
self['RAM (MB)'] = ''
|
|
||||||
self['Data Storage Size (MB)'] = ''
|
|
||||||
rate = device.rate
|
rate = device.rate
|
||||||
if rate:
|
if rate:
|
||||||
self['Rate'] = rate.rating
|
self['Rate'] = rate.rating
|
||||||
|
@ -177,3 +165,9 @@ class StockRow(OrderedDict):
|
||||||
self['RAM Range'] = rate.ram_range
|
self['RAM Range'] = rate.ram_range
|
||||||
self['Data Storage Rate'] = rate.data_storage
|
self['Data Storage Rate'] = rate.data_storage
|
||||||
self['Data Storage Range'] = rate.data_storage_range
|
self['Data Storage Range'] = rate.data_storage_range
|
||||||
|
|
||||||
|
|
||||||
|
def convert_none_to_empty_str(s):
|
||||||
|
if s is None:
|
||||||
|
return ''
|
||||||
|
return s
|
||||||
|
|
|
@ -18,7 +18,6 @@ from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.resources.action import models as evs
|
from ereuse_devicehub.resources.action import models as evs
|
||||||
from ereuse_devicehub.resources.device import models as devs
|
from ereuse_devicehub.resources.device import models as devs
|
||||||
from ereuse_devicehub.resources.device.views import DeviceView
|
from ereuse_devicehub.resources.device.views import DeviceView
|
||||||
|
|
||||||
from ereuse_devicehub.resources.documents.device_row import DeviceRow, StockRow
|
from ereuse_devicehub.resources.documents.device_row import DeviceRow, StockRow
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import pytest
|
|
||||||
import teal.marshmallow
|
|
||||||
from ereuse_utils.test import ANY
|
|
||||||
import csv
|
import csv
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import teal.marshmallow
|
||||||
|
from ereuse_utils.test import ANY
|
||||||
|
|
||||||
from ereuse_devicehub.client import Client, UserClient
|
from ereuse_devicehub.client import Client, UserClient
|
||||||
from ereuse_devicehub.resources.action.models import Snapshot
|
from ereuse_devicehub.resources.action.models import Snapshot
|
||||||
from ereuse_devicehub.resources.documents import documents
|
from ereuse_devicehub.resources.documents import documents
|
||||||
|
|
Reference in New Issue