join actions and tags
This commit is contained in:
parent
9800b48aa3
commit
9782ab68d6
|
@ -1669,7 +1669,7 @@ class BindingForm(FlaskForm):
|
|||
|
||||
if not self.placeholder:
|
||||
self.placeholder = Placeholder.query.filter(
|
||||
Placeholder.phid == self.phid.data, Placeholder.owner == g.user
|
||||
Placeholder.phid == self.phid.data.strip(), Placeholder.owner == g.user
|
||||
).first()
|
||||
|
||||
if not self.placeholder:
|
||||
|
|
|
@ -37,7 +37,7 @@ from ereuse_devicehub.inventory.forms import (
|
|||
)
|
||||
from ereuse_devicehub.labels.forms import PrintLabelsForm
|
||||
from ereuse_devicehub.parser.models import PlaceholdersLog, SnapshotsLog
|
||||
from ereuse_devicehub.resources.action.models import Trade
|
||||
from ereuse_devicehub.resources.action.models import ActionDevice, Trade
|
||||
from ereuse_devicehub.resources.device.models import (
|
||||
Computer,
|
||||
DataStorage,
|
||||
|
@ -194,12 +194,23 @@ class BindingView(GenericMixin):
|
|||
if request.method == 'POST':
|
||||
old_placeholder = device.binding
|
||||
old_device_placeholder = old_placeholder.device
|
||||
|
||||
if old_placeholder.is_abstract:
|
||||
for plog in PlaceholdersLog.query.filter_by(
|
||||
placeholder_id=old_placeholder.id
|
||||
):
|
||||
db.session.delete(plog)
|
||||
|
||||
for ac in old_device_placeholder.actions:
|
||||
ac.devices.add(placeholder.device)
|
||||
ac.devices.remove(old_device_placeholder)
|
||||
for act in ac.actions_device:
|
||||
if act.device == old_device_placeholder:
|
||||
db.session.delete(act)
|
||||
|
||||
db.session.delete(old_device_placeholder)
|
||||
for tag in list(old_device_placeholder.tags):
|
||||
tag.device = placeholder.device
|
||||
|
||||
device.binding = placeholder
|
||||
db.session.commit()
|
||||
|
@ -209,11 +220,16 @@ class BindingView(GenericMixin):
|
|||
)
|
||||
return flask.redirect(next_url)
|
||||
|
||||
# import pdb; pdb.set_trace()
|
||||
self.context.update(
|
||||
{
|
||||
'device': device.binding.device,
|
||||
'placeholder': placeholder,
|
||||
'page_title': 'Binding confirm',
|
||||
'actions': list(device.binding.device.actions)
|
||||
+ list(placeholder.device.actions),
|
||||
'tags': list(device.binding.device.tags)
|
||||
+ list(placeholder.device.tags),
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -242,10 +258,8 @@ class UnBindingView(GenericMixin):
|
|||
self.get_context()
|
||||
|
||||
if request.method == 'POST':
|
||||
self.clone_device(device)
|
||||
next_url = url_for(
|
||||
'inventory.device_details', id=placeholder.device.devicehub_id
|
||||
)
|
||||
new_device = self.clone_device(device)
|
||||
next_url = url_for('inventory.device_details', id=new_device.devicehub_id)
|
||||
messages.success('Device "{}" unbind successfully!'.format(phid))
|
||||
return flask.redirect(next_url)
|
||||
|
||||
|
@ -678,7 +692,13 @@ class ExportsView(View):
|
|||
def devices_list(self):
|
||||
"""Get device query and put information in csv format."""
|
||||
data = StringIO()
|
||||
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"', quoting=csv.QUOTE_ALL)
|
||||
cw = csv.writer(
|
||||
data,
|
||||
delimiter=';',
|
||||
lineterminator="\n",
|
||||
quotechar='"',
|
||||
quoting=csv.QUOTE_ALL,
|
||||
)
|
||||
first = True
|
||||
|
||||
for device in self.find_devices():
|
||||
|
@ -693,7 +713,13 @@ class ExportsView(View):
|
|||
def metrics(self):
|
||||
"""Get device query and put information in csv format."""
|
||||
data = StringIO()
|
||||
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"', quoting=csv.QUOTE_ALL)
|
||||
cw = csv.writer(
|
||||
data,
|
||||
delimiter=';',
|
||||
lineterminator="\n",
|
||||
quotechar='"',
|
||||
quoting=csv.QUOTE_ALL,
|
||||
)
|
||||
first = True
|
||||
devs_id = []
|
||||
# Get the allocate info
|
||||
|
@ -757,7 +783,13 @@ class ExportsView(View):
|
|||
|
||||
def lots_export(self):
|
||||
data = StringIO()
|
||||
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"', quoting=csv.QUOTE_ALL)
|
||||
cw = csv.writer(
|
||||
data,
|
||||
delimiter=';',
|
||||
lineterminator="\n",
|
||||
quotechar='"',
|
||||
quoting=csv.QUOTE_ALL,
|
||||
)
|
||||
|
||||
cw.writerow(
|
||||
[
|
||||
|
@ -827,7 +859,13 @@ class ExportsView(View):
|
|||
|
||||
def devices_lots_export(self):
|
||||
data = StringIO()
|
||||
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"', quoting=csv.QUOTE_ALL)
|
||||
cw = csv.writer(
|
||||
data,
|
||||
delimiter=';',
|
||||
lineterminator="\n",
|
||||
quotechar='"',
|
||||
quoting=csv.QUOTE_ALL,
|
||||
)
|
||||
head = [
|
||||
'DHID',
|
||||
'Lot Id',
|
||||
|
|
|
@ -139,7 +139,7 @@
|
|||
|
||||
<br />
|
||||
|
||||
{% if placeholder.device.actions or device.actions %}
|
||||
{% if actions %}
|
||||
<h2>Actions</h2>
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
|
@ -151,15 +151,37 @@
|
|||
<tbody>
|
||||
<tr>
|
||||
<td class="table-success text-right">
|
||||
{% for a in placeholder.device.actions %}
|
||||
{% for a in actions %}
|
||||
* {{ a.t }}<br />
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td class="table-danger">
|
||||
{% for a in device.actions %}
|
||||
* {{ a.t }}<br />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
<br />
|
||||
|
||||
{% if tags %}
|
||||
<h2>Tags</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 text-right">
|
||||
{% for tag in tags %}
|
||||
* {{ tag.id }}<br />
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td class="table-danger">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if device.placeholder and placeholder.binding %}
|
||||
{% if device.placeholder and placeholder.binding and device.is_abstract() != 'Abstract'%}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('inventory.unbinding', phid=placeholder.phid) }}">Unbinding</a>
|
||||
</li>
|
||||
|
@ -79,7 +79,21 @@
|
|||
|
||||
<div class="tab-pane fade {% if active_binding %}profile-overview{% else %}show active{% endif %}" id="type">
|
||||
<h5 class="card-title">Details</h5>
|
||||
{% if device.placeholder %}(<a href="{{ url_for('inventory.device_edit', id=device.devicehub_id)}}">edit</a>){% endif %}
|
||||
{% if device.placeholder %}
|
||||
<div class="row mb-3">
|
||||
<div class="col-lg-3 col-md-4 label ">
|
||||
(<a href="{{ url_for('inventory.device_edit', id=device.devicehub_id)}}">Edit Device</a>)
|
||||
</div>
|
||||
<div class="col-lg-9 col-md-8">{{ device.is_abstract() }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if device.placeholder %}
|
||||
<div class="row">
|
||||
<div class="col-lg-3 col-md-4 label ">Phid</div>
|
||||
<div class="col-lg-9 col-md-8">{{ device.placeholder.phid }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-3 col-md-4 label ">Type</div>
|
||||
|
|
|
@ -402,7 +402,7 @@
|
|||
<th scope="col">Title</th>
|
||||
<th scope="col">DHID</th>
|
||||
<th scope="col">PHID</th>
|
||||
<th scope="col">Is Abstract</th>
|
||||
<th scope="col">Type</th>
|
||||
<th scope="col">Unique Identifiers</th>
|
||||
<th scope="col">Lifecycle Status</th>
|
||||
<th scope="col">Allocated Status</th>
|
||||
|
|
Reference in New Issue