From ae4ea03b49018871ea5fe328c39b8052c72b942b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 12 Aug 2022 15:59:15 +0200 Subject: [PATCH] add new view for search phid --- ereuse_devicehub/inventory/views.py | 33 ++++++++++++--- .../templates/inventory/device_detail.html | 41 +------------------ 2 files changed, 30 insertions(+), 44 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index f2d72350..3b1bff66 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -148,15 +148,37 @@ class DeviceDetailView(GenericMixin): .one() ) - form_binding = BindingForm(device=device) - self.context.update( { 'device': device, 'placeholder': device.binding or device.placeholder, 'page_title': 'Device {}'.format(device.devicehub_id), + } + ) + + return flask.render_template(self.template_name, **self.context) + + +class BindingSearchView(GenericMixin): + methods = ['GET', 'POST'] + decorators = [login_required] + template_name = 'inventory/binding_search.html' + + def dispatch_request(self, dhid): + self.get_context() + device = ( + Device.query.filter(Device.owner_id == current_user.id) + .filter(Device.devicehub_id == dhid) + .one() + ) + + form_binding = BindingForm(device=device) + + self.context.update( + { + 'page_title': 'Search a Device for to do a binding from {}'.format(device.devicehub_id), 'form_binding': form_binding, - 'active_binding': False, + 'device': device } ) @@ -167,8 +189,6 @@ class DeviceDetailView(GenericMixin): phid=form_binding.placeholder.phid, ) return flask.redirect(next_url) - elif form_binding.phid.data: - self.context['active_binding'] = True return flask.render_template(self.template_name, **self.context) @@ -1227,3 +1247,6 @@ devices.add_url_rule( devices.add_url_rule( '/unbinding//', view_func=UnBindingView.as_view('unbinding') ) +devices.add_url_rule( + '//binding/', view_func=BindingSearchView.as_view('binding_search') +) diff --git a/ereuse_devicehub/templates/inventory/device_detail.html b/ereuse_devicehub/templates/inventory/device_detail.html index b233c3ad..98bef52d 100644 --- a/ereuse_devicehub/templates/inventory/device_detail.html +++ b/ereuse_devicehub/templates/inventory/device_detail.html @@ -21,7 +21,7 @@

{{ placeholder.device.devicehub_id }}

{% if placeholder.status in ['Abstract', 'Real'] %} - + Binding {% elif placeholder.status == 'Twin' %} @@ -61,7 +61,7 @@
-
+
Details Real parth
@@ -232,43 +232,6 @@
{% endif %}
- {% if placeholder.status %} -
-
Binding
-
-

- Be careful, binding implies changes in the data of a device that affect its - traceability. -

-
-
-
- {{ form_binding.csrf_token }} - {% for field in form_binding %} - {% if field != form_binding.csrf_token %} - -
- {{ field.label(class_="form-label") }}: - {{ field }} - {% if field.errors %} -

- {% for error in field.errors %} - {{ error }}
- {% endfor %} -

- {% endif %} -
- - {% endif %} - {% endfor %} -
- -
-
-
-
- {% endif %} -