2022-07-29 15:02:27 +00:00
|
|
|
import copy
|
2022-08-02 10:41:31 +00:00
|
|
|
import csv
|
2022-03-04 12:32:37 +00:00
|
|
|
import logging
|
2022-06-24 13:05:38 +00:00
|
|
|
import os
|
2022-02-22 10:11:53 +00:00
|
|
|
from io import StringIO
|
2022-06-24 13:05:38 +00:00
|
|
|
from pathlib import Path
|
2022-02-24 13:15:58 +00:00
|
|
|
|
|
|
|
import flask
|
|
|
|
import flask_weasyprint
|
2022-06-24 13:05:38 +00:00
|
|
|
from flask import Blueprint
|
|
|
|
from flask import current_app as app
|
|
|
|
from flask import g, make_response, request, url_for
|
2021-12-28 11:36:02 +00:00
|
|
|
from flask.views import View
|
2022-02-03 09:50:36 +00:00
|
|
|
from flask_login import current_user, login_required
|
2022-03-08 09:05:32 +00:00
|
|
|
from werkzeug.exceptions import NotFound
|
2021-12-28 11:36:02 +00:00
|
|
|
|
2022-04-29 11:10:44 +00:00
|
|
|
from ereuse_devicehub import messages
|
2022-03-08 09:05:32 +00:00
|
|
|
from ereuse_devicehub.db import db
|
2022-02-24 13:15:58 +00:00
|
|
|
from ereuse_devicehub.inventory.forms import (
|
2022-06-02 11:46:10 +00:00
|
|
|
AdvancedSearchForm,
|
2022-02-25 11:27:14 +00:00
|
|
|
AllocateForm,
|
2022-07-28 15:48:14 +00:00
|
|
|
BindingForm,
|
2022-02-25 11:27:14 +00:00
|
|
|
DataWipeForm,
|
2022-05-30 14:33:01 +00:00
|
|
|
EditTransferForm,
|
2022-03-07 12:07:26 +00:00
|
|
|
FilterForm,
|
2022-02-25 11:27:14 +00:00
|
|
|
LotForm,
|
|
|
|
NewActionForm,
|
|
|
|
NewDeviceForm,
|
2022-06-03 18:01:13 +00:00
|
|
|
NotesForm,
|
2022-02-25 11:27:14 +00:00
|
|
|
TagDeviceForm,
|
2022-02-25 11:34:02 +00:00
|
|
|
TradeDocumentForm,
|
|
|
|
TradeForm,
|
2022-05-27 14:32:22 +00:00
|
|
|
TransferForm,
|
2022-07-04 09:26:24 +00:00
|
|
|
UploadPlaceholderForm,
|
2022-02-25 11:57:13 +00:00
|
|
|
UploadSnapshotForm,
|
2022-02-25 11:56:01 +00:00
|
|
|
)
|
2022-03-31 14:12:35 +00:00
|
|
|
from ereuse_devicehub.labels.forms import PrintLabelsForm
|
2022-07-07 11:10:05 +00:00
|
|
|
from ereuse_devicehub.parser.models import PlaceholdersLog, SnapshotsLog
|
2022-09-20 08:27:02 +00:00
|
|
|
from ereuse_devicehub.resources.action.models import EraseBasic, Trade
|
2022-07-28 15:48:14 +00:00
|
|
|
from ereuse_devicehub.resources.device.models import (
|
|
|
|
Computer,
|
|
|
|
DataStorage,
|
|
|
|
Device,
|
|
|
|
Placeholder,
|
|
|
|
)
|
2022-02-25 11:57:13 +00:00
|
|
|
from ereuse_devicehub.resources.documents.device_row import ActionRow, DeviceRow
|
2022-06-17 12:14:32 +00:00
|
|
|
from ereuse_devicehub.resources.enums import SnapshotSoftware
|
2022-02-24 13:15:58 +00:00
|
|
|
from ereuse_devicehub.resources.hash_reports import insert_hash
|
2021-12-29 12:44:28 +00:00
|
|
|
from ereuse_devicehub.resources.lot.models import Lot
|
2022-01-11 12:13:57 +00:00
|
|
|
from ereuse_devicehub.resources.tag.model import Tag
|
2022-05-16 15:52:31 +00:00
|
|
|
from ereuse_devicehub.views import GenericMixin
|
2021-12-28 11:36:02 +00:00
|
|
|
|
2022-03-15 13:33:27 +00:00
|
|
|
devices = Blueprint('inventory', __name__, url_prefix='/inventory')
|
2021-12-28 11:36:02 +00:00
|
|
|
|
2022-03-04 12:32:37 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2021-12-28 11:36:02 +00:00
|
|
|
|
2022-05-16 15:52:31 +00:00
|
|
|
class DeviceListMixin(GenericMixin):
|
2022-03-08 16:43:15 +00:00
|
|
|
template_name = 'inventory/device_list.html'
|
|
|
|
|
2022-09-09 09:48:23 +00:00
|
|
|
def get_context(self, lot_id=None, all_devices=False):
|
2022-04-29 11:10:44 +00:00
|
|
|
super().get_context()
|
2022-09-09 09:48:23 +00:00
|
|
|
|
2022-04-29 11:10:44 +00:00
|
|
|
lots = self.context['lots']
|
2022-09-09 09:48:23 +00:00
|
|
|
form_filter = FilterForm(lots, lot_id, all_devices=all_devices)
|
2022-05-09 11:43:02 +00:00
|
|
|
devices = form_filter.search()
|
2021-12-30 20:40:44 +00:00
|
|
|
lot = None
|
2022-05-30 14:33:01 +00:00
|
|
|
form_transfer = ''
|
2022-06-06 11:37:58 +00:00
|
|
|
form_delivery = ''
|
|
|
|
form_receiver = ''
|
2022-01-25 11:53:36 +00:00
|
|
|
|
2022-01-25 09:30:46 +00:00
|
|
|
if lot_id:
|
|
|
|
lot = lots.filter(Lot.id == lot_id).one()
|
2022-05-30 14:33:01 +00:00
|
|
|
if not lot.is_temporary and lot.transfer:
|
2022-05-30 15:35:27 +00:00
|
|
|
form_transfer = EditTransferForm(lot_id=lot.id)
|
2022-06-03 18:01:13 +00:00
|
|
|
form_delivery = NotesForm(lot_id=lot.id, type='Delivery')
|
|
|
|
form_receiver = NotesForm(lot_id=lot.id, type='Receiver')
|
2022-02-04 12:22:47 +00:00
|
|
|
|
2022-05-12 12:23:01 +00:00
|
|
|
form_new_action = NewActionForm(lot=lot_id)
|
2022-04-29 11:10:44 +00:00
|
|
|
self.context.update(
|
|
|
|
{
|
|
|
|
'devices': devices,
|
|
|
|
'form_new_action': form_new_action,
|
2022-05-12 12:23:01 +00:00
|
|
|
'form_new_allocate': AllocateForm(lot=lot_id),
|
|
|
|
'form_new_datawipe': DataWipeForm(lot=lot_id),
|
2022-05-30 14:33:01 +00:00
|
|
|
'form_transfer': form_transfer,
|
2022-06-03 18:01:13 +00:00
|
|
|
'form_delivery': form_delivery,
|
|
|
|
'form_receiver': form_receiver,
|
2022-04-29 11:10:44 +00:00
|
|
|
'form_filter': form_filter,
|
|
|
|
'form_print_labels': PrintLabelsForm(),
|
|
|
|
'lot': lot,
|
2022-04-13 07:44:30 +00:00
|
|
|
'tags': self.get_user_tags(),
|
|
|
|
'list_devices': self.get_selected_devices(form_new_action),
|
2022-09-09 09:48:23 +00:00
|
|
|
'all_devices': all_devices,
|
2022-04-29 11:10:44 +00:00
|
|
|
}
|
|
|
|
)
|
2022-01-10 14:53:11 +00:00
|
|
|
|
2022-02-01 12:40:06 +00:00
|
|
|
return self.context
|
|
|
|
|
2022-04-13 07:44:30 +00:00
|
|
|
def get_user_tags(self):
|
|
|
|
return (
|
|
|
|
Tag.query.filter(Tag.owner_id == current_user.id)
|
|
|
|
.filter(Tag.device_id.is_(None))
|
|
|
|
.order_by(Tag.id.asc())
|
|
|
|
)
|
|
|
|
|
|
|
|
def get_selected_devices(self, action_form):
|
|
|
|
"""Retrieve selected devices (when action form is submited)"""
|
|
|
|
action_devices = action_form.devices.data
|
|
|
|
if action_devices:
|
|
|
|
return [int(x) for x in action_devices.split(",")]
|
|
|
|
return []
|
|
|
|
|
2022-02-01 12:40:06 +00:00
|
|
|
|
2022-09-20 08:27:02 +00:00
|
|
|
class ErasureListView(DeviceListMixin):
|
|
|
|
template_name = 'inventory/erasure_list.html'
|
|
|
|
|
|
|
|
def dispatch_request(self):
|
|
|
|
self.get_context()
|
|
|
|
self.get_devices()
|
|
|
|
return flask.render_template(self.template_name, **self.context)
|
|
|
|
|
|
|
|
def get_devices(self):
|
2022-09-20 10:20:30 +00:00
|
|
|
erasure = EraseBasic.query.filter_by(author=g.user).order_by(
|
|
|
|
EraseBasic.created.desc()
|
|
|
|
)
|
2022-09-20 08:27:02 +00:00
|
|
|
self.context['erasure'] = erasure
|
|
|
|
|
|
|
|
|
2022-05-16 15:52:31 +00:00
|
|
|
class DeviceListView(DeviceListMixin):
|
2022-02-01 12:40:06 +00:00
|
|
|
def dispatch_request(self, lot_id=None):
|
2022-09-09 09:48:23 +00:00
|
|
|
self.get_context(lot_id)
|
|
|
|
return flask.render_template(self.template_name, **self.context)
|
|
|
|
|
|
|
|
|
|
|
|
class AllDeviceListView(DeviceListMixin):
|
|
|
|
def dispatch_request(self):
|
|
|
|
self.get_context(all_devices=True)
|
2022-02-01 12:40:06 +00:00
|
|
|
return flask.render_template(self.template_name, **self.context)
|
2021-12-30 16:23:34 +00:00
|
|
|
|
|
|
|
|
2022-06-03 09:34:49 +00:00
|
|
|
class AdvancedSearchView(DeviceListMixin):
|
2022-06-02 11:46:10 +00:00
|
|
|
methods = ['GET', 'POST']
|
|
|
|
template_name = 'inventory/search.html'
|
|
|
|
title = "Advanced Search"
|
|
|
|
|
|
|
|
def dispatch_request(self):
|
|
|
|
query = request.args.get('q', '')
|
2022-09-09 09:48:23 +00:00
|
|
|
self.get_context()
|
2022-06-02 11:46:10 +00:00
|
|
|
form = AdvancedSearchForm(q=query)
|
|
|
|
self.context.update({'devices': form.devices, 'advanced_form': form})
|
|
|
|
return flask.render_template(self.template_name, **self.context)
|
|
|
|
|
|
|
|
|
2022-05-16 15:52:31 +00:00
|
|
|
class DeviceDetailView(GenericMixin):
|
2022-07-28 15:48:14 +00:00
|
|
|
methods = ['GET', 'POST']
|
2022-01-13 15:08:55 +00:00
|
|
|
decorators = [login_required]
|
2022-02-02 11:21:30 +00:00
|
|
|
template_name = 'inventory/device_detail.html'
|
2022-01-13 15:08:55 +00:00
|
|
|
|
|
|
|
def dispatch_request(self, id):
|
2022-04-29 11:10:44 +00:00
|
|
|
self.get_context()
|
2022-02-24 13:15:58 +00:00
|
|
|
device = (
|
|
|
|
Device.query.filter(Device.owner_id == current_user.id)
|
|
|
|
.filter(Device.devicehub_id == id)
|
|
|
|
.one()
|
|
|
|
)
|
2022-01-13 15:08:55 +00:00
|
|
|
|
2022-08-30 11:10:35 +00:00
|
|
|
form_tags = TagDeviceForm(dhid=id)
|
2022-04-29 11:10:44 +00:00
|
|
|
self.context.update(
|
|
|
|
{
|
|
|
|
'device': device,
|
2022-07-15 14:47:39 +00:00
|
|
|
'placeholder': device.binding or device.placeholder,
|
2022-04-29 11:10:44 +00:00
|
|
|
'page_title': 'Device {}'.format(device.devicehub_id),
|
2022-08-30 11:10:35 +00:00
|
|
|
'form_tag_device': form_tags,
|
2022-08-12 13:59:15 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
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(
|
|
|
|
{
|
2022-08-12 14:29:51 +00:00
|
|
|
'page_title': 'Search a Device for to do a binding from {}'.format(
|
|
|
|
device.devicehub_id
|
|
|
|
),
|
2022-07-28 15:48:14 +00:00
|
|
|
'form_binding': form_binding,
|
2022-08-12 14:29:51 +00:00
|
|
|
'device': device,
|
2022-07-28 15:48:14 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
if form_binding.validate_on_submit():
|
|
|
|
next_url = url_for(
|
|
|
|
'inventory.binding',
|
2022-08-12 14:29:51 +00:00
|
|
|
dhid=dhid,
|
2022-07-28 15:48:14 +00:00
|
|
|
phid=form_binding.placeholder.phid,
|
|
|
|
)
|
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
|
|
|
return flask.render_template(self.template_name, **self.context)
|
|
|
|
|
|
|
|
|
|
|
|
class BindingView(GenericMixin):
|
|
|
|
methods = ['GET', 'POST']
|
|
|
|
decorators = [login_required]
|
|
|
|
template_name = 'inventory/binding.html'
|
|
|
|
|
|
|
|
def dispatch_request(self, dhid, phid):
|
2022-08-11 15:30:00 +00:00
|
|
|
self.phid = phid
|
|
|
|
self.dhid = dhid
|
|
|
|
self.next_url = url_for('inventory.device_details', id=dhid)
|
2022-07-28 15:48:14 +00:00
|
|
|
self.get_context()
|
2022-08-11 15:30:00 +00:00
|
|
|
self.get_objects()
|
|
|
|
if self.check_errors():
|
|
|
|
return flask.redirect(self.next_url)
|
2022-08-08 16:09:25 +00:00
|
|
|
|
2022-08-11 12:50:47 +00:00
|
|
|
if request.method == 'POST':
|
2022-08-11 15:30:00 +00:00
|
|
|
return self.post()
|
2022-08-08 16:09:25 +00:00
|
|
|
|
2022-08-11 15:30:00 +00:00
|
|
|
self.context.update(
|
|
|
|
{
|
|
|
|
'new_placeholder': self.new_placeholder,
|
|
|
|
'old_placeholder': self.old_placeholder,
|
|
|
|
'page_title': 'Binding confirm',
|
|
|
|
'actions': list(self.old_device.actions)
|
|
|
|
+ list(self.new_device.actions),
|
|
|
|
'tags': list(self.old_device.tags) + list(self.new_device.tags),
|
|
|
|
'dhid': self.dhid,
|
|
|
|
}
|
|
|
|
)
|
2022-08-08 16:09:25 +00:00
|
|
|
|
2022-08-11 15:30:00 +00:00
|
|
|
return flask.render_template(self.template_name, **self.context)
|
2022-08-02 10:41:31 +00:00
|
|
|
|
2022-08-11 15:30:00 +00:00
|
|
|
def check_errors(self):
|
|
|
|
if not self.new_placeholder:
|
|
|
|
messages.error('Device Phid: "{}" not exist!'.format(self.phid))
|
|
|
|
return True
|
2022-08-09 10:17:18 +00:00
|
|
|
|
2022-09-15 09:51:27 +00:00
|
|
|
if self.old_device.placeholder.status != 'Snapshot':
|
2022-08-11 15:30:00 +00:00
|
|
|
messages.error(
|
2022-09-15 09:51:27 +00:00
|
|
|
'Device Dhid: "{}" is not a Snapshot device!'.format(self.dhid)
|
2022-08-11 15:30:00 +00:00
|
|
|
)
|
|
|
|
return True
|
|
|
|
|
|
|
|
if self.new_placeholder.status == 'Twin':
|
|
|
|
messages.error('Device Phid: "{}" is a Twin device!'.format(self.phid))
|
|
|
|
return True
|
2022-08-11 12:50:47 +00:00
|
|
|
|
2022-08-11 15:30:00 +00:00
|
|
|
if self.new_placeholder.status == self.old_placeholder.status:
|
|
|
|
txt = 'Device Phid: "{}" and device Dhid: "{}" have the same status, "{}"!'.format(
|
|
|
|
self.phid, self.dhid, self.new_placeholder.status
|
2022-07-28 15:48:14 +00:00
|
|
|
)
|
2022-08-11 15:30:00 +00:00
|
|
|
messages.error(txt)
|
|
|
|
return True
|
2022-07-28 15:48:14 +00:00
|
|
|
|
2022-08-11 15:30:00 +00:00
|
|
|
def get_objects(self):
|
|
|
|
self.old_device = (
|
|
|
|
Device.query.filter(Device.owner_id == g.user.id)
|
|
|
|
.filter(Device.devicehub_id == self.dhid)
|
|
|
|
.one()
|
|
|
|
)
|
|
|
|
self.new_placeholder = (
|
|
|
|
Placeholder.query.filter(Placeholder.owner_id == g.user.id)
|
|
|
|
.filter(Placeholder.phid == self.phid)
|
|
|
|
.first()
|
2022-04-29 11:10:44 +00:00
|
|
|
)
|
2022-07-28 15:48:14 +00:00
|
|
|
|
2022-08-11 15:30:00 +00:00
|
|
|
if not self.new_placeholder:
|
|
|
|
return
|
|
|
|
|
2022-09-15 09:51:27 +00:00
|
|
|
if self.old_device.placeholder.status == 'Snapshot':
|
2022-08-11 15:30:00 +00:00
|
|
|
self.new_device = self.new_placeholder.device
|
|
|
|
self.old_placeholder = self.old_device.placeholder
|
2022-09-15 09:51:27 +00:00
|
|
|
elif self.old_device.placeholder.status == 'Placeholder':
|
2022-08-11 15:30:00 +00:00
|
|
|
self.new_device = self.old_device
|
|
|
|
self.old_placeholder = self.new_placeholder
|
|
|
|
self.old_device = self.old_placeholder.device
|
|
|
|
self.new_placeholder = self.new_device.placeholder
|
|
|
|
|
|
|
|
self.abstract_device = self.old_placeholder.binding
|
2022-08-29 09:37:39 +00:00
|
|
|
self.real_dhid = self.new_device.devicehub_id
|
|
|
|
self.real_phid = self.new_placeholder.phid
|
|
|
|
self.abstract_dhid = self.old_device.devicehub_id
|
|
|
|
self.abstract_phid = self.old_placeholder.phid
|
2022-08-11 15:30:00 +00:00
|
|
|
|
2022-09-07 12:04:09 +00:00
|
|
|
# to do a backup of abstract_dhid and abstract_phid in
|
|
|
|
# workbench device
|
|
|
|
self.abstract_device.dhid_bk = self.abstract_dhid
|
|
|
|
self.abstract_device.phid_bk = self.abstract_phid
|
|
|
|
|
2022-08-11 15:30:00 +00:00
|
|
|
def post(self):
|
|
|
|
for plog in PlaceholdersLog.query.filter_by(
|
|
|
|
placeholder_id=self.old_placeholder.id
|
|
|
|
):
|
|
|
|
db.session.delete(plog)
|
|
|
|
|
|
|
|
for ac in self.old_device.actions:
|
|
|
|
ac.devices.add(self.new_device)
|
|
|
|
ac.devices.remove(self.old_device)
|
|
|
|
for act in ac.actions_device:
|
|
|
|
if act.device == self.old_device:
|
|
|
|
db.session.delete(act)
|
|
|
|
|
|
|
|
for tag in list(self.old_device.tags):
|
|
|
|
tag.device = self.new_device
|
|
|
|
|
|
|
|
db.session.delete(self.old_device)
|
|
|
|
self.abstract_device.binding = self.new_placeholder
|
|
|
|
db.session.commit()
|
|
|
|
|
2022-08-29 09:37:39 +00:00
|
|
|
next_url = url_for('inventory.device_details', id=self.real_dhid)
|
2022-09-15 09:51:27 +00:00
|
|
|
txt = 'Device placeholder with PHID: {} and DHID: {} bind successfully with '
|
|
|
|
txt += 'device snapshot PHID: {} DHID: {}.'
|
2022-08-11 15:30:00 +00:00
|
|
|
messages.success(
|
2022-08-29 09:37:39 +00:00
|
|
|
txt.format(
|
2022-08-29 10:49:15 +00:00
|
|
|
self.real_phid, self.real_dhid, self.abstract_phid, self.abstract_dhid
|
2022-08-11 15:30:00 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
return flask.redirect(next_url)
|
2022-01-13 15:08:55 +00:00
|
|
|
|
|
|
|
|
2022-07-29 15:02:27 +00:00
|
|
|
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()
|
|
|
|
)
|
2022-08-11 12:50:47 +00:00
|
|
|
if not placeholder.binding or placeholder.status != 'Twin':
|
2022-08-02 10:41:31 +00:00
|
|
|
next_url = url_for(
|
|
|
|
'inventory.device_details', id=placeholder.device.devicehub_id
|
|
|
|
)
|
2022-07-29 15:02:27 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
2022-08-11 12:50:47 +00:00
|
|
|
if placeholder.status != 'Twin':
|
|
|
|
dhid = placeholder.device.devicehub_id
|
2022-08-09 11:19:16 +00:00
|
|
|
next_url = url_for('inventory.device_details', id=dhid)
|
2022-08-11 12:50:47 +00:00
|
|
|
messages.error('Device Dhid: "{}" not is a Twin device!'.format(dhid))
|
2022-08-09 11:19:16 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
2022-07-29 15:02:27 +00:00
|
|
|
self.get_context()
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
2022-08-11 15:30:00 +00:00
|
|
|
dhid = placeholder.device.devicehub_id
|
|
|
|
self.clone_device(placeholder.binding)
|
|
|
|
next_url = url_for('inventory.device_details', id=dhid)
|
2022-08-29 10:49:15 +00:00
|
|
|
messages.success(
|
|
|
|
'Device with PHID:"{}" and DHID: {} unbind successfully!'.format(
|
|
|
|
phid, dhid
|
|
|
|
)
|
|
|
|
)
|
2022-07-29 15:02:27 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
|
|
|
self.context.update(
|
|
|
|
{
|
|
|
|
'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
|
|
|
|
|
|
|
|
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)
|
2022-08-02 10:41:31 +00:00
|
|
|
dict_device.pop('binding', None)
|
|
|
|
dict_device.pop('placeholder', None)
|
2022-07-29 15:02:27 +00:00
|
|
|
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)
|
2022-09-07 12:04:09 +00:00
|
|
|
if (
|
|
|
|
device.dhid_bk
|
|
|
|
and not Device.query.filter_by(devicehub_id=device.dhid_bk).first()
|
|
|
|
):
|
|
|
|
new_device.devicehub_id = device.dhid_bk
|
|
|
|
if (
|
|
|
|
device.phid_bk
|
|
|
|
and not Placeholder.query.filter_by(phid=device.phid_bk).first()
|
|
|
|
):
|
|
|
|
placeholder.phid = device.phid_bk
|
|
|
|
|
2022-07-29 15:02:27 +00:00
|
|
|
db.session.add(placeholder)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
return new_device
|
|
|
|
|
|
|
|
|
2022-05-16 15:52:31 +00:00
|
|
|
class LotCreateView(GenericMixin):
|
2021-12-30 20:35:54 +00:00
|
|
|
methods = ['GET', 'POST']
|
|
|
|
decorators = [login_required]
|
|
|
|
template_name = 'inventory/lot.html'
|
|
|
|
title = "Add a new lot"
|
|
|
|
|
2022-01-12 16:09:20 +00:00
|
|
|
def dispatch_request(self):
|
|
|
|
form = LotForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
form.save()
|
2022-03-15 13:33:27 +00:00
|
|
|
next_url = url_for('inventory.lotdevicelist', lot_id=form.id)
|
2022-01-12 16:09:20 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
2022-04-29 11:10:44 +00:00
|
|
|
self.get_context()
|
|
|
|
self.context.update(
|
|
|
|
{
|
|
|
|
'form': form,
|
|
|
|
'title': self.title,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return flask.render_template(self.template_name, **self.context)
|
2022-01-12 16:09:20 +00:00
|
|
|
|
|
|
|
|
2022-05-16 15:52:31 +00:00
|
|
|
class LotUpdateView(GenericMixin):
|
2022-01-12 16:09:20 +00:00
|
|
|
methods = ['GET', 'POST']
|
|
|
|
decorators = [login_required]
|
|
|
|
template_name = 'inventory/lot.html'
|
|
|
|
title = "Edit a new lot"
|
|
|
|
|
|
|
|
def dispatch_request(self, id):
|
2021-12-30 20:35:54 +00:00
|
|
|
form = LotForm(id=id)
|
|
|
|
if form.validate_on_submit():
|
2022-01-05 10:10:32 +00:00
|
|
|
form.save()
|
2022-03-15 13:33:27 +00:00
|
|
|
next_url = url_for('inventory.lotdevicelist', lot_id=id)
|
2021-12-30 12:53:28 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
2022-04-29 11:10:44 +00:00
|
|
|
self.get_context()
|
|
|
|
self.context.update(
|
|
|
|
{
|
|
|
|
'form': form,
|
|
|
|
'title': self.title,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return flask.render_template(self.template_name, **self.context)
|
2021-12-30 20:35:54 +00:00
|
|
|
|
2021-12-30 12:53:28 +00:00
|
|
|
|
2022-01-03 11:28:42 +00:00
|
|
|
class LotDeleteView(View):
|
|
|
|
methods = ['GET']
|
|
|
|
decorators = [login_required]
|
|
|
|
template_name = 'inventory/device_list.html'
|
|
|
|
|
|
|
|
def dispatch_request(self, id):
|
|
|
|
form = LotForm(id=id)
|
2022-03-07 09:20:18 +00:00
|
|
|
if form.instance.trade:
|
|
|
|
msg = "Sorry, the lot cannot be deleted because have a trade action "
|
2022-03-04 17:30:14 +00:00
|
|
|
messages.error(msg)
|
2022-03-15 13:33:27 +00:00
|
|
|
next_url = url_for('inventory.lotdevicelist', lot_id=id)
|
2022-03-04 17:30:14 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
2022-01-03 11:28:42 +00:00
|
|
|
form.remove()
|
2022-03-15 13:33:27 +00:00
|
|
|
next_url = url_for('inventory.devicelist')
|
2022-01-03 11:28:42 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
|
|
|
|
2022-05-16 15:52:31 +00:00
|
|
|
class UploadSnapshotView(GenericMixin):
|
2022-01-17 13:17:52 +00:00
|
|
|
methods = ['GET', 'POST']
|
|
|
|
decorators = [login_required]
|
|
|
|
template_name = 'inventory/upload_snapshot.html'
|
|
|
|
|
2022-03-08 16:43:15 +00:00
|
|
|
def dispatch_request(self, lot_id=None):
|
2022-04-29 11:10:44 +00:00
|
|
|
self.get_context()
|
2022-01-17 13:17:52 +00:00
|
|
|
form = UploadSnapshotForm()
|
2022-04-29 11:10:44 +00:00
|
|
|
self.context.update(
|
|
|
|
{
|
|
|
|
'page_title': 'Upload Snapshot',
|
|
|
|
'form': form,
|
|
|
|
'lot_id': lot_id,
|
|
|
|
}
|
|
|
|
)
|
2022-01-17 13:17:52 +00:00
|
|
|
if form.validate_on_submit():
|
2022-04-12 08:25:45 +00:00
|
|
|
snapshot, devices = form.save(commit=False)
|
2022-03-08 16:43:15 +00:00
|
|
|
if lot_id:
|
2022-04-29 11:10:44 +00:00
|
|
|
lots = self.context['lots']
|
2022-03-08 16:43:15 +00:00
|
|
|
lot = lots.filter(Lot.id == lot_id).one()
|
2022-04-12 08:25:45 +00:00
|
|
|
for dev in devices:
|
|
|
|
lot.devices.add(dev)
|
2022-03-08 16:43:15 +00:00
|
|
|
db.session.add(lot)
|
|
|
|
db.session.commit()
|
2022-01-17 13:17:52 +00:00
|
|
|
|
2022-04-29 11:10:44 +00:00
|
|
|
return flask.render_template(self.template_name, **self.context)
|
2022-01-17 13:17:52 +00:00
|
|
|
|
|
|
|
|
2022-05-16 15:52:31 +00:00
|
|
|
class DeviceCreateView(GenericMixin):
|
2022-01-19 12:40:40 +00:00
|
|
|
methods = ['GET', 'POST']
|
|
|
|
decorators = [login_required]
|
2022-02-02 11:21:30 +00:00
|
|
|
template_name = 'inventory/device_create.html'
|
2022-01-19 12:40:40 +00:00
|
|
|
|
2022-03-08 16:43:15 +00:00
|
|
|
def dispatch_request(self, lot_id=None):
|
2022-04-29 11:10:44 +00:00
|
|
|
self.get_context()
|
2022-01-19 12:40:40 +00:00
|
|
|
form = NewDeviceForm()
|
2022-04-29 11:10:44 +00:00
|
|
|
self.context.update(
|
|
|
|
{
|
|
|
|
'page_title': 'New Device',
|
|
|
|
'form': form,
|
|
|
|
'lot_id': lot_id,
|
|
|
|
}
|
|
|
|
)
|
2022-01-19 12:40:40 +00:00
|
|
|
if form.validate_on_submit():
|
2022-07-18 08:56:36 +00:00
|
|
|
form.save(commit=False)
|
2022-03-15 13:33:27 +00:00
|
|
|
next_url = url_for('inventory.devicelist')
|
2022-03-08 16:43:15 +00:00
|
|
|
if lot_id:
|
2022-03-15 13:33:27 +00:00
|
|
|
next_url = url_for('inventory.lotdevicelist', lot_id=lot_id)
|
2022-07-18 08:56:36 +00:00
|
|
|
if form.objs:
|
2022-07-18 08:07:37 +00:00
|
|
|
lots = self.context['lots']
|
|
|
|
lot = lots.filter(Lot.id == lot_id).one()
|
2022-07-18 08:56:36 +00:00
|
|
|
lot.devices = lot.devices.union(form.objs)
|
2022-07-18 08:07:37 +00:00
|
|
|
else:
|
|
|
|
messages.error('Sorry, the device could not be created')
|
2022-03-08 16:43:15 +00:00
|
|
|
|
|
|
|
db.session.commit()
|
2022-09-13 11:17:05 +00:00
|
|
|
|
|
|
|
amount = form.amount.data
|
|
|
|
tpy = form.type.data
|
2022-09-15 09:51:27 +00:00
|
|
|
txt = f'{amount} placeholders Device "{tpy}" created successfully.'
|
2022-09-13 16:15:50 +00:00
|
|
|
placeholder = (
|
|
|
|
Placeholder.query.filter_by(owner=g.user)
|
|
|
|
.order_by(Placeholder.id.desc())
|
|
|
|
.first()
|
|
|
|
)
|
|
|
|
if amount == 1 and placeholder:
|
|
|
|
phid = placeholder.phid
|
|
|
|
dhid = placeholder.device.devicehub_id
|
2022-09-15 09:51:27 +00:00
|
|
|
txt = f'Device "{tpy}" placeholder with PHID {phid} and DHID {dhid} '
|
2022-09-13 11:17:05 +00:00
|
|
|
txt += 'created successfully'
|
|
|
|
messages.success(txt)
|
2022-01-19 12:40:40 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
2022-04-29 11:10:44 +00:00
|
|
|
return flask.render_template(self.template_name, **self.context)
|
2022-01-19 12:40:40 +00:00
|
|
|
|
|
|
|
|
2022-07-05 16:09:47 +00:00
|
|
|
class DeviceEditView(GenericMixin):
|
|
|
|
methods = ['GET', 'POST']
|
|
|
|
decorators = [login_required]
|
|
|
|
template_name = 'inventory/device_create.html'
|
|
|
|
|
|
|
|
def dispatch_request(self, id):
|
|
|
|
self.get_context()
|
|
|
|
device = (
|
|
|
|
Device.query.filter(Device.owner_id == current_user.id)
|
|
|
|
.filter(Device.devicehub_id == id)
|
|
|
|
.one()
|
|
|
|
)
|
|
|
|
form = NewDeviceForm(_obj=device)
|
|
|
|
self.context.update(
|
|
|
|
{
|
|
|
|
'page_title': 'Edit Device',
|
|
|
|
'form': form,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
if form.validate_on_submit():
|
|
|
|
next_url = url_for('inventory.device_details', id=id)
|
|
|
|
form.save(commit=True)
|
|
|
|
messages.success('Device "{}" edited successfully!'.format(form.type.data))
|
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
|
|
|
return flask.render_template(self.template_name, **self.context)
|
|
|
|
|
|
|
|
|
2022-02-02 11:21:30 +00:00
|
|
|
class TagLinkDeviceView(View):
|
2022-01-25 11:53:36 +00:00
|
|
|
methods = ['POST']
|
|
|
|
decorators = [login_required]
|
|
|
|
|
2022-08-30 11:10:35 +00:00
|
|
|
def dispatch_request(self, dhid):
|
|
|
|
form = TagDeviceForm(dhid=dhid)
|
2022-01-25 11:53:36 +00:00
|
|
|
if form.validate_on_submit():
|
2022-08-30 11:10:35 +00:00
|
|
|
tag = form.tag.data
|
2022-01-25 11:53:36 +00:00
|
|
|
form.save()
|
|
|
|
|
2022-08-30 11:10:35 +00:00
|
|
|
next_url = url_for('inventory.device_details', id=dhid)
|
|
|
|
messages.success('Tag {} was linked successfully!'.format(tag))
|
|
|
|
return flask.redirect(next_url)
|
2022-01-25 11:53:36 +00:00
|
|
|
|
|
|
|
|
2022-05-16 15:52:31 +00:00
|
|
|
class TagUnlinkDeviceView(GenericMixin):
|
2022-01-25 13:39:15 +00:00
|
|
|
methods = ['POST', 'GET']
|
2022-01-25 11:53:36 +00:00
|
|
|
decorators = [login_required]
|
2022-02-02 11:21:30 +00:00
|
|
|
template_name = 'inventory/tag_unlink_device.html'
|
2022-01-25 11:53:36 +00:00
|
|
|
|
2022-08-30 11:10:35 +00:00
|
|
|
def dispatch_request(self, dhid):
|
2022-04-29 11:10:44 +00:00
|
|
|
self.get_context()
|
2022-08-30 11:10:35 +00:00
|
|
|
form = TagDeviceForm(delete=True, dhid=dhid)
|
2022-01-25 11:53:36 +00:00
|
|
|
if form.validate_on_submit():
|
|
|
|
form.remove()
|
|
|
|
|
2022-08-30 11:10:35 +00:00
|
|
|
next_url = url_for('inventory.device_details', id=dhid)
|
|
|
|
messages.success('Tag {} was unlinked successfully!'.format(form.tag.data))
|
2022-01-26 11:29:03 +00:00
|
|
|
return flask.redirect(next_url)
|
2022-01-25 11:53:36 +00:00
|
|
|
|
2022-04-29 11:10:44 +00:00
|
|
|
self.context.update(
|
|
|
|
{
|
|
|
|
'form': form,
|
2022-08-30 11:10:35 +00:00
|
|
|
'dhid': dhid,
|
2022-04-29 11:10:44 +00:00
|
|
|
}
|
2022-02-24 13:15:58 +00:00
|
|
|
)
|
2022-01-19 12:40:40 +00:00
|
|
|
|
2022-04-29 11:10:44 +00:00
|
|
|
return flask.render_template(self.template_name, **self.context)
|
|
|
|
|
2022-01-19 12:40:40 +00:00
|
|
|
|
2022-01-05 15:00:13 +00:00
|
|
|
class NewActionView(View):
|
|
|
|
methods = ['POST']
|
|
|
|
decorators = [login_required]
|
2022-02-08 10:52:30 +00:00
|
|
|
form_class = NewActionForm
|
2022-01-05 15:00:13 +00:00
|
|
|
|
|
|
|
def dispatch_request(self):
|
2022-02-08 10:52:30 +00:00
|
|
|
self.form = self.form_class()
|
2022-04-21 12:02:16 +00:00
|
|
|
next_url = self.get_next_url()
|
2022-02-04 11:10:27 +00:00
|
|
|
|
2022-02-01 12:40:06 +00:00
|
|
|
if self.form.validate_on_submit():
|
2022-02-24 13:15:58 +00:00
|
|
|
self.form.save()
|
|
|
|
messages.success(
|
|
|
|
'Action "{}" created successfully!'.format(self.form.type.data)
|
|
|
|
)
|
2022-02-08 10:49:13 +00:00
|
|
|
next_url = self.get_next_url()
|
2022-01-05 15:00:13 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
2022-04-21 12:02:16 +00:00
|
|
|
messages.error('Action {} error!'.format(self.form.type.data))
|
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
2022-02-08 10:49:13 +00:00
|
|
|
def get_next_url(self):
|
2022-02-04 11:10:27 +00:00
|
|
|
lot_id = self.form.lot.data
|
2022-02-08 10:49:13 +00:00
|
|
|
|
2022-02-04 11:10:27 +00:00
|
|
|
if lot_id:
|
2022-03-15 13:33:27 +00:00
|
|
|
return url_for('inventory.lotdevicelist', lot_id=lot_id)
|
2022-02-04 11:10:27 +00:00
|
|
|
|
2022-03-15 13:33:27 +00:00
|
|
|
return url_for('inventory.devicelist')
|
2022-01-05 15:00:13 +00:00
|
|
|
|
2022-01-03 11:28:42 +00:00
|
|
|
|
2022-05-16 15:52:31 +00:00
|
|
|
class NewAllocateView(DeviceListMixin, NewActionView):
|
2022-02-01 12:40:06 +00:00
|
|
|
methods = ['POST']
|
2022-02-08 10:52:30 +00:00
|
|
|
form_class = AllocateForm
|
2022-02-01 12:40:06 +00:00
|
|
|
|
2022-02-07 13:01:56 +00:00
|
|
|
def dispatch_request(self):
|
2022-02-08 10:52:30 +00:00
|
|
|
self.form = self.form_class()
|
2022-02-04 11:10:27 +00:00
|
|
|
|
2022-02-03 09:14:10 +00:00
|
|
|
if self.form.validate_on_submit():
|
2022-02-24 13:15:58 +00:00
|
|
|
self.form.save()
|
|
|
|
messages.success(
|
|
|
|
'Action "{}" created successfully!'.format(self.form.type.data)
|
|
|
|
)
|
2022-02-03 09:14:10 +00:00
|
|
|
|
2022-02-08 10:49:13 +00:00
|
|
|
next_url = self.get_next_url()
|
2022-02-03 09:14:10 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
2022-04-21 12:02:16 +00:00
|
|
|
messages.error('Action {} error!'.format(self.form.type.data))
|
2022-04-29 15:53:59 +00:00
|
|
|
for k, v in self.form.errors.items():
|
|
|
|
value = ';'.join(v)
|
2022-05-12 08:33:04 +00:00
|
|
|
key = self.form[k].label.text
|
|
|
|
messages.error('Action Error {key}: {value}!'.format(key=key, value=value))
|
2022-04-21 12:02:16 +00:00
|
|
|
next_url = self.get_next_url()
|
|
|
|
return flask.redirect(next_url)
|
2022-02-01 12:40:06 +00:00
|
|
|
|
|
|
|
|
2022-05-16 15:52:31 +00:00
|
|
|
class NewDataWipeView(DeviceListMixin, NewActionView):
|
2022-02-07 13:01:56 +00:00
|
|
|
methods = ['POST']
|
2022-02-09 10:27:08 +00:00
|
|
|
form_class = DataWipeForm
|
2022-02-07 13:01:56 +00:00
|
|
|
|
|
|
|
def dispatch_request(self):
|
2022-02-09 10:27:08 +00:00
|
|
|
self.form = self.form_class()
|
|
|
|
|
|
|
|
if self.form.validate_on_submit():
|
2022-02-24 13:15:58 +00:00
|
|
|
self.form.save()
|
|
|
|
messages.success(
|
|
|
|
'Action "{}" created successfully!'.format(self.form.type.data)
|
|
|
|
)
|
2022-02-09 10:27:08 +00:00
|
|
|
|
|
|
|
next_url = self.get_next_url()
|
|
|
|
return flask.redirect(next_url)
|
2022-02-07 13:01:56 +00:00
|
|
|
|
2022-04-21 12:02:16 +00:00
|
|
|
messages.error('Action {} error!'.format(self.form.type.data))
|
|
|
|
next_url = self.get_next_url()
|
|
|
|
return flask.redirect(next_url)
|
2022-02-07 13:01:56 +00:00
|
|
|
|
|
|
|
|
2022-05-16 15:52:31 +00:00
|
|
|
class NewTradeView(DeviceListMixin, NewActionView):
|
2022-02-09 13:06:28 +00:00
|
|
|
methods = ['POST']
|
|
|
|
form_class = TradeForm
|
|
|
|
|
|
|
|
def dispatch_request(self):
|
|
|
|
self.form = self.form_class()
|
|
|
|
|
|
|
|
if self.form.validate_on_submit():
|
2022-02-24 13:15:58 +00:00
|
|
|
self.form.save()
|
|
|
|
messages.success(
|
|
|
|
'Action "{}" created successfully!'.format(self.form.type.data)
|
|
|
|
)
|
2022-02-09 13:06:28 +00:00
|
|
|
|
|
|
|
next_url = self.get_next_url()
|
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
2022-04-21 12:02:16 +00:00
|
|
|
messages.error('Action {} error!'.format(self.form.type.data))
|
|
|
|
next_url = self.get_next_url()
|
|
|
|
return flask.redirect(next_url)
|
2022-02-09 13:06:28 +00:00
|
|
|
|
|
|
|
|
2022-02-21 12:03:03 +00:00
|
|
|
class NewTradeDocumentView(View):
|
|
|
|
methods = ['POST', 'GET']
|
|
|
|
decorators = [login_required]
|
|
|
|
template_name = 'inventory/trade_document.html'
|
|
|
|
form_class = TradeDocumentForm
|
|
|
|
title = "Add new document"
|
|
|
|
|
|
|
|
def dispatch_request(self, lot_id):
|
|
|
|
self.form = self.form_class(lot=lot_id)
|
2022-04-29 11:10:44 +00:00
|
|
|
self.get_context()
|
2022-02-21 12:03:03 +00:00
|
|
|
|
|
|
|
if self.form.validate_on_submit():
|
|
|
|
self.form.save()
|
|
|
|
messages.success('Document created successfully!')
|
2022-03-15 13:33:27 +00:00
|
|
|
next_url = url_for('inventory.lotdevicelist', lot_id=lot_id)
|
2022-02-21 12:03:03 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
2022-04-29 11:10:44 +00:00
|
|
|
self.context.update({'form': self.form, 'title': self.title})
|
|
|
|
return flask.render_template(self.template_name, **self.context)
|
2022-02-21 12:03:03 +00:00
|
|
|
|
|
|
|
|
2022-06-01 13:01:02 +00:00
|
|
|
class NewTransferView(GenericMixin):
|
2022-05-27 14:32:22 +00:00
|
|
|
methods = ['POST', 'GET']
|
|
|
|
template_name = 'inventory/new_transfer.html'
|
|
|
|
form_class = TransferForm
|
|
|
|
title = "Add new transfer"
|
|
|
|
|
|
|
|
def dispatch_request(self, lot_id, type_id):
|
|
|
|
self.form = self.form_class(lot_id=lot_id, type=type_id)
|
|
|
|
self.get_context()
|
|
|
|
|
|
|
|
if self.form.validate_on_submit():
|
|
|
|
self.form.save()
|
|
|
|
new_lot_id = lot_id
|
|
|
|
if self.form.newlot.id:
|
2022-05-30 15:35:27 +00:00
|
|
|
new_lot_id = "{}".format(self.form.newlot.id)
|
2022-05-30 14:33:01 +00:00
|
|
|
Lot.query.filter(Lot.id == new_lot_id).one()
|
2022-05-27 14:32:22 +00:00
|
|
|
messages.success('Transfer created successfully!')
|
2022-06-01 11:15:04 +00:00
|
|
|
next_url = url_for('inventory.lotdevicelist', lot_id=str(new_lot_id))
|
2022-05-27 14:32:22 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
|
|
|
self.context.update({'form': self.form, 'title': self.title})
|
|
|
|
return flask.render_template(self.template_name, **self.context)
|
|
|
|
|
|
|
|
|
2022-06-01 13:01:02 +00:00
|
|
|
class EditTransferView(GenericMixin):
|
2022-05-30 14:33:01 +00:00
|
|
|
methods = ['POST']
|
|
|
|
form_class = EditTransferForm
|
|
|
|
|
|
|
|
def dispatch_request(self, lot_id):
|
|
|
|
self.get_context()
|
|
|
|
form = self.form_class(request.form, lot_id=lot_id)
|
|
|
|
next_url = url_for('inventory.lotdevicelist', lot_id=lot_id)
|
|
|
|
|
|
|
|
if form.validate_on_submit():
|
|
|
|
form.save()
|
|
|
|
messages.success('Transfer updated successfully!')
|
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
|
|
|
messages.error('Transfer updated error!')
|
2022-06-06 11:37:58 +00:00
|
|
|
for k, v in form.errors.items():
|
|
|
|
value = ';'.join(v)
|
|
|
|
key = form[k].label.text
|
|
|
|
messages.error('Error {key}: {value}!'.format(key=key, value=value))
|
2022-05-30 14:33:01 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
|
|
|
|
2022-02-22 10:11:53 +00:00
|
|
|
class ExportsView(View):
|
|
|
|
methods = ['GET']
|
|
|
|
decorators = [login_required]
|
|
|
|
|
2022-02-24 13:15:58 +00:00
|
|
|
def dispatch_request(self, export_id):
|
2022-02-22 10:11:53 +00:00
|
|
|
export_ids = {
|
2022-02-24 13:15:58 +00:00
|
|
|
'metrics': self.metrics,
|
|
|
|
'devices': self.devices_list,
|
2022-09-21 07:42:31 +00:00
|
|
|
'actions_erasures': self.actions_erasures,
|
2022-02-24 13:15:58 +00:00
|
|
|
'certificates': self.erasure,
|
2022-06-17 12:14:32 +00:00
|
|
|
'lots': self.lots_export,
|
2022-06-20 08:40:00 +00:00
|
|
|
'devices_lots': self.devices_lots_export,
|
2022-06-24 13:05:38 +00:00
|
|
|
'snapshot': self.snapshot,
|
2022-02-22 10:11:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if export_id not in export_ids:
|
|
|
|
return NotFound()
|
|
|
|
return export_ids[export_id]()
|
|
|
|
|
2022-02-24 13:15:58 +00:00
|
|
|
def find_devices(self):
|
|
|
|
args = request.args.get('ids')
|
|
|
|
ids = args.split(',') if args else []
|
|
|
|
query = Device.query.filter(Device.owner == g.user)
|
|
|
|
return query.filter(Device.devicehub_id.in_(ids))
|
|
|
|
|
|
|
|
def response_csv(self, data, name):
|
2022-02-22 10:11:53 +00:00
|
|
|
bfile = data.getvalue().encode('utf-8')
|
2022-02-24 13:15:58 +00:00
|
|
|
# insert proof
|
|
|
|
insert_hash(bfile)
|
2022-02-22 10:11:53 +00:00
|
|
|
output = make_response(bfile)
|
2022-02-24 13:15:58 +00:00
|
|
|
output.headers['Content-Disposition'] = 'attachment; filename={}'.format(name)
|
2022-02-22 10:11:53 +00:00
|
|
|
output.headers['Content-type'] = 'text/csv'
|
|
|
|
return output
|
|
|
|
|
2022-02-24 13:15:58 +00:00
|
|
|
def devices_list(self):
|
|
|
|
"""Get device query and put information in csv format."""
|
|
|
|
data = StringIO()
|
2022-08-08 16:09:25 +00:00
|
|
|
cw = csv.writer(
|
|
|
|
data,
|
|
|
|
delimiter=';',
|
|
|
|
lineterminator="\n",
|
|
|
|
quotechar='"',
|
|
|
|
quoting=csv.QUOTE_ALL,
|
|
|
|
)
|
2022-02-24 13:15:58 +00:00
|
|
|
first = True
|
|
|
|
|
|
|
|
for device in self.find_devices():
|
|
|
|
d = DeviceRow(device, {})
|
|
|
|
if first:
|
|
|
|
cw.writerow(d.keys())
|
|
|
|
first = False
|
|
|
|
cw.writerow(d.values())
|
|
|
|
|
|
|
|
return self.response_csv(data, "export.csv")
|
|
|
|
|
|
|
|
def metrics(self):
|
|
|
|
"""Get device query and put information in csv format."""
|
|
|
|
data = StringIO()
|
2022-08-08 16:09:25 +00:00
|
|
|
cw = csv.writer(
|
|
|
|
data,
|
|
|
|
delimiter=';',
|
|
|
|
lineterminator="\n",
|
|
|
|
quotechar='"',
|
|
|
|
quoting=csv.QUOTE_ALL,
|
|
|
|
)
|
2022-02-24 13:15:58 +00:00
|
|
|
first = True
|
|
|
|
devs_id = []
|
|
|
|
# Get the allocate info
|
|
|
|
for device in self.find_devices():
|
|
|
|
devs_id.append(device.id)
|
|
|
|
for allocate in device.get_metrics():
|
|
|
|
d = ActionRow(allocate)
|
|
|
|
if first:
|
|
|
|
cw.writerow(d.keys())
|
|
|
|
first = False
|
|
|
|
cw.writerow(d.values())
|
|
|
|
|
|
|
|
# Get the trade info
|
|
|
|
query_trade = Trade.query.filter(
|
|
|
|
Trade.devices.any(Device.id.in_(devs_id))
|
|
|
|
).all()
|
|
|
|
|
|
|
|
lot_id = request.args.get('lot')
|
|
|
|
if lot_id and not query_trade:
|
|
|
|
lot = Lot.query.filter_by(id=lot_id).one()
|
|
|
|
if hasattr(lot, "trade") and lot.trade:
|
|
|
|
if g.user in [lot.trade.user_from, lot.trade.user_to]:
|
|
|
|
query_trade = [lot.trade]
|
|
|
|
|
|
|
|
for trade in query_trade:
|
|
|
|
data_rows = trade.get_metrics()
|
|
|
|
for row in data_rows:
|
|
|
|
d = ActionRow(row)
|
|
|
|
if first:
|
|
|
|
cw.writerow(d.keys())
|
|
|
|
first = False
|
|
|
|
cw.writerow(d.values())
|
|
|
|
|
|
|
|
return self.response_csv(data, "actions_export.csv")
|
|
|
|
|
|
|
|
def erasure(self):
|
|
|
|
template = self.build_erasure_certificate()
|
|
|
|
res = flask_weasyprint.render_pdf(
|
|
|
|
flask_weasyprint.HTML(string=template),
|
|
|
|
download_filename='erasure-certificate.pdf',
|
|
|
|
)
|
|
|
|
insert_hash(res.data)
|
|
|
|
return res
|
|
|
|
|
2022-09-21 07:42:31 +00:00
|
|
|
def actions_erasures(self):
|
|
|
|
data = StringIO()
|
2022-09-21 09:35:31 +00:00
|
|
|
cw = csv.writer(
|
|
|
|
data,
|
|
|
|
delimiter=';',
|
|
|
|
lineterminator="\n",
|
|
|
|
quotechar='"',
|
|
|
|
quoting=csv.QUOTE_ALL,
|
|
|
|
)
|
|
|
|
|
|
|
|
cw.writerow(
|
|
|
|
[
|
|
|
|
'Data Storage Serial',
|
|
|
|
'Snapshot ID',
|
|
|
|
'Type of Erasure',
|
|
|
|
'PHID Erasure Host',
|
|
|
|
'Result',
|
|
|
|
'Time',
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
args = request.args.get('ids')
|
|
|
|
ids = args.split(',') if args else []
|
|
|
|
|
|
|
|
query = EraseBasic.query.filter_by(author=g.user)
|
|
|
|
query = query.filter(EraseBasic.id.in_(ids))
|
|
|
|
query = query.order_by(EraseBasic.created.desc())
|
|
|
|
|
|
|
|
for ac in query:
|
|
|
|
row = [
|
|
|
|
ac.device.serial_number.upper(),
|
|
|
|
ac.snapshot.uuid,
|
|
|
|
ac.type,
|
|
|
|
ac.get_phid(),
|
|
|
|
ac.severity,
|
|
|
|
ac.created.strftime('%Y-%m-%d %H:%M:%S'),
|
|
|
|
]
|
|
|
|
cw.writerow(row)
|
|
|
|
|
2022-09-21 07:42:31 +00:00
|
|
|
return self.response_csv(data, "Erasures.csv")
|
|
|
|
|
2022-02-24 13:15:58 +00:00
|
|
|
def build_erasure_certificate(self):
|
|
|
|
erasures = []
|
|
|
|
for device in self.find_devices():
|
2022-09-20 14:02:25 +00:00
|
|
|
if device.placeholder and device.placeholder.binding:
|
|
|
|
device = device.placeholder.binding
|
2022-02-24 13:15:58 +00:00
|
|
|
if isinstance(device, Computer):
|
|
|
|
for privacy in device.privacy:
|
|
|
|
erasures.append(privacy)
|
|
|
|
elif isinstance(device, DataStorage):
|
|
|
|
if device.privacy:
|
|
|
|
erasures.append(device.privacy)
|
|
|
|
|
|
|
|
params = {
|
|
|
|
'title': 'Erasure Certificate',
|
|
|
|
'erasures': tuple(erasures),
|
|
|
|
'url_pdf': '',
|
|
|
|
}
|
|
|
|
return flask.render_template('inventory/erasure.html', **params)
|
|
|
|
|
2022-06-17 12:14:32 +00:00
|
|
|
def lots_export(self):
|
|
|
|
data = StringIO()
|
2022-08-08 16:09:25 +00:00
|
|
|
cw = csv.writer(
|
|
|
|
data,
|
|
|
|
delimiter=';',
|
|
|
|
lineterminator="\n",
|
|
|
|
quotechar='"',
|
|
|
|
quoting=csv.QUOTE_ALL,
|
|
|
|
)
|
2022-06-17 12:14:32 +00:00
|
|
|
|
|
|
|
cw.writerow(
|
|
|
|
[
|
|
|
|
'Lot Id',
|
|
|
|
'Lot Name',
|
|
|
|
'Lot Type',
|
|
|
|
'Transfer Status',
|
|
|
|
'Transfer Code',
|
|
|
|
'Transfer Date',
|
|
|
|
'Transfer Creation Date',
|
|
|
|
'Transfer Update Date',
|
|
|
|
'Transfer Description',
|
|
|
|
'Devices Number',
|
|
|
|
'Devices Snapshots',
|
|
|
|
'Devices Placeholders',
|
|
|
|
'Delivery Note Number',
|
|
|
|
'Delivery Note Date',
|
|
|
|
'Delivery Note Units',
|
|
|
|
'Delivery Note Weight',
|
|
|
|
'Receiver Note Number',
|
|
|
|
'Receiver Note Date',
|
|
|
|
'Receiver Note Units',
|
|
|
|
'Receiver Note Weight',
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
for lot in Lot.query.filter_by(owner=g.user):
|
|
|
|
delivery_note = lot.transfer and lot.transfer.delivery_note or ''
|
|
|
|
receiver_note = lot.transfer and lot.transfer.receiver_note or ''
|
|
|
|
wb_devs = 0
|
|
|
|
placeholders = 0
|
|
|
|
|
|
|
|
for dev in lot.devices:
|
|
|
|
snapshots = [e for e in dev.actions if e.type == 'Snapshot']
|
|
|
|
if not snapshots or snapshots[-1].software not in [
|
|
|
|
SnapshotSoftware.Workbench
|
|
|
|
]:
|
|
|
|
placeholders += 1
|
|
|
|
elif snapshots[-1].software in [SnapshotSoftware.Workbench]:
|
|
|
|
wb_devs += 1
|
|
|
|
|
|
|
|
row = [
|
|
|
|
lot.id,
|
|
|
|
lot.name,
|
2022-06-20 08:40:00 +00:00
|
|
|
lot.type_transfer(),
|
2022-06-17 12:14:32 +00:00
|
|
|
lot.transfer and (lot.transfer.closed and 'Closed' or 'Open') or '',
|
|
|
|
lot.transfer and lot.transfer.code or '',
|
|
|
|
lot.transfer and lot.transfer.date or '',
|
|
|
|
lot.transfer and lot.transfer.created or '',
|
|
|
|
lot.transfer and lot.transfer.updated or '',
|
|
|
|
lot.transfer and lot.transfer.description or '',
|
|
|
|
len(lot.devices),
|
|
|
|
wb_devs,
|
|
|
|
placeholders,
|
|
|
|
delivery_note and delivery_note.number or '',
|
|
|
|
delivery_note and delivery_note.date or '',
|
|
|
|
delivery_note and delivery_note.units or '',
|
|
|
|
delivery_note and delivery_note.weight or '',
|
|
|
|
receiver_note and receiver_note.number or '',
|
|
|
|
receiver_note and receiver_note.date or '',
|
|
|
|
receiver_note and receiver_note.units or '',
|
|
|
|
receiver_note and receiver_note.weight or '',
|
|
|
|
]
|
|
|
|
cw.writerow(row)
|
|
|
|
|
|
|
|
return self.response_csv(data, "lots_export.csv")
|
|
|
|
|
2022-06-20 08:40:00 +00:00
|
|
|
def devices_lots_export(self):
|
|
|
|
data = StringIO()
|
2022-08-08 16:09:25 +00:00
|
|
|
cw = csv.writer(
|
|
|
|
data,
|
|
|
|
delimiter=';',
|
|
|
|
lineterminator="\n",
|
|
|
|
quotechar='"',
|
|
|
|
quoting=csv.QUOTE_ALL,
|
|
|
|
)
|
2022-06-20 08:40:00 +00:00
|
|
|
head = [
|
|
|
|
'DHID',
|
|
|
|
'Lot Id',
|
|
|
|
'Lot Name',
|
|
|
|
'Lot Type',
|
|
|
|
'Transfer Status',
|
|
|
|
'Transfer Code',
|
|
|
|
'Transfer Date',
|
|
|
|
'Transfer Creation Date',
|
2022-06-20 08:51:32 +00:00
|
|
|
'Transfer Update Date',
|
2022-06-20 08:40:00 +00:00
|
|
|
]
|
|
|
|
cw.writerow(head)
|
|
|
|
|
|
|
|
for dev in self.find_devices():
|
|
|
|
for lot in dev.lots:
|
|
|
|
row = [
|
|
|
|
dev.devicehub_id,
|
|
|
|
lot.id,
|
|
|
|
lot.name,
|
2022-06-20 12:35:57 +00:00
|
|
|
lot.type_transfer(),
|
2022-06-20 08:40:00 +00:00
|
|
|
lot.transfer and (lot.transfer.closed and 'Closed' or 'Open') or '',
|
|
|
|
lot.transfer and lot.transfer.code or '',
|
|
|
|
lot.transfer and lot.transfer.date or '',
|
|
|
|
lot.transfer and lot.transfer.created or '',
|
|
|
|
lot.transfer and lot.transfer.updated or '',
|
|
|
|
]
|
|
|
|
cw.writerow(row)
|
|
|
|
|
2022-06-20 08:51:32 +00:00
|
|
|
return self.response_csv(
|
|
|
|
data, "Devices_Incoming_and_Outgoing_Lots_Spreadsheet.csv"
|
|
|
|
)
|
2022-06-20 08:40:00 +00:00
|
|
|
|
2022-06-24 13:05:38 +00:00
|
|
|
def snapshot(self):
|
|
|
|
uuid = request.args.get('id')
|
|
|
|
if not uuid:
|
|
|
|
messages.error('Snapshot not exist!')
|
|
|
|
return flask.redirect(request.referrer)
|
|
|
|
|
|
|
|
user = g.user.email
|
|
|
|
name_file = f"*_{user}_{uuid}.json"
|
|
|
|
tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
|
|
|
path_dir_base = os.path.join(tmp_snapshots, user)
|
|
|
|
|
|
|
|
for _file in Path(path_dir_base).glob(name_file):
|
|
|
|
with open(_file) as file_snapshot:
|
|
|
|
snapshot = file_snapshot.read()
|
|
|
|
data = StringIO()
|
|
|
|
data.write(snapshot)
|
|
|
|
bfile = data.getvalue().encode('utf-8')
|
|
|
|
output = make_response(bfile)
|
|
|
|
output.headers['Content-Disposition'] = 'attachment; filename={}'.format(
|
|
|
|
name_file
|
|
|
|
)
|
|
|
|
output.headers['Content-type'] = 'text/json'
|
|
|
|
return output
|
|
|
|
|
|
|
|
messages.error('Snapshot not exist!')
|
|
|
|
return flask.redirect(request.referrer)
|
|
|
|
|
2022-02-22 10:11:53 +00:00
|
|
|
|
2022-05-18 09:01:58 +00:00
|
|
|
class SnapshotListView(GenericMixin):
|
2022-05-11 14:59:36 +00:00
|
|
|
template_name = 'inventory/snapshots_list.html'
|
|
|
|
|
2022-05-11 15:03:31 +00:00
|
|
|
def dispatch_request(self):
|
2022-05-11 14:59:36 +00:00
|
|
|
self.get_context()
|
2022-05-18 09:01:58 +00:00
|
|
|
self.context['page_title'] = "Snapshots Logs"
|
2022-05-19 11:48:52 +00:00
|
|
|
self.context['snapshots_log'] = self.get_snapshots_log()
|
2022-05-18 09:01:58 +00:00
|
|
|
|
2022-05-11 14:59:36 +00:00
|
|
|
return flask.render_template(self.template_name, **self.context)
|
2022-04-13 16:31:39 +00:00
|
|
|
|
2022-05-19 11:48:52 +00:00
|
|
|
def get_snapshots_log(self):
|
|
|
|
snapshots_log = SnapshotsLog.query.filter(
|
|
|
|
SnapshotsLog.owner == g.user
|
|
|
|
).order_by(SnapshotsLog.created.desc())
|
|
|
|
logs = {}
|
|
|
|
for snap in snapshots_log:
|
2022-06-15 11:39:06 +00:00
|
|
|
try:
|
|
|
|
system_uuid = snap.snapshot.device.system_uuid or ''
|
|
|
|
except AttributeError:
|
|
|
|
system_uuid = ''
|
|
|
|
|
2022-05-19 11:48:52 +00:00
|
|
|
if snap.snapshot_uuid not in logs:
|
|
|
|
logs[snap.snapshot_uuid] = {
|
|
|
|
'sid': snap.sid,
|
|
|
|
'snapshot_uuid': snap.snapshot_uuid,
|
|
|
|
'version': snap.version,
|
2022-05-19 16:16:47 +00:00
|
|
|
'device': snap.get_device(),
|
2022-06-15 11:39:06 +00:00
|
|
|
'system_uuid': system_uuid,
|
2022-05-19 11:48:52 +00:00
|
|
|
'status': snap.get_status(),
|
|
|
|
'severity': snap.severity,
|
|
|
|
'created': snap.created,
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
|
|
|
|
if snap.created > logs[snap.snapshot_uuid]['created']:
|
|
|
|
logs[snap.snapshot_uuid]['created'] = snap.created
|
|
|
|
|
|
|
|
if snap.severity > logs[snap.snapshot_uuid]['severity']:
|
|
|
|
logs[snap.snapshot_uuid]['severity'] = snap.severity
|
|
|
|
logs[snap.snapshot_uuid]['status'] = snap.get_status()
|
|
|
|
|
|
|
|
result = sorted(logs.values(), key=lambda d: d['created'])
|
|
|
|
result.reverse()
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2022-04-13 16:31:39 +00:00
|
|
|
|
2022-05-19 16:16:47 +00:00
|
|
|
class SnapshotDetailView(GenericMixin):
|
|
|
|
template_name = 'inventory/snapshot_detail.html'
|
|
|
|
|
|
|
|
def dispatch_request(self, snapshot_uuid):
|
|
|
|
self.snapshot_uuid = snapshot_uuid
|
|
|
|
self.get_context()
|
|
|
|
self.context['page_title'] = "Snapshot Detail"
|
|
|
|
self.context['snapshots_log'] = self.get_snapshots_log()
|
|
|
|
self.context['snapshot_uuid'] = snapshot_uuid
|
|
|
|
self.context['snapshot_sid'] = ''
|
|
|
|
if self.context['snapshots_log'].count():
|
|
|
|
self.context['snapshot_sid'] = self.context['snapshots_log'][0].sid
|
|
|
|
|
|
|
|
return flask.render_template(self.template_name, **self.context)
|
|
|
|
|
|
|
|
def get_snapshots_log(self):
|
|
|
|
return (
|
|
|
|
SnapshotsLog.query.filter(SnapshotsLog.owner == g.user)
|
|
|
|
.filter(SnapshotsLog.snapshot_uuid == self.snapshot_uuid)
|
|
|
|
.order_by(SnapshotsLog.created.desc())
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-06-03 18:01:13 +00:00
|
|
|
class DeliveryNoteView(GenericMixin):
|
|
|
|
methods = ['POST']
|
|
|
|
form_class = NotesForm
|
|
|
|
|
|
|
|
def dispatch_request(self, lot_id):
|
|
|
|
self.get_context()
|
|
|
|
form = self.form_class(request.form, lot_id=lot_id, type='Delivery')
|
|
|
|
next_url = url_for('inventory.lotdevicelist', lot_id=lot_id)
|
|
|
|
|
|
|
|
if form.validate_on_submit():
|
|
|
|
form.save()
|
2022-06-06 11:37:58 +00:00
|
|
|
messages.success('Delivery Note updated successfully!')
|
2022-06-03 18:01:13 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
2022-06-06 11:37:58 +00:00
|
|
|
messages.error('Delivery Note updated error!')
|
|
|
|
for k, v in form.errors.items():
|
|
|
|
value = ';'.join(v)
|
|
|
|
key = form[k].label.text
|
|
|
|
messages.error('Error {key}: {value}!'.format(key=key, value=value))
|
2022-06-03 18:01:13 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
|
|
|
|
|
|
|
class ReceiverNoteView(GenericMixin):
|
|
|
|
methods = ['POST']
|
|
|
|
form_class = NotesForm
|
|
|
|
|
|
|
|
def dispatch_request(self, lot_id):
|
|
|
|
self.get_context()
|
|
|
|
form = self.form_class(request.form, lot_id=lot_id, type='Receiver')
|
|
|
|
next_url = url_for('inventory.lotdevicelist', lot_id=lot_id)
|
|
|
|
|
|
|
|
if form.validate_on_submit():
|
|
|
|
form.save()
|
2022-06-06 11:37:58 +00:00
|
|
|
messages.success('Receiver Note updated successfully!')
|
2022-06-03 18:01:13 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
2022-06-06 11:37:58 +00:00
|
|
|
messages.error('Receiver Note updated error!')
|
|
|
|
for k, v in form.errors.items():
|
|
|
|
value = ';'.join(v)
|
|
|
|
key = form[k].label.text
|
|
|
|
messages.error('Error {key}: {value}!'.format(key=key, value=value))
|
2022-06-03 18:01:13 +00:00
|
|
|
return flask.redirect(next_url)
|
|
|
|
|
|
|
|
|
2022-07-04 09:26:24 +00:00
|
|
|
class UploadPlaceholderView(GenericMixin):
|
|
|
|
methods = ['GET', 'POST']
|
|
|
|
decorators = [login_required]
|
|
|
|
template_name = 'inventory/upload_placeholder.html'
|
|
|
|
|
|
|
|
def dispatch_request(self, lot_id=None):
|
|
|
|
self.get_context()
|
|
|
|
form = UploadPlaceholderForm()
|
|
|
|
self.context.update(
|
|
|
|
{
|
|
|
|
'page_title': 'Upload Placeholder',
|
|
|
|
'form': form,
|
|
|
|
'lot_id': lot_id,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
if form.validate_on_submit():
|
|
|
|
snapshots = form.save(commit=False)
|
|
|
|
if lot_id:
|
|
|
|
lots = self.context['lots']
|
|
|
|
lot = lots.filter(Lot.id == lot_id).one()
|
2022-07-07 11:10:05 +00:00
|
|
|
for device, p in snapshots:
|
2022-07-05 16:09:47 +00:00
|
|
|
lot.devices.add(device)
|
2022-07-04 09:26:24 +00:00
|
|
|
db.session.add(lot)
|
|
|
|
db.session.commit()
|
2022-09-12 15:38:29 +00:00
|
|
|
dev_new = form.dev_new
|
|
|
|
dev_update = form.dev_update
|
|
|
|
total = dev_new + dev_update
|
|
|
|
txt = 'Placeholders uploaded successfully!'
|
|
|
|
|
|
|
|
if dev_update == 0:
|
|
|
|
txt = f'A total of {total} Placeholders have been successfully'
|
|
|
|
txt += ' uploaded. All of them have been new registrations in'
|
|
|
|
txt += ' the system.'
|
|
|
|
|
|
|
|
if dev_new == 0:
|
|
|
|
txt = f'A total of {total} Placeholders have been successfully'
|
|
|
|
txt += ' uploaded. All of them are updates.'
|
|
|
|
|
|
|
|
if dev_new and dev_update:
|
|
|
|
txt = f'A total of {total} Placeholders have been successfully'
|
|
|
|
txt += f' uploaded. Among these {dev_new} are registered for '
|
|
|
|
txt += ' the first time in the system and another'
|
|
|
|
txt += f' {dev_update} have been updated.'
|
|
|
|
|
|
|
|
messages.success(txt)
|
2022-07-04 09:26:24 +00:00
|
|
|
|
|
|
|
return flask.render_template(self.template_name, **self.context)
|
|
|
|
|
|
|
|
|
2022-07-07 11:10:05 +00:00
|
|
|
class PlaceholderLogListView(GenericMixin):
|
|
|
|
template_name = 'inventory/placeholder_log_list.html'
|
|
|
|
|
|
|
|
def dispatch_request(self):
|
|
|
|
self.get_context()
|
|
|
|
self.context['page_title'] = "Placeholder Logs"
|
|
|
|
self.context['placeholders_log'] = self.get_placeholders_log()
|
|
|
|
|
|
|
|
return flask.render_template(self.template_name, **self.context)
|
|
|
|
|
|
|
|
def get_placeholders_log(self):
|
|
|
|
placeholder_log = PlaceholdersLog.query.filter(
|
|
|
|
PlaceholdersLog.owner == g.user
|
|
|
|
).order_by(PlaceholdersLog.created.desc())
|
|
|
|
|
|
|
|
return placeholder_log
|
|
|
|
|
|
|
|
|
2022-01-05 15:00:13 +00:00
|
|
|
devices.add_url_rule('/action/add/', view_func=NewActionView.as_view('action_add'))
|
2022-02-09 13:06:28 +00:00
|
|
|
devices.add_url_rule('/action/trade/add/', view_func=NewTradeView.as_view('trade_add'))
|
2022-02-24 13:15:58 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/action/allocate/add/', view_func=NewAllocateView.as_view('allocate_add')
|
|
|
|
)
|
|
|
|
devices.add_url_rule(
|
|
|
|
'/action/datawipe/add/', view_func=NewDataWipeView.as_view('datawipe_add')
|
|
|
|
)
|
|
|
|
devices.add_url_rule(
|
|
|
|
'/lot/<string:lot_id>/trade-document/add/',
|
|
|
|
view_func=NewTradeDocumentView.as_view('trade_document_add'),
|
|
|
|
)
|
2021-12-29 09:13:34 +00:00
|
|
|
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
|
2022-09-09 09:48:23 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/all/device/', view_func=AllDeviceListView.as_view('alldevicelist')
|
|
|
|
)
|
2022-06-02 11:46:10 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/search/', view_func=AdvancedSearchView.as_view('advanced_search')
|
|
|
|
)
|
2022-02-24 13:15:58 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/device/<string:id>/', view_func=DeviceDetailView.as_view('device_details')
|
|
|
|
)
|
|
|
|
devices.add_url_rule(
|
|
|
|
'/lot/<string:lot_id>/device/', view_func=DeviceListView.as_view('lotdevicelist')
|
|
|
|
)
|
2022-01-12 16:09:20 +00:00
|
|
|
devices.add_url_rule('/lot/add/', view_func=LotCreateView.as_view('lot_add'))
|
2022-02-24 13:15:58 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/lot/<string:id>/del/', view_func=LotDeleteView.as_view('lot_del')
|
|
|
|
)
|
2022-01-12 16:09:20 +00:00
|
|
|
devices.add_url_rule('/lot/<string:id>/', view_func=LotUpdateView.as_view('lot_edit'))
|
2022-02-24 13:15:58 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/upload-snapshot/', view_func=UploadSnapshotView.as_view('upload_snapshot')
|
|
|
|
)
|
2022-03-08 16:43:15 +00:00
|
|
|
devices.add_url_rule(
|
2022-03-08 16:49:56 +00:00
|
|
|
'/lot/<string:lot_id>/upload-snapshot/',
|
|
|
|
view_func=UploadSnapshotView.as_view('lot_upload_snapshot'),
|
2022-03-08 16:43:15 +00:00
|
|
|
)
|
2022-02-02 11:21:30 +00:00
|
|
|
devices.add_url_rule('/device/add/', view_func=DeviceCreateView.as_view('device_add'))
|
2022-03-08 16:43:15 +00:00
|
|
|
devices.add_url_rule(
|
2022-03-08 16:49:56 +00:00
|
|
|
'/lot/<string:lot_id>/device/add/',
|
|
|
|
view_func=DeviceCreateView.as_view('lot_device_add'),
|
2022-03-08 16:43:15 +00:00
|
|
|
)
|
2022-07-05 16:09:47 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/device/edit/<string:id>/', view_func=DeviceEditView.as_view('device_edit')
|
|
|
|
)
|
2022-02-24 13:15:58 +00:00
|
|
|
devices.add_url_rule(
|
2022-08-30 11:10:35 +00:00
|
|
|
'/tag/devices/<string:dhid>/add/',
|
|
|
|
view_func=TagLinkDeviceView.as_view('tag_devices_add'),
|
2022-02-24 13:15:58 +00:00
|
|
|
)
|
|
|
|
devices.add_url_rule(
|
2022-08-30 11:10:35 +00:00
|
|
|
'/tag/devices/<string:dhid>/del/',
|
2022-02-24 13:15:58 +00:00
|
|
|
view_func=TagUnlinkDeviceView.as_view('tag_devices_del'),
|
|
|
|
)
|
|
|
|
devices.add_url_rule(
|
|
|
|
'/export/<string:export_id>/', view_func=ExportsView.as_view('export')
|
|
|
|
)
|
2022-05-11 14:59:36 +00:00
|
|
|
devices.add_url_rule('/snapshots/', view_func=SnapshotListView.as_view('snapshotslist'))
|
2022-05-19 16:16:47 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/snapshots/<string:snapshot_uuid>/',
|
|
|
|
view_func=SnapshotDetailView.as_view('snapshot_detail'),
|
|
|
|
)
|
2022-05-27 14:32:22 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/lot/<string:lot_id>/transfer/<string:type_id>/',
|
|
|
|
view_func=NewTransferView.as_view('new_transfer'),
|
|
|
|
)
|
2022-05-30 14:33:01 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/lot/<string:lot_id>/transfer/',
|
|
|
|
view_func=EditTransferView.as_view('edit_transfer'),
|
|
|
|
)
|
2022-06-03 18:01:13 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/lot/<string:lot_id>/deliverynote/',
|
2022-06-06 11:37:58 +00:00
|
|
|
view_func=DeliveryNoteView.as_view('delivery_note'),
|
2022-06-03 18:01:13 +00:00
|
|
|
)
|
|
|
|
devices.add_url_rule(
|
|
|
|
'/lot/<string:lot_id>/receivernote/',
|
2022-06-06 11:37:58 +00:00
|
|
|
view_func=ReceiverNoteView.as_view('receiver_note'),
|
2022-06-03 18:01:13 +00:00
|
|
|
)
|
2022-07-04 09:26:24 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/upload-placeholder/',
|
|
|
|
view_func=UploadPlaceholderView.as_view('upload_placeholder'),
|
|
|
|
)
|
|
|
|
devices.add_url_rule(
|
|
|
|
'/lot/<string:lot_id>/upload-placeholder/',
|
|
|
|
view_func=UploadPlaceholderView.as_view('lot_upload_placeholder'),
|
|
|
|
)
|
2022-07-07 11:10:05 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/placeholder-logs/', view_func=PlaceholderLogListView.as_view('placeholder_logs')
|
|
|
|
)
|
2022-07-28 15:48:14 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/binding/<string:dhid>/<string:phid>/', view_func=BindingView.as_view('binding')
|
|
|
|
)
|
2022-07-29 15:02:27 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/unbinding/<string:phid>/', view_func=UnBindingView.as_view('unbinding')
|
|
|
|
)
|
2022-08-12 13:59:15 +00:00
|
|
|
devices.add_url_rule(
|
2022-08-12 14:29:51 +00:00
|
|
|
'/device/<string:dhid>/binding/',
|
|
|
|
view_func=BindingSearchView.as_view('binding_search'),
|
2022-08-12 13:59:15 +00:00
|
|
|
)
|
2022-09-20 08:27:02 +00:00
|
|
|
devices.add_url_rule(
|
|
|
|
'/device/erasure/', view_func=ErasureListView.as_view('device_erasure_list')
|
|
|
|
)
|