diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 9bf31d33..b1fdb645 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -317,6 +317,7 @@ class NewDeviceForm(FlaskForm): id_device_supplier = StringField('Id Supplier', [validators.Optional()]) phid = StringField('Placeholder Hardware identity (Phid)', [validators.Optional()]) pallet = StringField('Identity of pallet', [validators.Optional()]) + components = TextAreaField('Components', [validators.Optional()]) info = TextAreaField('Info', [validators.Optional()]) serial_number = StringField('Seria Number', [validators.Optional()]) model = StringField('Model', [validators.Optional()]) @@ -392,6 +393,7 @@ class NewDeviceForm(FlaskForm): self.phid.data = self._obj.placeholder.phid self.pallet.data = self._obj.placeholder.pallet self.info.data = self._obj.placeholder.info + self.components.data = self._obj.placeholder.components self.serial_number.data = self._obj.serial_number self.model.data = self._obj.model self.manufacturer.data = self._obj.manufacturer @@ -420,6 +422,7 @@ class NewDeviceForm(FlaskForm): self.id_device_supplier.render_kw = disabled self.pallet.render_kw = disabled self.info.render_kw = disabled + self.components.render_kw = disabled self.serial_number.render_kw = disabled self.model.render_kw = disabled self.manufacturer.render_kw = disabled @@ -595,6 +598,7 @@ class NewDeviceForm(FlaskForm): 'phid': self.phid.data or None, 'id_device_supplier': self.id_device_supplier.data, 'info': self.info.data, + 'components': self.components.data, 'pallet': self.pallet.data, 'is_abstract': False, } @@ -608,6 +612,7 @@ class NewDeviceForm(FlaskForm): self.id_device_supplier.data or None ) self._obj.placeholder.info = self.info.data or None + self._obj.placeholder.components = self.components.data or None self._obj.placeholder.pallet = self.pallet.data or None self._obj.model = self.model.data self._obj.manufacturer = self.manufacturer.data @@ -1662,8 +1667,8 @@ class BindingForm(FlaskForm): self.phid.errors = [txt] return False - if self.device.placeholder: - txt = "This is not a device Workbench." + if self.device.is_abstract() != 'Abstract': + txt = "This is not a abstract device." self.phid.errors = [txt] return False diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 8d0eafb7..6239d98c 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -191,6 +191,14 @@ class BindingView(GenericMixin): .one() ) + if device.is_abstract() != 'Abstract': + next_url = url_for('inventory.device_details', id=dhid) + messages.error('Device "{}" not is a Abstract device!'.format(dhid)) + return flask.redirect(next_url) + + if device.placeholder: + device = device.placeholder.binding + if request.method == 'POST': old_placeholder = device.binding old_device_placeholder = old_placeholder.device diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 76f1d2ad..a50d1593 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -667,13 +667,18 @@ class Device(Thing): action.functionality_range = value def is_abstract(self): - if not self.placeholder: - return '' - if self.placeholder.is_abstract: - return 'Abstract' - if self.placeholder.binding: + if self.placeholder: + if self.placeholder.is_abstract: + return 'Abstract' + if self.placeholder.binding: + return 'Twin' + return 'Real' + if self.binding: + if self.binding.is_abstract: + return 'Abstract' return 'Twin' - return 'Real' + + return '' def is_status(self, action): from ereuse_devicehub.resources.device import states @@ -878,6 +883,7 @@ class Placeholder(Thing): phid = Column(Unicode(), nullable=False, default=create_phid) pallet.comment = "used for identification where from where is this placeholders" info = db.Column(CIText()) + components = Column(CIText()) info.comment = "more info of placeholders" is_abstract = db.Column(Boolean, default=False) id_device_supplier = db.Column(CIText()) diff --git a/ereuse_devicehub/templates/inventory/device_create.html b/ereuse_devicehub/templates/inventory/device_create.html index a8bcf221..cdf674a3 100644 --- a/ereuse_devicehub/templates/inventory/device_create.html +++ b/ereuse_devicehub/templates/inventory/device_create.html @@ -142,6 +142,19 @@ {% endif %} +
+ + {{ form.components(class_="form-control") }} + Description of components + {% if form.components.errors %} +

+ {% for error in form.components.errors %} + {{ error }}
+ {% endfor %} +

+ {% endif %} +
+
{{ form.serial_number(class_="form-control") }} diff --git a/ereuse_devicehub/templates/inventory/device_detail.html b/ereuse_devicehub/templates/inventory/device_detail.html index 81b02e25..9f46e787 100644 --- a/ereuse_devicehub/templates/inventory/device_detail.html +++ b/ereuse_devicehub/templates/inventory/device_detail.html @@ -62,13 +62,13 @@ - {% if device.binding %} + {% if device.is_abstract() == 'Abstract' %} {% endif %} - {% if device.placeholder and placeholder.binding and device.is_abstract() != 'Abstract'%} + {% if device.is_abstract() == 'Twin' %} @@ -102,17 +102,17 @@
Manufacturer
-
{{ device.manufacturer }}
+
{{ device.manufacturer or ''}}
Model
-
{{ device.model }}
+
{{ device.model or ''}}
Serial Number
-
{{ device.serial_number }}
+
{{ device.serial_number or ''}}
@@ -222,6 +222,7 @@
Components Details
+ {% if device.binding %}
{% for component in device.components|sort(attribute='type') %}
@@ -241,8 +242,13 @@
{% endfor %}
+ {% else %} +
+ {{ device.placeholder.components or '' }} +
+ {% endif %}
- {% if placeholder.binding %} + {% if device.is_abstract() %}
Binding
@@ -252,7 +258,7 @@

-
+ {{ form_binding.csrf_token }} {% for field in form_binding %} {% if field != form_binding.csrf_token %}