From e451668ff9b9740beeca9ad2ed9d72546f879226 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 23 Jun 2023 10:22:46 +0200 Subject: [PATCH] fix templates --- .../modules/did/templates/anonymous.html | 259 ++++++++++++++ .../modules/did/templates/operator.html | 323 ++++++++++++++++++ .../modules/did/templates/verifier.html | 320 +++++++++++++++++ ereuse_devicehub/modules/did/views.py | 14 +- ereuse_devicehub/resources/device/models.py | 8 +- ereuse_devicehub/resources/user/models.py | 6 + .../templates/labels/print_labels.html | 2 +- 7 files changed, 929 insertions(+), 3 deletions(-) create mode 100644 ereuse_devicehub/modules/did/templates/anonymous.html create mode 100644 ereuse_devicehub/modules/did/templates/operator.html create mode 100644 ereuse_devicehub/modules/did/templates/verifier.html diff --git a/ereuse_devicehub/modules/did/templates/anonymous.html b/ereuse_devicehub/modules/did/templates/anonymous.html new file mode 100644 index 00000000..b2efdadc --- /dev/null +++ b/ereuse_devicehub/modules/did/templates/anonymous.html @@ -0,0 +1,259 @@ + + + + + + + + Device {{ device_real.dhid }} - Usody + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ +
+ +
+
+ +
+
+
Details
+
+
+ Type +
+
+ {{ device_real.type or '- not detected -' }} +
+
+
+
+ Manufacturer +
+
+ {{ device_real.manufacturer and device_real.manufacturer.upper() or '- not detected -' }} +
+
+
+
+ Model +
+
+ {{ device_real.model or '- not detected -' }} +
+
+
+
+ Device Identifier (CHID): +
+ +
+
+
+ Usody Identifier (DHID) +
+
+ {{ device_real.dhid }} +
+
+
+
+
+
+
Components
+
+
+
    + {% for component in components %} + {% if component.type == "Processor" %} +
  • + Processor: {{ component.manufacturer or '- not detected -' }} {{ component.model or '- not detected -'}} +
  • + {% endif %} + {% endfor %} + {% for component in components %} + {% if component.type in ['HardDrive', 'SolidStateDrive'] %} +
  • + {{ component.type }}: + {% if component.size %}{{ component.size/1000 }}GB{% else %} - not detected - {% endif %} +
  • + {% endif %} + {% endfor %} + {% for component in components %} + {% if component.type == 'RamModule' %} +
  • + Ram: + {% if component.size %}{{ component.size }}MB{% else %} - not detected - {% endif %} +
  • + {% endif %} + {% endfor %} + {% for component in components %} + {% if component.type == 'SoundCard' %} +
  • + Sound: {{ component.manufacturer or '- not detected -' }} {{ component.model or '- not detected -'}} +
  • + {% endif %} + {% endfor %} + {% for component in components %} + {% if component.type == 'NetworkAdapter' %} +
  • + Network: {{ component.manufacturer or '- not detected -' }} {{ component.model or '- not detected -'}} +
  • + {% endif %} + {% endfor %} +
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+ +
+ Help | + Privacy | + Terms +
+
+ DeviceHub +
+
+
+
+
+ +{% if user.is_anonymous and not rols %} + +{% else %} + +{% endif %} + + + +{% if rols and not rol %} + +{% endif %} + + diff --git a/ereuse_devicehub/modules/did/templates/operator.html b/ereuse_devicehub/modules/did/templates/operator.html new file mode 100644 index 00000000..d472450a --- /dev/null +++ b/ereuse_devicehub/modules/did/templates/operator.html @@ -0,0 +1,323 @@ + + + + + + + + Device {{ device_real.dhid }} - Usody + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ +
+ +
+
+ +
+
+
Basic
+
+
+ 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 +
+
+ {{ device_abstract.serial_number and device_abstract.serial_number.upper() or '- not detected -' }} +
+
+
+
+ Usody Identifier (DHID) +
+
+ {{ device_real.dhid }} +
+
+
+
+ Inventory Identifier (PHID) +
+
+ {{ device_real.phid() }} +
+
+
+
+ Device Identifier (CHID): +
+ +
+
+
+ Last Digital Passport (Last Dpp): +
+
+ {% if last_dpp %} + {{ last_dpp.key|truncate(20, True, '...') }} + {% else %} + - not detected - + {% endif %} +
+
+
+
+
+
+
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 %} +
+
+
+
+
+
+
Components
+
+ {% if components %} +
+ {% for component in components|sort(attribute='type') %} +
+
+
{{ component.type }}
+ {{ component.created.strftime('%H:%M %d-%m-%Y') }} +
+

+ Manufacturer: {{ component.manufacturer or '- not detected -' }}
+ Model: {{ component.model or '- not detected -' }}
+ Serial: {{ component.serial_number and component.serial_number.upper() or '- not detected -' }} +

