From 1023f3fdcae412b0505eee3863842345bba8be89 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 5 May 2022 12:00:02 +0200 Subject: [PATCH 1/4] add public link in model --- ereuse_devicehub/resources/device/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 09451277..c08ec3b8 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -10,7 +10,7 @@ from typing import Dict, List, Set from boltons import urlutils from citext import CIText from ereuse_utils.naming import HID_CONVERSION_DOC, Naming -from flask import g +from flask import g, request from flask_sqlalchemy import event from more_itertools import unique_everseen from sqlalchemy import BigInteger, Boolean, Column @@ -297,6 +297,11 @@ class Device(Thing): actions.reverse() return actions + @property + def public_link(self) -> str: + host_url = request.host_url.strip('/') + return "{}{}".format(host_url, self.url.to_text()) + @property def url(self) -> urlutils.URL: """The URL where to GET this device.""" From 1c670641f4cdabd29e550f7c271a4579f6e7c008 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 5 May 2022 12:00:40 +0200 Subject: [PATCH 2/4] add web: public link in device details page --- ereuse_devicehub/templates/inventory/device_detail.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ereuse_devicehub/templates/inventory/device_detail.html b/ereuse_devicehub/templates/inventory/device_detail.html index 7a96c4a9..051cde2a 100644 --- a/ereuse_devicehub/templates/inventory/device_detail.html +++ b/ereuse_devicehub/templates/inventory/device_detail.html @@ -26,6 +26,10 @@ + + From 33fd574f18b9f9974baa8c2f375e971412c40fbd Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 5 May 2022 12:31:29 +0200 Subject: [PATCH 3/4] add lots tab in device details --- .../templates/inventory/device_detail.html | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/ereuse_devicehub/templates/inventory/device_detail.html b/ereuse_devicehub/templates/inventory/device_detail.html index 051cde2a..f18c1e0e 100644 --- a/ereuse_devicehub/templates/inventory/device_detail.html +++ b/ereuse_devicehub/templates/inventory/device_detail.html @@ -30,6 +30,10 @@ Web + + @@ -73,6 +77,50 @@ +
+
Incoming Lots
+ +
+ {% for lot in device.lots %} + {% if lot.is_incoming %} + + {% endif %} + {% endfor %} +
+ +
Outgoing Lots
+ +
+ {% for lot in device.lots %} + {% if lot.is_outgoing %} + + {% endif %} + {% endfor %} +
+ +
Temporary Lots
+ +
+ {% for lot in device.lots %} + {% if lot.is_temporary %} + + {% endif %} + {% endfor %} +
+
+
Status Details
From af30453c12afc6643163a2958a502c130fd0e239 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 5 May 2022 13:10:02 +0200 Subject: [PATCH 4/4] fix message of allocate bug --- ereuse_devicehub/inventory/forms.py | 26 ++++++++++++++++++++++---- tests/test_render_2_0.py | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 0b88aa95..d58fcaf9 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -603,21 +603,39 @@ class AllocateForm(ActionFormMix): end_users = IntegerField('End users', [validators.Optional()]) def validate(self, extra_validators=None): - is_valid = super().validate(extra_validators) + if not super().validate(extra_validators): + return False if self.type.data not in ['Allocate', 'Deallocate']: return False + if not self.validate_dates(): + return False + + if not self.check_devices(): + return False + + return True + + def validate_dates(self): start_time = self.start_time.data end_time = self.end_time.data + + if not start_time: + self.start_time.errors = ['Not a valid date value.!'] + return False + if start_time and end_time and end_time < start_time: error = ['The action cannot finish before it starts.'] self.end_time.errors = error - is_valid = False + return False - if is_valid and not end_time: + if not end_time: self.end_time.data = self.start_time.data + return True + + def check_devices(self): if self.type.data == 'Allocate': txt = "You need deallocate before allocate this device again" for device in self._devices: @@ -636,7 +654,7 @@ class AllocateForm(ActionFormMix): device.allocated = False - return is_valid + return True class DataWipeDocumentForm(Form): diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index 0df56652..8e9f89af 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -668,7 +668,7 @@ def test_action_allocate_error_required(user3: UserClientFlask): body, status = user3.post(uri, data=data) assert status == '200 OK' assert 'Action Allocate error' in body - assert 'You need to specify a number of users!' in body + assert 'Not a valid date value.' in body @pytest.mark.mvp