add unbinding
This commit is contained in:
parent
c98de60680
commit
7e4deea7fe
|
@ -1,4 +1,5 @@
|
||||||
import csv
|
import csv
|
||||||
|
import copy
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from distutils.util import strtobool
|
from distutils.util import strtobool
|
||||||
|
@ -217,6 +218,72 @@ class BindingView(GenericMixin):
|
||||||
return flask.render_template(self.template_name, **self.context)
|
return flask.render_template(self.template_name, **self.context)
|
||||||
|
|
||||||
|
|
||||||
|
class UnBindingView(GenericMixin):
|
||||||
|
methods = ['GET', 'POST']
|
||||||
|
decorators = [login_required]
|
||||||
|
template_name = 'inventory/unbinding.html'
|
||||||
|
|
||||||
|
def dispatch_request(self, phid):
|
||||||
|
placeholder = (
|
||||||
|
Placeholder.query.filter(Placeholder.owner_id == g.user.id)
|
||||||
|
.filter(Placeholder.phid == phid)
|
||||||
|
.one()
|
||||||
|
)
|
||||||
|
if not placeholder.binding:
|
||||||
|
next_url = url_for('inventory.device_details', id=placeholder.device.devicehub_id)
|
||||||
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
device = placeholder.binding
|
||||||
|
|
||||||
|
self.get_context()
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
self.clone_device(device)
|
||||||
|
next_url = url_for('inventory.device_details', id=placeholder.device.devicehub_id)
|
||||||
|
messages.success(
|
||||||
|
'Device "{}" unbind successfully!'.format(phid)
|
||||||
|
)
|
||||||
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
self.context.update(
|
||||||
|
{
|
||||||
|
'device': device,
|
||||||
|
'placeholder': placeholder,
|
||||||
|
'page_title': 'Unbinding confirm',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return flask.render_template(self.template_name, **self.context)
|
||||||
|
|
||||||
|
def clone_device(self, device):
|
||||||
|
if device.binding.is_abstract:
|
||||||
|
return
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
|
|
||||||
|
dict_device = copy.copy(device.__dict__)
|
||||||
|
dict_device.pop('_sa_instance_state')
|
||||||
|
dict_device.pop('id', None)
|
||||||
|
dict_device.pop('devicehub_id', None)
|
||||||
|
dict_device.pop('actions_multiple', None)
|
||||||
|
dict_device.pop('actions_one', None)
|
||||||
|
dict_device.pop('components', None)
|
||||||
|
dict_device.pop('tags', None)
|
||||||
|
dict_device.pop('system_uuid', None)
|
||||||
|
new_device = device.__class__(**dict_device)
|
||||||
|
db.session.add(new_device)
|
||||||
|
|
||||||
|
if hasattr(device, 'components'):
|
||||||
|
for c in device.components:
|
||||||
|
if c.binding:
|
||||||
|
c.binding.device.parent = new_device
|
||||||
|
|
||||||
|
placeholder = Placeholder(device=new_device, binding=device, is_abstract=True)
|
||||||
|
db.session.add(placeholder)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return new_device
|
||||||
|
|
||||||
|
|
||||||
class LotCreateView(GenericMixin):
|
class LotCreateView(GenericMixin):
|
||||||
methods = ['GET', 'POST']
|
methods = ['GET', 'POST']
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
|
@ -1064,3 +1131,6 @@ devices.add_url_rule(
|
||||||
devices.add_url_rule(
|
devices.add_url_rule(
|
||||||
'/binding/<string:dhid>/<string:phid>/', view_func=BindingView.as_view('binding')
|
'/binding/<string:dhid>/<string:phid>/', view_func=BindingView.as_view('binding')
|
||||||
)
|
)
|
||||||
|
devices.add_url_rule(
|
||||||
|
'/unbinding/<string:phid>/', view_func=UnBindingView.as_view('unbinding')
|
||||||
|
)
|
||||||
|
|
|
@ -215,6 +215,24 @@ class Device(Thing):
|
||||||
def reverse_actions(self) -> list:
|
def reverse_actions(self) -> list:
|
||||||
return reversed(self.actions)
|
return reversed(self.actions)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def manual_actions(self) -> list:
|
||||||
|
mactions = [
|
||||||
|
'ActionDevice',
|
||||||
|
'Allocate',
|
||||||
|
'DataWipe',
|
||||||
|
'Deallocate',
|
||||||
|
'Management',
|
||||||
|
'Prepare',
|
||||||
|
'Ready',
|
||||||
|
'Recycling',
|
||||||
|
'Refurbish',
|
||||||
|
'ToPrepare',
|
||||||
|
'ToRepair',
|
||||||
|
'Use',
|
||||||
|
]
|
||||||
|
return [a for a in self.actions if a in mactions]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def actions(self) -> list:
|
def actions(self) -> list:
|
||||||
"""All the actions where the device participated, including:
|
"""All the actions where the device participated, including:
|
||||||
|
|
|
@ -68,6 +68,12 @@
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if device.placeholder and placeholder.binding %}
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{{ url_for('inventory.unbinding', phid=placeholder.phid) }}">Unbinding</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content pt-2">
|
<div class="tab-content pt-2">
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,185 @@
|
||||||
|
{% extends "ereuse_devicehub/base_site.html" %}
|
||||||
|
{% block main %}
|
||||||
|
|
||||||
|
<div class="pagetitle">
|
||||||
|
<h1>{{ title }}</h1>
|
||||||
|
<nav>
|
||||||
|
<ol class="breadcrumb">
|
||||||
|
<!-- TODO@slamora replace with lot list URL when exists -->
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
</div><!-- End Page Title -->
|
||||||
|
|
||||||
|
<section class="section profile">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-12">
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
|
||||||
|
<div class="pt-4 pb-2">
|
||||||
|
<h5 class="card-title text-center pb-0 fs-4">{{ title }}</h5>
|
||||||
|
<p class="text-center">Please check that the information is correct.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr class="text-center">
|
||||||
|
<th scope="col">Basic Data</th>
|
||||||
|
<th scope="col">Info to be Entered</th>
|
||||||
|
<th scope="col">Info to be Decoupled</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">PHID:</th>
|
||||||
|
<td class="table-success"></td>
|
||||||
|
<td class="table-danger text-right">{{ placeholder.phid or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Manufacturer:</th>
|
||||||
|
<td class="table-success">{{ device.manufacturer or '' }}</td>
|
||||||
|
<td class="table-danger text-right">{{ placeholder.device.manufacturer or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Model:</th>
|
||||||
|
<td class="table-success">{{ device.model or '' }}</td>
|
||||||
|
<td class="table-danger">{{ placeholder.device.model or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Serial Number:</th>
|
||||||
|
<td class="table-success">{{ device.serial_number or '' }}</td>
|
||||||
|
<td class="table-danger">{{ placeholder.device.serial_number or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Brand:</th>
|
||||||
|
<td class="table-success">{{ device.brand or '' }}</td>
|
||||||
|
<td class="table-danger">{{ placeholder.device.brand or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Sku:</th>
|
||||||
|
<td class="table-success">{{ device.sku or '' }}</td>
|
||||||
|
<td class="table-danger">{{ placeholder.device.sku or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Generation:</th>
|
||||||
|
<td class="table-success">{{ device.generation or '' }}</td>
|
||||||
|
<td class="table-danger">{{ placeholder.device.generation or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Version:</th>
|
||||||
|
<td class="table-success">{{ device.version or '' }}</td>
|
||||||
|
<td class="table-danger">{{ placeholder.device.version or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Weight:</th>
|
||||||
|
<td class="table-success">{{ device.weight or '' }}</td>
|
||||||
|
<td class="table-danger">{{ placeholder.device.weight or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Width:</th>
|
||||||
|
<td class="table-success">{{ device.width or '' }}</td>
|
||||||
|
<td class="table-danger">{{ placeholder.device.width or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Height:</th>
|
||||||
|
<td class="table-success">{{ device.height or '' }}</td>
|
||||||
|
<td class="table-danger">{{ placeholder.device.height or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Depth:</th>
|
||||||
|
<td class="table-success">{{ device.depth or '' }}</td>
|
||||||
|
<td class="table-danger">{{ placeholder.device.depth or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Color:</th>
|
||||||
|
<td class="table-success">{{ device.color or '' }}</td>
|
||||||
|
<td class="table-danger">{{ placeholder.device.color or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Production date:</th>
|
||||||
|
<td class="table-success">{{ device.production_date or '' }}</td>
|
||||||
|
<td class="table-danger">{{ placeholder.device.production_date or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Variant:</th>
|
||||||
|
<td class="table-success">{{ device.variant or '' }}</td>
|
||||||
|
<td class="table-danger">{{ placeholder.device.variant or '' }}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
{% if placeholder.device.components or device.components %}
|
||||||
|
<h2>Components</h2>
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr class="text-center">
|
||||||
|
<th scope="col">Info to be Entered</th>
|
||||||
|
<th scope="col">Info to be Decoupled</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="table-success">
|
||||||
|
{% for c in device.components %}
|
||||||
|
* {{ c.verbose_name }}<br />
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
|
<td class="table-danger text-right">
|
||||||
|
{% for c in placeholder.device.components %}
|
||||||
|
* {{ c.verbose_name }}<br />
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
{% if placeholder.device.manual_actions or device.manual_actions %}
|
||||||
|
<h2>Actions</h2>
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr class="text-center">
|
||||||
|
<th scope="col">Info to be Entered</th>
|
||||||
|
<th scope="col">Info to be Decoupled</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="table-success">
|
||||||
|
{% for a in device.manual_actions %}
|
||||||
|
* {{ a.t }}<br />
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
|
<td class="table-danger text-right">
|
||||||
|
{% for a in placeholder.device.manual_actions %}
|
||||||
|
* {{ a.t }}<br />
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<form method="post">
|
||||||
|
<a href="{{ url_for('inventory.device_details', id=placeholder.device.devicehub_id) }}" class="btn btn-danger">Cancel</a>
|
||||||
|
<button class="btn btn-primary" type="submit">Confirm</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-xl-8">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{% endblock main %}
|
Reference in New Issue