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

View File

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

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -10,49 +10,67 @@
crossorigin="anonymous">
<title>Devicehub | {{ device.__format__('t') }}</title>
</head>
<body class="container">
<body>
<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>
<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">
<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.
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:
</p>
<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>
{% 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">
<table class="table table-striped">
<thead>
@ -67,7 +85,12 @@
<td>
CPU {{ device.processor_model }}
</td>
<td>{{ device.rate.processor_range if device.rate }}</td>
<td>
{% if device.rate %}
{{ device.rate.processor_range }}
({{ device.rate.processor }})
{% endif %}
</td>
</tr>
{% endif %}
{% if device.ram_size %}
@ -76,7 +99,12 @@
RAM {{ device.ram_size // 1000 }} GB
{{ macros.component_type(device.components, 'RamModule') }}
</td>
<td>{{ device.rate.ram_range if device.rate }}</td>
<td>
{% if device.rate %}
{{ device.rate.ram_range }}
({{ device.rate.ram }})
{% endif %}
</td>
</tr>
{% endif %}
{% if device.data_storage_size %}
@ -86,7 +114,12 @@
{{ macros.component_type(device.components, 'SolidStateDrive') }}
{{ macros.component_type(device.components, 'HardDrive') }}
</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>
{% endif %}
{% if device.graphic_card_model %}
@ -129,6 +162,7 @@
</td>
<td>
{{ device.rate.rating_range }}
({{ device.rate.rating }})
</td>
</tr>
{% endif %}
@ -182,9 +216,7 @@
</div>
</article>
</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>
</div>
</body>
</html>

View File

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

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

View File

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