From 6b5db319229126283c80e92a1ef73f4396924c97 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 1 Feb 2023 13:28:31 +0100 Subject: [PATCH 1/2] add new version of public page --- .../device/templates/devices/layout.html | 559 ++++++------------ ereuse_devicehub/resources/device/views.py | 11 +- 2 files changed, 180 insertions(+), 390 deletions(-) diff --git a/ereuse_devicehub/resources/device/templates/devices/layout.html b/ereuse_devicehub/resources/device/templates/devices/layout.html index f513d0b9..a9509915 100644 --- a/ereuse_devicehub/resources/device/templates/devices/layout.html +++ b/ereuse_devicehub/resources/device/templates/devices/layout.html @@ -1,400 +1,181 @@ -{% import 'devices/macros.html' as macros %} - - - - - - - - Devicehub | {{ device.__format__('t') }} - - - +
+
- -
-
- -
-
-
-
-
-
    - {% for key, value in device.public_properties.items() %} -
  • {{ key }}: {{ value or '' }}
  • - {% endfor %} -
- {% if isinstance(device, d.Computer) %} -
- - - - - - - - - {% if device.processor_model %} - - - - - {% endif %} - {% if device.ram_size %} - - - - - {% endif %} - {% if device.data_storage_size %} - - - - - {% endif %} - {% if device.graphic_card_model %} - - - - - {% endif %} - {% if device.network_speeds %} - - - - - {% endif %} - -
Range
- CPU – {{ device.processor_model }} - - Processor Rate = {% if device.rate %} - {{ device.rate.processor_range }} - ({{ device.rate.processor }}) - {% endif %} -
- RAM – {{ device.ram_size // 1000 }} GB - {{ macros.component_type(device.components, 'RamModule') }} - - RAM Rate = {% if device.rate %} - {{ device.rate.ram_range }} - ({{ device.rate.ram }}) - {% endif %} -
- Data Storage – {{ device.data_storage_size // 1000 }} GB - {{ macros.component_type(device.components, 'SolidStateDrive') }} - {{ macros.component_type(device.components, 'HardDrive') }} - - Data Storage Rate = {% if device.rate %} - {{ device.rate.data_storage_range }} - ({{ device.rate.data_storage }}) - {% endif %} -
- Graphics – {{ device.graphic_card_model }} - {{ macros.component_type(device.components, 'GraphicCard') }} -
- 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') }} -
-
-

Actual Status

-
    -
  1. - - Lifecycle Status - - — - {% if device.status %} - {{ device.status.type }} - {% endif %} -
  2. -
  3. - - Allocate Status - - — - {% if device.allocated_status %} - {{ device.allocated_status.type }} - {% endif %} -
  4. -
  5. - - Physical Status - - — - {% if device.physical_status %} - {{ device.physical_status.type }} - {% endif %} -
  6. -
+
+
-

Public traceability log of the device

-
- Latest one. +
+
+ +
+
+
Basic
+
+
+ Usody Identifier (DHID) +
+
+ {{ device_real.dhid }} +
+
+
+
+ Inventory Identifier (PHID) +
+
+ {{ device_real.phid() }} +
+
+
+
+ Type +
+
+ {{ device_real.type or '- not detected -' }} +
+
+
+
+ Manufacturer +
+
+ {{ device_real.manufacturer or '- not detected -' }} +
+
+
+
+ Model +
+
+ {{ device_real.model or '- not detected -' }} +
+
+
+
+ Part Number +
+
+ {{ device_real.part_number or '- not detected -' }} +
+
+
+
+ Serial Number +
+
+ - anonymized - +
+
-
    - {% for action in device.public_actions %} -
  1. - - {{ device.is_status(action) }} - {% if not device.is_status(action) %} - {{ action.type }} - {% endif %} - - — - {% if device.is_status(action) %} - {{ action }} {{ action.type }} - {% else %} - {{ action }} - {% endif %} -
    -
    - - {{ action._date_str }} - -
    - {% if action.certificate %} - See the certificate - {% endif %} -
  2. - {% endfor %} -
-
- Oldest one. +
- {% endif %} -
-
- {% if abstract %} -
- -
-
-
-
-
-
    - {% for key, value in abstract.public_properties.items() %} -
  • {{ key }}: {{ value or '' }}
  • - {% endfor %} -
- {% if isinstance(abstract, d.Computer) %} -
- - - - - - - - - {% if abstract.processor_model %} - - - - +
+
Status
+
+
+
Physical
+
{{ device_real.physical_status and device.physical_status.type or '- not status -' }}
+
+
+
+
+
Lifecycle
+
{{ device_real.status and device_real.status.type or '- not status -' }}
+
+
+
+
+
Allocation
+
+ {% if device_real.allocated %} + Allocated + {% else %} + Not allocated {% endif %} - {% if abstract.ram_size %} -
- - - - {% endif %} - {% if abstract.data_storage_size %} - - - - - {% endif %} - {% if abstract.graphic_card_model %} - - - - - {% endif %} - {% if abstract.network_speeds %} - - - - - {% endif %} - -
Range
- CPU – {{ abstract.processor_model }} - - Processor Rate = {% if abstract.rate %} - {{ abstract.rate.processor_range }} - ({{ abstract.rate.processor }}) - {% endif %} -
- RAM – {{ abstract.ram_size // 1000 }} GB - {{ macros.component_type(abstract.components, 'RamModule') }} - - RAM Rate = {% if abstract.rate %} - {{ abstract.rate.ram_range }} - ({{ abstract.rate.ram }}) - {% endif %} -
- Data Storage – {{ abstract.data_storage_size // 1000 }} GB - {{ macros.component_type(abstract.components, 'SolidStateDrive') }} - {{ macros.component_type(abstract.components, 'HardDrive') }} - - Data Storage Rate = {% if abstract.rate %} - {{ abstract.rate.data_storage_range }} - ({{ abstract.rate.data_storage }}) - {% endif %} -
- Graphics – {{ abstract.graphic_card_model }} - {{ macros.component_type(abstract.components, 'GraphicCard') }} -
- Network – - {% if abstract.network_speeds[0] %} - Ethernet - {% if abstract.network_speeds[0] != None %} - max. {{ abstract.network_speeds[0] }} Mbps - {% endif %} - {% endif %} - {% if abstract.network_speeds[0] and abstract.network_speeds[1] %} - + - {% endif %} - {% if abstract.network_speeds[1] %} - WiFi - {% if abstract.network_speeds[1] != None %} - max. {{ abstract.network_speeds[1] }} Mbps - {% endif %} - {% endif %} - {{ macros.component_type(abstract.components, 'NetworkAdapter') }} -
+
+
+
-

Actual Status

-
    -
  1. - - Lifecycle Status - - — - {% if abstract.status %} - {{ abstract.status.type }} - {% endif %} -
  2. -
  3. - - Allocate Status - - — - {% if abstract.allocated_status %} - {{ abstract.allocated_status.type }} - {% endif %} -
  4. -
  5. - - Physical Status - - — - {% if abstract.physical_status %} - {{ abstract.physical_status.type }} - {% endif %} -
  6. -
+
+
+
+
Components
+
+ {% if placeholder.binding %} +
+ {% for component in placeholder.binding.components|sort(attribute='type') %} +
+
+
{{ component.type }}
+ {{ component.created.strftime('%H:%M %d-%m-%Y') }} +
+

+ {{ component.manufacturer }}
+ {{ component.model }}
+

+ + {% if component.type in ['RamModule', 'HardDrive', 'SolidStateDrive'] %} + {{ component.size }}MB + {% endif %} + +
+ {% endfor %} +
+ {% else %} +
+
+ - not detected - +
+
+ {% endif %} +
+
+
+
Repair history
+
+
+ {% for action in placeholder.actions %} +
+ {{ action.type }} {{ action.severity }} + {{ action.created.strftime('%H:%M %d-%m-%Y') }} +
+ {% endfor %} +
+
+
+
+
+
+
+
+
+
-

Public traceability log of the abstract

-
- Latest one. -
-
    - {% for action in abstract.public_actions %} -
  1. - - {{ abstract.is_status(action) }} - {% if not abstract.is_status(action) %} - {{ action.type }} - {% endif %} - - — - {% if abstract.is_status(action) %} - {{ action }} {{ action.type }} - {% else %} - {{ action }} - {% endif %} -
    -
    - - {{ action._date_str }} - -
    - {% if action.certificate %} - See the certificate - {% endif %} -
  2. - {% endfor %} -
-
- Oldest one. -
- {% endif %} - - - {% endif %} + + +
+
+
+
+ +
+ Help | + Privacy | + Terms +
+
+ DeviceHub +
+
+
-
-
-
- Page generated by:
- -
-
- - +{% endblock body%} diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 6896089c..ab6850f1 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -148,8 +148,17 @@ class DeviceView(View): if device.is_abstract() == 'Twin': abstract = device.placeholder.binding + placeholder = device.binding or device.placeholder + device_abstract = placeholder and placeholder.binding or device + device_real = placeholder and placeholder.device or device return render_template( - 'devices/layout.html', device=device, states=states, abstract=abstract + 'devices/layout.html', + placeholder=placeholder, + device=device, + device_abstract=device_abstract, + device_real=device_real, + states=states, + abstract=abstract ) @auth.Auth.requires_auth From 7dc3ac9530f53aa56b509447cb8125001906ad72 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 1 Feb 2023 16:35:27 +0100 Subject: [PATCH 2/2] fix test --- ereuse_devicehub/resources/device/views.py | 2 +- tests/test_device.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index ab6850f1..40e6ff94 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -158,7 +158,7 @@ class DeviceView(View): device_abstract=device_abstract, device_real=device_real, states=states, - abstract=abstract + abstract=abstract, ) @auth.Auth.requires_auth diff --git a/tests/test_device.py b/tests/test_device.py index ac8c1d07..9977cd5c 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -560,7 +560,6 @@ def test_get_device_permissions( html, _ = client.get(res=d.Device, item=s['device']['devicehubID'], accept=ANY) assert 'intel atom cpu n270 @ 1.60ghz' in html - assert '00:24:8C:7F:CF:2D – 100 Mbps' in html pc2, res2 = user2.get(res=d.Device, item=s['device']['devicehubID'], accept=ANY) assert res2.status_code == 200 assert pc2 == html @@ -692,7 +691,6 @@ def test_device_public(user: UserClient, client: Client): s, _ = user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot) html, _ = client.get(res=d.Device, item=s['device']['devicehubID'], accept=ANY) assert 'intel atom cpu n270 @ 1.60ghz' in html - assert '00:24:8C:7F:CF:2D – 100 Mbps' in html @pytest.mark.mvp