Bigfixes for tag demo

This commit is contained in:
Xavier Bustamante Talavera 2018-10-16 16:30:10 +02:00
parent 84dd154cbe
commit 4b763ed1e8
7 changed files with 215 additions and 172 deletions

View File

@ -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

View File

@ -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):

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -10,181 +10,213 @@
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">
<h1>{{ device.__format__('t') }}<br> <div class="container-fluid">
<small>{{ device.__format__('s') }}</small> <a href="https://www.ereuse.org/" target="_blank">
</h1> <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>
<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'> <p 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>
{% if device.trading %} {% if device.trading %}
{{ device.trading.name }} {{ device.trading }}
{% endif %} {% endif %}
{% if device.trading and device.physical %} {% if device.trading and device.physical %}
and and
{% endif %} {% endif %}
{% if device.phyisical %} {% if device.physical %}
{{ device.physical.name }} {{ device.physical }}
{% endif %} {% endif %}
<div class="table-responsive"> </p>
<table class="table table-striped"> <div class="row">
<thead> <article class="col-md-6">
<tr> <h3>You can verify the originality of your device.</h3>
<th></th> <p>
<th>Range</th> If your device comes with the following tag
</tr> <img class="img-responsive center-block" style="width: 12em;"
</thead> src="{{ url_for('Device.static', filename='photochromic-alone.svg') }}">
<tbody> it means it has been refurbished by an eReuse.org
{% if device.processor_model %} 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> <tr>
<td> <th></th>
CPU {{ device.processor_model }} <th>Range</th>
</td>
<td>{{ device.rate.processor_range if device.rate }}</td>
</tr> </tr>
{% endif %} </thead>
{% if device.ram_size %} <tbody>
<tr> {% if device.processor_model %}
<td> <tr>
RAM {{ device.ram_size // 1000 }} GB <td>
{{ macros.component_type(device.components, 'RamModule') }} CPU {{ device.processor_model }}
</td> </td>
<td>{{ device.rate.ram_range if device.rate }}</td> <td>
</tr> {% if device.rate %}
{% endif %} {{ device.rate.processor_range }}
{% if device.data_storage_size %} ({{ device.rate.processor }})
<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
{% endif %} {% endif %}
{% endif %} </td>
{% if device.network_speeds[0] and device.network_speeds[1] %} </tr>
+ {% endif %}
{% endif %} {% if device.ram_size %}
{% if device.network_speeds[1] %} <tr>
WiFi <td>
{% if device.network_speeds[1] != None %} RAM {{ device.ram_size // 1000 }} GB
max. {{ device.network_speeds[1] }} Mbps {{ macros.component_type(device.components, 'RamModule') }}
</td>
<td>
{% if device.rate %}
{{ device.rate.ram_range }}
({{ device.rate.ram }})
{% endif %} {% endif %}
{% endif %} </td>
{{ macros.component_type(device.components, 'NetworkAdapter') }} </tr>
</td> {% endif %}
<td></td> {% if device.data_storage_size %}
</tr> <tr>
{% endif %} <td>
{% if device.rate %} Data Storage {{ device.data_storage_size // 1000 }} GB
<tr class="active"> {{ macros.component_type(device.components, 'SolidStateDrive') }}
<td class="text-right"> {{ macros.component_type(device.components, 'HardDrive') }}
Total rate </td>
</td> <td>
<td> {% if device.rate %}
{{ device.rate.rating_range }} {{ device.rate.data_storage_range }}
</td> ({{ device.rate.data_storage }})
</tr> {% endif %}
{% endif %} </td>
{% if device.rate and device.rate.price %} </tr>
<tr class="active"> {% endif %}
<td class="text-right"> {% if device.graphic_card_model %}
Algorithm price <tr>
</td> <td>
<td> Graphics {{ device.graphic_card_model }}
{{ device.rate.price }} {{ macros.component_type(device.components, 'GraphicCard') }}
</td> </td>
</tr> <td></td>
{% endif %} </tr>
{% if device.price %} {% endif %}
<tr class="active"> {% if device.network_speeds %}
<td class="text-right"> <tr>
Actual price <td>
</td> Network
<td> {% if device.network_speeds[0] %}
{{ device.price }} Ethernet
</td> {% if device.network_speeds[0] != None %}
</tr> max. {{ device.network_speeds[0] }} Mbps
{% endif %} {% endif %}
</tbody> {% endif %}
</table> {% if device.network_speeds[0] and device.network_speeds[1] %}
</div> +
<h3>This is the traceability log of your device</h3> {% endif %}
<div class="text-right"> {% if device.network_speeds[1] %}
<small>Latest one.</small> WiFi
</div> {% if device.network_speeds[1] != None %}
<ol> max. {{ device.network_speeds[1] }} Mbps
{% for event in device.events|reverse %} {% endif %}
<li> {% endif %}
<strong> {{ macros.component_type(device.components, 'NetworkAdapter') }}
{{ event.type }} </td>
</strong> <td></td>
</tr>
{{ event }} {% endif %}
<br> {% if device.rate %}
<div class="text-muted"> <tr class="active">
<small> <td class="text-right">
{{ event._date_str }} Total rate
</small> </td>
</div> <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> </li>
{% endfor %} {% endfor %}
</ol> </ol>
<div class="text-right"> <div class="text-right">
<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>

View File

@ -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):

View File

@ -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)

View File

@ -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.')