From 56b36ab244b09aa1c2377d5183e85b2059be7577 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 17 Jul 2023 17:13:55 +0200 Subject: [PATCH] add laer datas in operator template --- .../modules/did/templates/operator.html | 59 +++++++++++++++++++ ereuse_devicehub/modules/did/views.py | 32 +++++++--- 2 files changed, 82 insertions(+), 9 deletions(-) diff --git a/ereuse_devicehub/modules/did/templates/operator.html b/ereuse_devicehub/modules/did/templates/operator.html index 8116354c..e33a29c1 100644 --- a/ereuse_devicehub/modules/did/templates/operator.html +++ b/ereuse_devicehub/modules/did/templates/operator.html @@ -282,6 +282,65 @@ + {% if manuals.laer %} +
+
+
Recycled Content
+ +
+
+ Metal +
+
+
+ +
{{ manuals.laer.0.metal }}% +
+
+
+
+
+
+ Plastic post Consumer +
+
+
+
{{ manuals.laer.0.plastic_post_consumer }}% +
+
+
+
+
+
+ Plastic post Industry +
+
+
+
{{ manuals.laer.0.plastic_post_industry }}% +
+
+
+
+
+
+ {% endif %} + + {% if manuals.ifixit %}
diff --git a/ereuse_devicehub/modules/did/views.py b/ereuse_devicehub/modules/did/views.py index 710f5bbd..ea820186 100644 --- a/ereuse_devicehub/modules/did/views.py +++ b/ereuse_devicehub/modules/did/views.py @@ -1,4 +1,5 @@ import json +import logging import flask import requests @@ -13,6 +14,9 @@ from ereuse_devicehub import __version__ from ereuse_devicehub.modules.dpp.models import Dpp from ereuse_devicehub.resources.device.models import Device +logger = logging.getLogger(__name__) + + did = Blueprint('did', __name__, url_prefix='/did', template_folder='templates') @@ -196,16 +200,26 @@ class DidView(View): return {'data': dpps} def get_manuals(self): - params = { - "manufacturer": self.device.manufacturer, - "model": self.device.model, + manuals = { + 'ifixit': [], + 'icecat': [], + 'details': {}, + 'laer': [], } - self.params = json.dumps(params) - manuals = {'ifixit': [], 'icecat': [], 'details': {}} - manuals['ifixit'] = self.request_manuals('ifixit') - manuals['icecat'] = self.request_manuals('icecat') - if manuals['icecat']: - manuals['details'] = manuals['icecat'][0] + try: + params = { + "manufacturer": self.device.manufacturer, + "model": self.device.model, + } + self.params = json.dumps(params) + manuals['ifixit'] = self.request_manuals('ifixit') + manuals['icecat'] = self.request_manuals('icecat') + manuals['laer'] = self.request_manuals('laer') + if manuals['icecat']: + manuals['details'] = manuals['icecat'][0] + except Exception as err: + logger.error("Error: {}".format(err)) + self.context['manuals'] = manuals def request_manuals(self, prefix):