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:
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
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,181 +10,213 @@
|
|||
crossorigin="anonymous">
|
||||
<title>Devicehub | {{ device.__format__('t') }}</title>
|
||||
</head>
|
||||
<body class="container">
|
||||
<body>
|
||||
|
||||
<div class="page-header">
|
||||
<h1>{{ device.__format__('t') }}<br>
|
||||
<small>{{ device.__format__('s') }}</small>
|
||||
</h1>
|
||||
<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>
|
||||
<small>{{ device.__format__('s') }}</small>
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<h2 class='text-center'>
|
||||
This is your {{ device.t }}.
|
||||
</h2>
|
||||
|
||||
<h2 class='text-center'>
|
||||
This is your {{ device.t }}.
|
||||
</h2>
|
||||
|
||||
<div class="row">
|
||||
<article class="col-md-6">
|
||||
<h3>You can verify the originality of your device.</h3>
|
||||
<p>
|
||||
If your device comes with the following tag
|
||||
</p>
|
||||
<img class="img-responsive center-block" style="width: 12em;"
|
||||
src="{{ url_for('Device.static', filename='photochromic-alone.svg') }}">
|
||||
<p>
|
||||
It means it has been refurbished by an eReuse.org
|
||||
certificated organization.
|
||||
</p>
|
||||
<p>
|
||||
The tag is special –illuminate it with the torch of
|
||||
your phone for 6 seconds and it will react like in
|
||||
the following image:
|
||||
</p>
|
||||
<img class="img-responsive center-block" style="width: 30em;"
|
||||
src="{{ url_for('Device.static', filename='photochromic-tag-web.svg') }}">
|
||||
</article>
|
||||
<article class="col-md-6">
|
||||
<h3>These are the specifications</h3>
|
||||
<p class="text-center">
|
||||
{% if device.trading %}
|
||||
{{ device.trading.name }}
|
||||
{{ device.trading }}
|
||||
{% endif %}
|
||||
{% if device.trading and device.physical %}
|
||||
and
|
||||
{% endif %}
|
||||
{% if device.phyisical %}
|
||||
{{ device.physical.name }}
|
||||
{% if device.physical %}
|
||||
{{ device.physical }}
|
||||
{% endif %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Range</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% if device.processor_model %}
|
||||
</p>
|
||||
<div class="row">
|
||||
<article class="col-md-6">
|
||||
<h3>You can verify the originality of your device.</h3>
|
||||
<p>
|
||||
If your device comes with the following tag
|
||||
<img class="img-responsive center-block" style="width: 12em;"
|
||||
src="{{ url_for('Device.static', filename='photochromic-alone.svg') }}">
|
||||
it means it has been refurbished by an eReuse.org
|
||||
certified organization.
|
||||
</p>
|
||||
<p>
|
||||
The tag is special –illuminate it with the torch of
|
||||
your phone for 6 seconds and it will react like in
|
||||
the following image:
|
||||
<img class="img-responsive center-block" style="width: 30em;"
|
||||
src="{{ url_for('Device.static', filename='photochromic-tag-web.svg') }}">
|
||||
This is proof that this device is genuine.
|
||||
</p>
|
||||
</article>
|
||||
<article class="col-md-6">
|
||||
<h3>These are the specifications</h3>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>
|
||||
CPU – {{ device.processor_model }}
|
||||
</td>
|
||||
<td>{{ device.rate.processor_range if device.rate }}</td>
|
||||
<th></th>
|
||||
<th>Range</th>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.ram_size %}
|
||||
<tr>
|
||||
<td>
|
||||
RAM – {{ device.ram_size // 1000 }} GB
|
||||
{{ macros.component_type(device.components, 'RamModule') }}
|
||||
</td>
|
||||
<td>{{ device.rate.ram_range if device.rate }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.data_storage_size %}
|
||||
<tr>
|
||||
<td>
|
||||
Data Storage – {{ device.data_storage_size // 1000 }} GB
|
||||
{{ macros.component_type(device.components, 'SolidStateDrive') }}
|
||||
{{ macros.component_type(device.components, 'HardDrive') }}
|
||||
</td>
|
||||
<td>{{ device.rate.data_storage_range if device.rate }}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.graphic_card_model %}
|
||||
<tr>
|
||||
<td>
|
||||
Graphics – {{ device.graphic_card_model }}
|
||||
{{ macros.component_type(device.components, 'GraphicCard') }}
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.network_speeds %}
|
||||
<tr>
|
||||
<td>
|
||||
Network –
|
||||
{% if device.network_speeds[0] %}
|
||||
Ethernet
|
||||
{% if device.network_speeds[0] != None %}
|
||||
max. {{ device.network_speeds[0] }} Mbps
|
||||
</thead>
|
||||
<tbody>
|
||||
{% if device.processor_model %}
|
||||
<tr>
|
||||
<td>
|
||||
CPU – {{ device.processor_model }}
|
||||
</td>
|
||||
<td>
|
||||
{% if device.rate %}
|
||||
{{ device.rate.processor_range }}
|
||||
({{ device.rate.processor }})
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if device.network_speeds[0] and device.network_speeds[1] %}
|
||||
+
|
||||
{% endif %}
|
||||
{% if device.network_speeds[1] %}
|
||||
WiFi
|
||||
{% if device.network_speeds[1] != None %}
|
||||
max. {{ device.network_speeds[1] }} Mbps
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.ram_size %}
|
||||
<tr>
|
||||
<td>
|
||||
RAM – {{ device.ram_size // 1000 }} GB
|
||||
{{ macros.component_type(device.components, 'RamModule') }}
|
||||
</td>
|
||||
<td>
|
||||
{% if device.rate %}
|
||||
{{ device.rate.ram_range }}
|
||||
({{ device.rate.ram }})
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{{ macros.component_type(device.components, 'NetworkAdapter') }}
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.rate %}
|
||||
<tr class="active">
|
||||
<td class="text-right">
|
||||
Total rate
|
||||
</td>
|
||||
<td>
|
||||
{{ device.rate.rating_range }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.rate and device.rate.price %}
|
||||
<tr class="active">
|
||||
<td class="text-right">
|
||||
Algorithm price
|
||||
</td>
|
||||
<td>
|
||||
{{ device.rate.price }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.price %}
|
||||
<tr class="active">
|
||||
<td class="text-right">
|
||||
Actual price
|
||||
</td>
|
||||
<td>
|
||||
{{ device.price }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<h3>This is the traceability log of your device</h3>
|
||||
<div class="text-right">
|
||||
<small>Latest one.</small>
|
||||
</div>
|
||||
<ol>
|
||||
{% for event in device.events|reverse %}
|
||||
<li>
|
||||
<strong>
|
||||
{{ event.type }}
|
||||
</strong>
|
||||
—
|
||||
{{ event }}
|
||||
<br>
|
||||
<div class="text-muted">
|
||||
<small>
|
||||
{{ event._date_str }}
|
||||
</small>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.data_storage_size %}
|
||||
<tr>
|
||||
<td>
|
||||
Data Storage – {{ device.data_storage_size // 1000 }} GB
|
||||
{{ macros.component_type(device.components, 'SolidStateDrive') }}
|
||||
{{ macros.component_type(device.components, 'HardDrive') }}
|
||||
</td>
|
||||
<td>
|
||||
{% if device.rate %}
|
||||
{{ device.rate.data_storage_range }}
|
||||
({{ device.rate.data_storage }})
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.graphic_card_model %}
|
||||
<tr>
|
||||
<td>
|
||||
Graphics – {{ device.graphic_card_model }}
|
||||
{{ macros.component_type(device.components, 'GraphicCard') }}
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.network_speeds %}
|
||||
<tr>
|
||||
<td>
|
||||
Network –
|
||||
{% if device.network_speeds[0] %}
|
||||
Ethernet
|
||||
{% if device.network_speeds[0] != None %}
|
||||
max. {{ device.network_speeds[0] }} Mbps
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if device.network_speeds[0] and device.network_speeds[1] %}
|
||||
+
|
||||
{% endif %}
|
||||
{% if device.network_speeds[1] %}
|
||||
WiFi
|
||||
{% if device.network_speeds[1] != None %}
|
||||
max. {{ device.network_speeds[1] }} Mbps
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{{ macros.component_type(device.components, 'NetworkAdapter') }}
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.rate %}
|
||||
<tr class="active">
|
||||
<td class="text-right">
|
||||
Total rate
|
||||
</td>
|
||||
<td>
|
||||
{{ device.rate.rating_range }}
|
||||
({{ device.rate.rating }})
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.rate and device.rate.price %}
|
||||
<tr class="active">
|
||||
<td class="text-right">
|
||||
Algorithm price
|
||||
</td>
|
||||
<td>
|
||||
{{ device.rate.price }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if device.price %}
|
||||
<tr class="active">
|
||||
<td class="text-right">
|
||||
Actual price
|
||||
</td>
|
||||
<td>
|
||||
{{ device.price }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<h3>This is the traceability log of your device</h3>
|
||||
<div class="text-right">
|
||||
<small>Latest one.</small>
|
||||
</div>
|
||||
<ol>
|
||||
{% for event in device.events|reverse %}
|
||||
<li>
|
||||
<strong>
|
||||
{{ event.type }}
|
||||
</strong>
|
||||
—
|
||||
{{ event }}
|
||||
<br>
|
||||
<div class="text-muted">
|
||||
<small>
|
||||
{{ event._date_str }}
|
||||
</small>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
<div class="text-right">
|
||||
<small>Oldest one.</small>
|
||||
</div>
|
||||
</article>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
<div class="text-right">
|
||||
<small>Oldest one.</small>
|
||||
</div>
|
||||
</article>
|
||||
</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>
|
||||
</html>
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.')
|
||||
|
|
Reference in a new issue