diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 9e47b557..cc57ed74 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -187,7 +187,9 @@ class Device(Thing): if 't' in format_spec: v += '{0.t} {0.model}'.format(self) if 's' in format_spec: - v += '({0.manufacturer}) S/N {0.serial_number}'.format(self) + v += '({0.manufacturer})'.format(self) + if self.serial_number: + v += ' S/N ' + self.serial_number.upper() return v @@ -272,7 +274,9 @@ class Computer(Device): if 't' in format_spec: v += '{0.chassis} {0.model}'.format(self) elif 's' in format_spec: - v += '({0.manufacturer}) S/N {0.serial_number}'.format(self) + v += '({0.manufacturer})'.format(self) + if self.serial_number: + v += ' S/N ' + self.serial_number.upper() return v diff --git a/ereuse_devicehub/resources/device/states.py b/ereuse_devicehub/resources/device/states.py index 99247573..809e0a64 100644 --- a/ereuse_devicehub/resources/device/states.py +++ b/ereuse_devicehub/resources/device/states.py @@ -12,7 +12,7 @@ class State(Enum): return (s.value for s in cls) def __str__(self): - return inflection.humanize(self.name) + return inflection.humanize(inflection.underscore(self.name)) class Trading(State): diff --git a/ereuse_devicehub/resources/device/static/magrama.svg b/ereuse_devicehub/resources/device/static/magrama.svg new file mode 100644 index 00000000..b792c830 --- /dev/null +++ b/ereuse_devicehub/resources/device/static/magrama.svg @@ -0,0 +1,3 @@ + +PlataformaRAEE08006417910000001670001COCINAS41*Grandesaparatosconcomponentespeligrosos diff --git a/ereuse_devicehub/resources/device/templates/devices/layout.html b/ereuse_devicehub/resources/device/templates/devices/layout.html index 927e2bd0..0f7d0957 100644 --- a/ereuse_devicehub/resources/device/templates/devices/layout.html +++ b/ereuse_devicehub/resources/device/templates/devices/layout.html @@ -10,181 +10,213 @@ crossorigin="anonymous"> Devicehub | {{ device.__format__('t') }} - + - - - - + diff --git a/ereuse_devicehub/resources/enums.py b/ereuse_devicehub/resources/enums.py index 7376bce4..de99d8f7 100644 --- a/ereuse_devicehub/resources/enums.py +++ b/ereuse_devicehub/resources/enums.py @@ -245,7 +245,7 @@ class ComputerChassis(Enum): Virtual = 'Non-physical device' def __format__(self, format_spec): - return self.value.lower() + return inflection.humanize(inflection.underscore(self.value)) class ReceiverRole(Enum): diff --git a/ereuse_devicehub/resources/tag/view.py b/ereuse_devicehub/resources/tag/view.py index 344b9e3e..4d756aeb 100644 --- a/ereuse_devicehub/resources/tag/view.py +++ b/ereuse_devicehub/resources/tag/view.py @@ -1,6 +1,6 @@ -from flask import Response, current_app as app, request +from flask import Response, current_app as app, redirect, request from teal.marshmallow import ValidationError -from teal.resource import View +from teal.resource import View, url_for_resource from ereuse_devicehub.db import db from ereuse_devicehub.resources.device.models import Device @@ -27,6 +27,8 @@ class TagDeviceView(View): tag = Tag.from_an_id(id).one() # type: Tag if not tag.device: raise TagNotLinked(tag.id) + if not request.authorization: + return redirect(location=url_for_resource(Device, tag.device.id)) return app.resources[Device.t].schema.jsonify(tag.device) # noinspection PyMethodOverriding @@ -55,6 +57,8 @@ def get_device_from_tag(id: str): """ # todo this could be more efficient by Device.query... join with tag device = Tag.query.filter_by(id=id).one().device + if not request.authorization: + return redirect(location=url_for_resource(Device, device.id)) if device is None: raise TagNotLinked(id) return app.resources[Device.t].schema.jsonify(device) diff --git a/tests/test_device.py b/tests/test_device.py index ee392400..a630f490 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -506,8 +506,8 @@ def test_device_properties_format(app: Devicehub, user: UserClient): with app.app_context(): pc = Laptop.query.one() # type: Laptop assert format(pc) == 'Laptop 1: model 1000h, S/N 94oaaq021116' - assert format(pc, 't') == 'netbook 1000h' - assert format(pc, 's') == '(asustek computer inc.) S/N 94oaaq021116' + assert format(pc, 't') == 'Netbook 1000h' + assert format(pc, 's') == '(asustek computer inc.) S/N 94OAAQ021116' assert pc.ram_size == 1024 assert pc.data_storage_size == 152627 assert pc.graphic_card_model == 'mobile 945gse express integrated graphics controller' @@ -516,18 +516,18 @@ def test_device_properties_format(app: Devicehub, user: UserClient): assert format(net) == 'NetworkAdapter 2: model ar8121/ar8113/ar8114 ' \ 'gigabit or fast ethernet, S/N 00:24:8c:7f:cf:2d' assert format(net, 't') == 'NetworkAdapter ar8121/ar8113/ar8114 gigabit or fast ethernet' - assert format(net, 's') == '(qualcomm atheros) S/N 00:24:8c:7f:cf:2d – 100 Mbps' + assert format(net, 's') == '(qualcomm atheros) S/N 00:24:8C:7F:CF:2D – 100 Mbps' hdd = next(c for c in pc.components if isinstance(c, DataStorage)) assert format(hdd) == 'HardDrive 7: model st9160310as, S/N 5sv4tqa6' assert format(hdd, 't') == 'HardDrive st9160310as' - assert format(hdd, 's') == '(seagate) S/N 5sv4tqa6 – 152 GB' + assert format(hdd, 's') == '(seagate) S/N 5SV4TQA6 – 152 GB' def test_device_public(user: UserClient, client: Client): s, _ = user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot) html, _ = client.get(res=Device, item=s['device']['id'], accept=ANY) assert 'intel atom cpu n270 @ 1.60ghz' in html - assert 'S/N 00:24:8c:7f:cf:2d – 100 Mbps' in html + assert 'S/N 00:24:8C:7F:CF:2D – 100 Mbps' in html @pytest.mark.xfail(reason='Functionality not yet developed.')