+ + {% 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 %} +
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+ +
+ Help | + Privacy | + Terms +
+
+ DeviceHub +
+
+
+
+
+ +{% if user.is_anonymous and not rols %} + +{% else %} + +{% endif %} + + + +{% if not user.is_anonymous and not rol %} + +{% endif %} + + diff --git a/ereuse_devicehub/modules/did/templates/verifier.html b/ereuse_devicehub/modules/did/templates/verifier.html new file mode 100644 index 00000000..bf6348be --- /dev/null +++ b/ereuse_devicehub/modules/did/templates/verifier.html @@ -0,0 +1,320 @@ + + + + + + + + Device {{ device_real.dhid }} - Usody + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ +
+ +
+
+ +
+
+
Details
+
+
+ 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 +
+
+ {{ device_abstract.serial_number and device_abstract.serial_number.upper() or '- not detected -' }} +
+
+
+
+ Usody Identifier (DHID) +
+
+ {{ device_real.dhid }} +
+
+
+
+ Inventory Identifier (PHID) +
+
+ {{ device_real.phid() }} +
+
+
+
+ Device Identifier (CHID): +
+ +
+ {% if last_dpp %} +
+
+ Last Digital Passport (Last Dpp): +
+
+ + {% else %} +
+
+ Last Digital Passport (Last Dpp): +
+
+ - not detected - +
+
+ {% endif %} + {% if before_dpp %} +
+
+ Before Digital Passport (Before Dpp): +
+
+ + {% else %} +
+
+ Before Digital Passport (Before Dpp): +
+
+ - not detected - +
+
+ {% endif %} +
+
+
+
+
Components
+
+ {% if components %} +
+ {% for component in components|sort(attribute='type') %} +
+
+
{{ component.type }}
+ {{ component.created.strftime('%H:%M %d-%m-%Y') }} +
+

+ Manufacturer: {{ component.manufacturer or '- not detected -' }}
+ Model: {{ component.model or '- not detected -' }}
+ {% if rol %} + Serial: {{ component.serial_number and component.serial_number.upper() or '- not detected -' }}
+ {% endif %} + {% if component.type in ['HardDrive', 'SolidStateDrive'] %} + Chid: + + {{ component.chid }} + + {% endif %} +

+ + {% if component.type in ['RamModule', 'HardDrive', 'SolidStateDrive'] %} + {{ component.size }}MB + {% endif %} + +
+ {% endfor %} +
+ {% else %} +
+
+ - not detected - +
+
+ {% endif %} +
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+ +
+ Help | + Privacy | + Terms +
+
+ DeviceHub +
+
+
+
+
+ +{% if user.is_anonymous and not rols %} + +{% else %} + +{% endif %} + + + +{% if not user.is_anonymous and not rol %} + +{% endif %} + + diff --git a/ereuse_devicehub/modules/did/views.py b/ereuse_devicehub/modules/did/views.py index 99d5c80c..4f7bf757 100644 --- a/ereuse_devicehub/modules/did/views.py +++ b/ereuse_devicehub/modules/did/views.py @@ -17,7 +17,7 @@ did = Blueprint('did', __name__, url_prefix='/did', template_folder='templates') class DidView(View): methods = ['GET', 'POST'] - template_name = 'did/layout.html' + template_name = 'anonymous.html' def dispatch_request(self, id_dpp): self.dpp = None @@ -42,9 +42,21 @@ class DidView(View): if self.accept_json(): return jsonify(self.get_result()) + self.get_template() return render_template(self.template_name, **self.context) + def get_template(self): + rol = self.context.get('rol') + if not rol: + return + + tlmp = { + "isOperator": "operator.html", + "isVerifier": "verifier.html", + } + self.template_name = tlmp.get(rol, self.template_name) + def accept_json(self): if 'json' in request.headers.get('Accept', []): return True diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index b16fe3a3..6e37f628 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -16,7 +16,7 @@ from boltons import urlutils from citext import CIText from ereuseapi.methods import API from flask import current_app as app -from flask import g, request, session +from flask import g, request, session, url_for from more_itertools import unique_everseen from sqlalchemy import BigInteger, Boolean, Column from sqlalchemy import Enum as DBEnum @@ -355,6 +355,12 @@ class Device(Thing): host_url = request.host_url.strip('/') return "{}{}".format(host_url, self.url.to_text()) + @property + def chid_link(self) -> str: + host_url = request.host_url.strip('/') + url = url_for('did.did', id_dpp=self.chid) + return "{}{}".format(host_url, url) + @property def url(self) -> urlutils.URL: """The URL where to GET this device.""" diff --git a/ereuse_devicehub/resources/user/models.py b/ereuse_devicehub/resources/user/models.py index 272b0943..21efa70f 100644 --- a/ereuse_devicehub/resources/user/models.py +++ b/ereuse_devicehub/resources/user/models.py @@ -159,6 +159,12 @@ class User(UserMixin, Thing): def get_rols_dlt(self): return json.loads(self.rols_dlt) + def set_rols_dlt(self, token_dlt=None): + rols = self.get_rols(self, token_dlt=token_dlt) + if rols: + self.rols_dlt = json.dumps(rols) + return rols + def get_rols(self, token_dlt=None): if 'dpp' not in app.blueprints.keys(): diff --git a/ereuse_devicehub/templates/labels/print_labels.html b/ereuse_devicehub/templates/labels/print_labels.html index e8db7d0c..33190462 100644 --- a/ereuse_devicehub/templates/labels/print_labels.html +++ b/ereuse_devicehub/templates/labels/print_labels.html @@ -192,7 +192,7 @@ {% endblock main %}