Bigfixes for tag demo
This commit is contained in:
parent
84dd154cbe
commit
4b763ed1e8
|
@ -187,7 +187,9 @@ class Device(Thing):
|
||||||
if 't' in format_spec:
|
if 't' in format_spec:
|
||||||
v += '{0.t} {0.model}'.format(self)
|
v += '{0.t} {0.model}'.format(self)
|
||||||
if 's' in format_spec:
|
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
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
@ -272,7 +274,9 @@ class Computer(Device):
|
||||||
if 't' in format_spec:
|
if 't' in format_spec:
|
||||||
v += '{0.chassis} {0.model}'.format(self)
|
v += '{0.chassis} {0.model}'.format(self)
|
||||||
elif 's' in format_spec:
|
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
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ class State(Enum):
|
||||||
return (s.value for s in cls)
|
return (s.value for s in cls)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return inflection.humanize(self.name)
|
return inflection.humanize(inflection.underscore(self.name))
|
||||||
|
|
||||||
|
|
||||||
class Trading(State):
|
class Trading(State):
|
||||||
|
|
3
ereuse_devicehub/resources/device/static/magrama.svg
Normal file
3
ereuse_devicehub/resources/device/static/magrama.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 22 KiB |
|
@ -10,49 +10,67 @@
|
||||||
crossorigin="anonymous">
|
crossorigin="anonymous">
|
||||||
<title>Devicehub | {{ device.__format__('t') }}</title>
|
<title>Devicehub | {{ device.__format__('t') }}</title>
|
||||||
</head>
|
</head>
|
||||||
<body class="container">
|
<body>
|
||||||
|
|
||||||
<div class="page-header">
|
<nav class="navbar navbar-default" style="background-color: gainsboro; margin: 0 !important">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<a href="https://www.ereuse.org/" target="_blank">
|
||||||
|
<img alt="Brand"
|
||||||
|
class="center-block"
|
||||||
|
style="height: 4em; padding-bottom: 0.1em"
|
||||||
|
src="{{ url_for('Device.static', filename='ereuse-logo.svg') }}">
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<div class="jumbotron">
|
||||||
|
<img class="center-block"
|
||||||
|
style="height: 13em; padding-bottom: 0.1em"
|
||||||
|
src="{{ url_for('Device.static', filename='magrama.svg') }}">
|
||||||
|
</div>
|
||||||
|
<div class="container">
|
||||||
|
<div class="page-header">
|
||||||
<h1>{{ device.__format__('t') }}<br>
|
<h1>{{ device.__format__('t') }}<br>
|
||||||
<small>{{ device.__format__('s') }}</small>
|
<small>{{ device.__format__('s') }}</small>
|
||||||
</h1>
|
</h1>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="container">
|
||||||
<h2 class='text-center'>
|
<h2 class='text-center'>
|
||||||
This is your {{ device.t }}.
|
This is your {{ device.t }}.
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<div class="row">
|
<p class="text-center">
|
||||||
|
{% if device.trading %}
|
||||||
|
{{ device.trading }}
|
||||||
|
{% endif %}
|
||||||
|
{% if device.trading and device.physical %}
|
||||||
|
and
|
||||||
|
{% endif %}
|
||||||
|
{% if device.physical %}
|
||||||
|
{{ device.physical }}
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
<div class="row">
|
||||||
<article class="col-md-6">
|
<article class="col-md-6">
|
||||||
<h3>You can verify the originality of your device.</h3>
|
<h3>You can verify the originality of your device.</h3>
|
||||||
<p>
|
<p>
|
||||||
If your device comes with the following tag
|
If your device comes with the following tag
|
||||||
</p>
|
|
||||||
<img class="img-responsive center-block" style="width: 12em;"
|
<img class="img-responsive center-block" style="width: 12em;"
|
||||||
src="{{ url_for('Device.static', filename='photochromic-alone.svg') }}">
|
src="{{ url_for('Device.static', filename='photochromic-alone.svg') }}">
|
||||||
<p>
|
it means it has been refurbished by an eReuse.org
|
||||||
It means it has been refurbished by an eReuse.org
|
certified organization.
|
||||||
certificated organization.
|
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
The tag is special –illuminate it with the torch of
|
The tag is special –illuminate it with the torch of
|
||||||
your phone for 6 seconds and it will react like in
|
your phone for 6 seconds and it will react like in
|
||||||
the following image:
|
the following image:
|
||||||
</p>
|
|
||||||
<img class="img-responsive center-block" style="width: 30em;"
|
<img class="img-responsive center-block" style="width: 30em;"
|
||||||
src="{{ url_for('Device.static', filename='photochromic-tag-web.svg') }}">
|
src="{{ url_for('Device.static', filename='photochromic-tag-web.svg') }}">
|
||||||
|
This is proof that this device is genuine.
|
||||||
|
</p>
|
||||||
</article>
|
</article>
|
||||||
<article class="col-md-6">
|
<article class="col-md-6">
|
||||||
<h3>These are the specifications</h3>
|
<h3>These are the specifications</h3>
|
||||||
{% if device.trading %}
|
|
||||||
{{ device.trading.name }}
|
|
||||||
{% endif %}
|
|
||||||
{% if device.trading and device.physical %}
|
|
||||||
and
|
|
||||||
{% endif %}
|
|
||||||
{% if device.phyisical %}
|
|
||||||
{{ device.physical.name }}
|
|
||||||
{% endif %}
|
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -67,7 +85,12 @@
|
||||||
<td>
|
<td>
|
||||||
CPU – {{ device.processor_model }}
|
CPU – {{ device.processor_model }}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ device.rate.processor_range if device.rate }}</td>
|
<td>
|
||||||
|
{% if device.rate %}
|
||||||
|
{{ device.rate.processor_range }}
|
||||||
|
({{ device.rate.processor }})
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if device.ram_size %}
|
{% if device.ram_size %}
|
||||||
|
@ -76,7 +99,12 @@
|
||||||
RAM – {{ device.ram_size // 1000 }} GB
|
RAM – {{ device.ram_size // 1000 }} GB
|
||||||
{{ macros.component_type(device.components, 'RamModule') }}
|
{{ macros.component_type(device.components, 'RamModule') }}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ device.rate.ram_range if device.rate }}</td>
|
<td>
|
||||||
|
{% if device.rate %}
|
||||||
|
{{ device.rate.ram_range }}
|
||||||
|
({{ device.rate.ram }})
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if device.data_storage_size %}
|
{% if device.data_storage_size %}
|
||||||
|
@ -86,7 +114,12 @@
|
||||||
{{ macros.component_type(device.components, 'SolidStateDrive') }}
|
{{ macros.component_type(device.components, 'SolidStateDrive') }}
|
||||||
{{ macros.component_type(device.components, 'HardDrive') }}
|
{{ macros.component_type(device.components, 'HardDrive') }}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ device.rate.data_storage_range if device.rate }}</td>
|
<td>
|
||||||
|
{% if device.rate %}
|
||||||
|
{{ device.rate.data_storage_range }}
|
||||||
|
({{ device.rate.data_storage }})
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if device.graphic_card_model %}
|
{% if device.graphic_card_model %}
|
||||||
|
@ -129,6 +162,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ device.rate.rating_range }}
|
{{ device.rate.rating_range }}
|
||||||
|
({{ device.rate.rating }})
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -181,10 +215,8 @@
|
||||||
<small>Oldest one.</small>
|
<small>Oldest one.</small>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a href="https://www.ereuse.org/">
|
|
||||||
<img class="img-responsive center-block" style="max-width: 30em;"
|
|
||||||
src="{{ url_for('Device.static', filename='ereuse-logo.svg') }}">
|
|
||||||
</a>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -245,7 +245,7 @@ class ComputerChassis(Enum):
|
||||||
Virtual = 'Non-physical device'
|
Virtual = 'Non-physical device'
|
||||||
|
|
||||||
def __format__(self, format_spec):
|
def __format__(self, format_spec):
|
||||||
return self.value.lower()
|
return inflection.humanize(inflection.underscore(self.value))
|
||||||
|
|
||||||
|
|
||||||
class ReceiverRole(Enum):
|
class ReceiverRole(Enum):
|
||||||
|
|
|
@ -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.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.db import db
|
||||||
from ereuse_devicehub.resources.device.models import Device
|
from ereuse_devicehub.resources.device.models import Device
|
||||||
|
@ -27,6 +27,8 @@ class TagDeviceView(View):
|
||||||
tag = Tag.from_an_id(id).one() # type: Tag
|
tag = Tag.from_an_id(id).one() # type: Tag
|
||||||
if not tag.device:
|
if not tag.device:
|
||||||
raise TagNotLinked(tag.id)
|
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)
|
return app.resources[Device.t].schema.jsonify(tag.device)
|
||||||
|
|
||||||
# noinspection PyMethodOverriding
|
# 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
|
# todo this could be more efficient by Device.query... join with tag
|
||||||
device = Tag.query.filter_by(id=id).one().device
|
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:
|
if device is None:
|
||||||
raise TagNotLinked(id)
|
raise TagNotLinked(id)
|
||||||
return app.resources[Device.t].schema.jsonify(device)
|
return app.resources[Device.t].schema.jsonify(device)
|
||||||
|
|
|
@ -506,8 +506,8 @@ def test_device_properties_format(app: Devicehub, user: UserClient):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
pc = Laptop.query.one() # type: Laptop
|
pc = Laptop.query.one() # type: Laptop
|
||||||
assert format(pc) == 'Laptop 1: model 1000h, S/N 94oaaq021116'
|
assert format(pc) == 'Laptop 1: model 1000h, S/N 94oaaq021116'
|
||||||
assert format(pc, 't') == 'netbook 1000h'
|
assert format(pc, 't') == 'Netbook 1000h'
|
||||||
assert format(pc, 's') == '(asustek computer inc.) S/N 94oaaq021116'
|
assert format(pc, 's') == '(asustek computer inc.) S/N 94OAAQ021116'
|
||||||
assert pc.ram_size == 1024
|
assert pc.ram_size == 1024
|
||||||
assert pc.data_storage_size == 152627
|
assert pc.data_storage_size == 152627
|
||||||
assert pc.graphic_card_model == 'mobile 945gse express integrated graphics controller'
|
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 ' \
|
assert format(net) == 'NetworkAdapter 2: model ar8121/ar8113/ar8114 ' \
|
||||||
'gigabit or fast ethernet, S/N 00:24:8c:7f:cf:2d'
|
'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, '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))
|
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) == 'HardDrive 7: model st9160310as, S/N 5sv4tqa6'
|
||||||
assert format(hdd, 't') == 'HardDrive st9160310as'
|
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):
|
def test_device_public(user: UserClient, client: Client):
|
||||||
s, _ = user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
|
s, _ = user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
|
||||||
html, _ = client.get(res=Device, item=s['device']['id'], accept=ANY)
|
html, _ = client.get(res=Device, item=s['device']['id'], accept=ANY)
|
||||||
assert 'intel atom cpu n270 @ 1.60ghz' in html
|
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.')
|
@pytest.mark.xfail(reason='Functionality not yet developed.')
|
||||||
|
|
Reference in a new issue