join actions and tags

This commit is contained in:
Cayo Puigdefabregas 2022-08-08 18:09:25 +02:00
parent 9800b48aa3
commit 9782ab68d6
5 changed files with 91 additions and 17 deletions

View File

@ -1669,7 +1669,7 @@ class BindingForm(FlaskForm):
if not self.placeholder: if not self.placeholder:
self.placeholder = Placeholder.query.filter( 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() ).first()
if not self.placeholder: if not self.placeholder:

View File

@ -37,7 +37,7 @@ from ereuse_devicehub.inventory.forms import (
) )
from ereuse_devicehub.labels.forms import PrintLabelsForm from ereuse_devicehub.labels.forms import PrintLabelsForm
from ereuse_devicehub.parser.models import PlaceholdersLog, SnapshotsLog 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 ( from ereuse_devicehub.resources.device.models import (
Computer, Computer,
DataStorage, DataStorage,
@ -194,12 +194,23 @@ class BindingView(GenericMixin):
if request.method == 'POST': if request.method == 'POST':
old_placeholder = device.binding old_placeholder = device.binding
old_device_placeholder = old_placeholder.device old_device_placeholder = old_placeholder.device
if old_placeholder.is_abstract: if old_placeholder.is_abstract:
for plog in PlaceholdersLog.query.filter_by( for plog in PlaceholdersLog.query.filter_by(
placeholder_id=old_placeholder.id placeholder_id=old_placeholder.id
): ):
db.session.delete(plog) 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) db.session.delete(old_device_placeholder)
for tag in list(old_device_placeholder.tags):
tag.device = placeholder.device
device.binding = placeholder device.binding = placeholder
db.session.commit() db.session.commit()
@ -209,11 +220,16 @@ class BindingView(GenericMixin):
) )
return flask.redirect(next_url) return flask.redirect(next_url)
# import pdb; pdb.set_trace()
self.context.update( self.context.update(
{ {
'device': device.binding.device, 'device': device.binding.device,
'placeholder': placeholder, 'placeholder': placeholder,
'page_title': 'Binding confirm', '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() self.get_context()
if request.method == 'POST': if request.method == 'POST':
self.clone_device(device) new_device = self.clone_device(device)
next_url = url_for( next_url = url_for('inventory.device_details', id=new_device.devicehub_id)
'inventory.device_details', id=placeholder.device.devicehub_id
)
messages.success('Device "{}" unbind successfully!'.format(phid)) messages.success('Device "{}" unbind successfully!'.format(phid))
return flask.redirect(next_url) return flask.redirect(next_url)
@ -678,7 +692,13 @@ class ExportsView(View):
def devices_list(self): def devices_list(self):
"""Get device query and put information in csv format.""" """Get device query and put information in csv format."""
data = StringIO() 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 first = True
for device in self.find_devices(): for device in self.find_devices():
@ -693,7 +713,13 @@ class ExportsView(View):
def metrics(self): def metrics(self):
"""Get device query and put information in csv format.""" """Get device query and put information in csv format."""
data = StringIO() 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 first = True
devs_id = [] devs_id = []
# Get the allocate info # Get the allocate info
@ -757,7 +783,13 @@ class ExportsView(View):
def lots_export(self): def lots_export(self):
data = StringIO() 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( cw.writerow(
[ [
@ -827,7 +859,13 @@ class ExportsView(View):
def devices_lots_export(self): def devices_lots_export(self):
data = StringIO() 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 = [ head = [
'DHID', 'DHID',
'Lot Id', 'Lot Id',

View File

@ -139,7 +139,7 @@
<br /> <br />
{% if placeholder.device.actions or device.actions %} {% if actions %}
<h2>Actions</h2> <h2>Actions</h2>
<table class="table table-hover"> <table class="table table-hover">
<thead> <thead>
@ -151,15 +151,37 @@
<tbody> <tbody>
<tr> <tr>
<td class="table-success text-right"> <td class="table-success text-right">
{% for a in placeholder.device.actions %} {% for a in actions %}
* {{ a.t }}<br /> * {{ a.t }}<br />
{% endfor %} {% endfor %}
</td> </td>
<td class="table-danger"> <td class="table-danger">
{% for a in device.actions %} </td>
* {{ a.t }}<br /> </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 %} {% endfor %}
</td> </td>
<td class="table-danger">
</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -68,7 +68,7 @@
</li> </li>
{% endif %} {% endif %}
{% if device.placeholder and placeholder.binding %} {% if device.placeholder and placeholder.binding and device.is_abstract() != 'Abstract'%}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{{ url_for('inventory.unbinding', phid=placeholder.phid) }}">Unbinding</a> <a class="nav-link" href="{{ url_for('inventory.unbinding', phid=placeholder.phid) }}">Unbinding</a>
</li> </li>
@ -79,7 +79,21 @@
<div class="tab-pane fade {% if active_binding %}profile-overview{% else %}show active{% endif %}" id="type"> <div class="tab-pane fade {% if active_binding %}profile-overview{% else %}show active{% endif %}" id="type">
<h5 class="card-title">Details</h5> <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="row">
<div class="col-lg-3 col-md-4 label ">Type</div> <div class="col-lg-3 col-md-4 label ">Type</div>

View File

@ -402,7 +402,7 @@
<th scope="col">Title</th> <th scope="col">Title</th>
<th scope="col">DHID</th> <th scope="col">DHID</th>
<th scope="col">PHID</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">Unique Identifiers</th>
<th scope="col">Lifecycle Status</th> <th scope="col">Lifecycle Status</th>
<th scope="col">Allocated Status</th> <th scope="col">Allocated Status</th>