remove report of devicehub commands
This commit is contained in:
parent
eae036d7c0
commit
6c7ae1bb75
|
@ -15,6 +15,7 @@ from teal.teal import Teal
|
||||||
|
|
||||||
from ereuse_devicehub.auth import Auth
|
from ereuse_devicehub.auth import Auth
|
||||||
from ereuse_devicehub.client import Client, UserClient
|
from ereuse_devicehub.client import Client, UserClient
|
||||||
|
|
||||||
# from ereuse_devicehub.commands.reports import Report
|
# from ereuse_devicehub.commands.reports import Report
|
||||||
from ereuse_devicehub.commands.users import GetToken
|
from ereuse_devicehub.commands.users import GetToken
|
||||||
from ereuse_devicehub.config import DevicehubConfig
|
from ereuse_devicehub.config import DevicehubConfig
|
||||||
|
|
|
@ -61,9 +61,9 @@ class DocumentView(DeviceView):
|
||||||
200:
|
200:
|
||||||
description: Return the collection or the specific one.
|
description: Return the collection or the specific one.
|
||||||
"""
|
"""
|
||||||
args = self.QUERY_PARSER.parse(self.find_args,
|
args = self.QUERY_PARSER.parse(
|
||||||
flask.request,
|
self.find_args, flask.request, locations=('querystring',)
|
||||||
locations=('querystring',))
|
)
|
||||||
ids = []
|
ids = []
|
||||||
if 'filter' in request.args:
|
if 'filter' in request.args:
|
||||||
filters = json.loads(request.args.get('filter', {}))
|
filters = json.loads(request.args.get('filter', {}))
|
||||||
|
@ -112,7 +112,8 @@ class DocumentView(DeviceView):
|
||||||
template = self.erasure(query)
|
template = self.erasure(query)
|
||||||
if args.get('format') == Format.PDF:
|
if args.get('format') == Format.PDF:
|
||||||
res = flask_weasyprint.render_pdf(
|
res = flask_weasyprint.render_pdf(
|
||||||
flask_weasyprint.HTML(string=template), download_filename='{}.pdf'.format(type)
|
flask_weasyprint.HTML(string=template),
|
||||||
|
download_filename='{}.pdf'.format(type),
|
||||||
)
|
)
|
||||||
insert_hash(res.data)
|
insert_hash(res.data)
|
||||||
else:
|
else:
|
||||||
|
@ -139,7 +140,7 @@ class DocumentView(DeviceView):
|
||||||
params = {
|
params = {
|
||||||
'title': 'Erasure Certificate',
|
'title': 'Erasure Certificate',
|
||||||
'erasures': tuple(erasures()),
|
'erasures': tuple(erasures()),
|
||||||
'url_pdf': url_pdf.to_text()
|
'url_pdf': url_pdf.to_text(),
|
||||||
}
|
}
|
||||||
return flask.render_template('documents/erasure.html', **params)
|
return flask.render_template('documents/erasure.html', **params)
|
||||||
|
|
||||||
|
@ -158,7 +159,13 @@ class DevicesDocumentView(DeviceView):
|
||||||
def generate_post_csv(self, query):
|
def generate_post_csv(self, query):
|
||||||
"""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
|
||||||
document_ids = self.get_documents_id()
|
document_ids = self.get_documents_id()
|
||||||
for device in query:
|
for device in query:
|
||||||
|
@ -192,7 +199,13 @@ class ActionsDocumentView(DeviceView):
|
||||||
def generate_post_csv(self, query):
|
def generate_post_csv(self, query):
|
||||||
"""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 = []
|
||||||
for device in query:
|
for device in query:
|
||||||
|
@ -203,7 +216,9 @@ class ActionsDocumentView(DeviceView):
|
||||||
cw.writerow(d.keys())
|
cw.writerow(d.keys())
|
||||||
first = False
|
first = False
|
||||||
cw.writerow(d.values())
|
cw.writerow(d.values())
|
||||||
query_trade = Trade.query.filter(Trade.devices.any(Device.id.in_(devs_id))).all()
|
query_trade = Trade.query.filter(
|
||||||
|
Trade.devices.any(Device.id.in_(devs_id))
|
||||||
|
).all()
|
||||||
|
|
||||||
lot_id = request.args.get('lot')
|
lot_id = request.args.get('lot')
|
||||||
if lot_id and not query_trade:
|
if lot_id and not query_trade:
|
||||||
|
@ -224,7 +239,9 @@ class ActionsDocumentView(DeviceView):
|
||||||
bfile = data.getvalue().encode('utf-8')
|
bfile = data.getvalue().encode('utf-8')
|
||||||
output = make_response(bfile)
|
output = make_response(bfile)
|
||||||
insert_hash(bfile)
|
insert_hash(bfile)
|
||||||
output.headers['Content-Disposition'] = 'attachment; filename=actions_export.csv'
|
output.headers[
|
||||||
|
'Content-Disposition'
|
||||||
|
] = 'attachment; filename=actions_export.csv'
|
||||||
output.headers['Content-type'] = 'text/csv'
|
output.headers['Content-type'] = 'text/csv'
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
@ -276,7 +293,13 @@ class StockDocumentView(DeviceView):
|
||||||
def generate_post_csv(self, query):
|
def generate_post_csv(self, query):
|
||||||
"""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 query:
|
for device in query:
|
||||||
d = StockRow(device)
|
d = StockRow(device)
|
||||||
|
@ -310,6 +333,7 @@ class StampsView(View):
|
||||||
This view render one public ans static page for see the links for to do the check
|
This view render one public ans static page for see the links for to do the check
|
||||||
of one csv file
|
of one csv file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_url_path(self):
|
def get_url_path(self):
|
||||||
url = urlutils.URL(request.url)
|
url = urlutils.URL(request.url)
|
||||||
url.normalize()
|
url.normalize()
|
||||||
|
@ -318,8 +342,9 @@ class StampsView(View):
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
result = ('', '')
|
result = ('', '')
|
||||||
return flask.render_template('documents/stamp.html', rq_url=self.get_url_path(),
|
return flask.render_template(
|
||||||
result=result)
|
'documents/stamp.html', rq_url=self.get_url_path(), result=result
|
||||||
|
)
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
result = ('', '')
|
result = ('', '')
|
||||||
|
@ -330,18 +355,26 @@ class StampsView(View):
|
||||||
ok = '100% coincidence. The attached file contains data 100% existing in \
|
ok = '100% coincidence. The attached file contains data 100% existing in \
|
||||||
to our backend'
|
to our backend'
|
||||||
result = ('Bad', bad)
|
result = ('Bad', bad)
|
||||||
mime = ['text/csv', 'application/pdf', 'text/plain', 'text/markdown',
|
mime = [
|
||||||
'image/jpeg', 'image/png', 'text/html',
|
'text/csv',
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
'application/pdf',
|
||||||
'application/vnd.oasis.opendocument.spreadsheet',
|
'text/plain',
|
||||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
'text/markdown',
|
||||||
'application/msword']
|
'image/jpeg',
|
||||||
|
'image/png',
|
||||||
|
'text/html',
|
||||||
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||||
|
'application/vnd.oasis.opendocument.spreadsheet',
|
||||||
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||||
|
'application/msword',
|
||||||
|
]
|
||||||
if file_check.mimetype in mime:
|
if file_check.mimetype in mime:
|
||||||
if verify_hash(file_check):
|
if verify_hash(file_check):
|
||||||
result = ('Ok', ok)
|
result = ('Ok', ok)
|
||||||
|
|
||||||
return flask.render_template('documents/stamp.html', rq_url=self.get_url_path(),
|
return flask.render_template(
|
||||||
result=result)
|
'documents/stamp.html', rq_url=self.get_url_path(), result=result
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class WbConfDocumentView(DeviceView):
|
class WbConfDocumentView(DeviceView):
|
||||||
|
@ -349,10 +382,11 @@ class WbConfDocumentView(DeviceView):
|
||||||
if not wbtype.lower() in ['usodyrate', 'usodywipe']:
|
if not wbtype.lower() in ['usodyrate', 'usodywipe']:
|
||||||
return jsonify('')
|
return jsonify('')
|
||||||
|
|
||||||
data = {'token': self.get_token(),
|
data = {
|
||||||
'host': app.config['HOST'],
|
'token': self.get_token(),
|
||||||
'inventory': app.config['SCHEMA']
|
'host': app.config['HOST'],
|
||||||
}
|
'inventory': app.config['SCHEMA'],
|
||||||
|
}
|
||||||
data['erase'] = False
|
data['erase'] = False
|
||||||
# data['erase'] = True if wbtype == 'usodywipe' else False
|
# data['erase'] = True if wbtype == 'usodywipe' else False
|
||||||
|
|
||||||
|
@ -387,18 +421,31 @@ class DocumentDef(Resource):
|
||||||
VIEW = None # We do not want to create default / documents endpoint
|
VIEW = None # We do not want to create default / documents endpoint
|
||||||
AUTH = False
|
AUTH = False
|
||||||
|
|
||||||
def __init__(self, app,
|
def __init__(
|
||||||
import_name=__name__,
|
self,
|
||||||
static_folder='static',
|
app,
|
||||||
static_url_path=None,
|
import_name=__name__,
|
||||||
template_folder='templates',
|
static_folder='static',
|
||||||
url_prefix=None,
|
static_url_path=None,
|
||||||
subdomain=None,
|
template_folder='templates',
|
||||||
url_defaults=None,
|
url_prefix=None,
|
||||||
root_path=None,
|
subdomain=None,
|
||||||
cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()):
|
url_defaults=None,
|
||||||
super().__init__(app, import_name, static_folder, static_url_path, template_folder,
|
root_path=None,
|
||||||
url_prefix, subdomain, url_defaults, root_path, cli_commands)
|
cli_commands: Iterable[Tuple[Callable, str or None]] = tuple(),
|
||||||
|
):
|
||||||
|
super().__init__(
|
||||||
|
app,
|
||||||
|
import_name,
|
||||||
|
static_folder,
|
||||||
|
static_url_path,
|
||||||
|
template_folder,
|
||||||
|
url_prefix,
|
||||||
|
subdomain,
|
||||||
|
url_defaults,
|
||||||
|
root_path,
|
||||||
|
cli_commands,
|
||||||
|
)
|
||||||
d = {'id': None}
|
d = {'id': None}
|
||||||
get = {'GET'}
|
get = {'GET'}
|
||||||
|
|
||||||
|
@ -409,12 +456,15 @@ class DocumentDef(Resource):
|
||||||
view = app.auth.requires_auth(view)
|
view = app.auth.requires_auth(view)
|
||||||
|
|
||||||
self.add_url_rule('/erasures/', defaults=d, view_func=view, methods=get)
|
self.add_url_rule('/erasures/', defaults=d, view_func=view, methods=get)
|
||||||
self.add_url_rule('/erasures/<{}:{}>'.format(self.ID_CONVERTER.value, self.ID_NAME),
|
self.add_url_rule(
|
||||||
view_func=view, methods=get)
|
'/erasures/<{}:{}>'.format(self.ID_CONVERTER.value, self.ID_NAME),
|
||||||
|
view_func=view,
|
||||||
|
methods=get,
|
||||||
|
)
|
||||||
|
|
||||||
devices_view = DevicesDocumentView.as_view('devicesDocumentView',
|
devices_view = DevicesDocumentView.as_view(
|
||||||
definition=self,
|
'devicesDocumentView', definition=self, auth=app.auth
|
||||||
auth=app.auth)
|
)
|
||||||
devices_view = app.auth.requires_auth(devices_view)
|
devices_view = app.auth.requires_auth(devices_view)
|
||||||
|
|
||||||
stock_view = StockDocumentView.as_view('stockDocumentView', definition=self)
|
stock_view = StockDocumentView.as_view('stockDocumentView', definition=self)
|
||||||
|
@ -426,7 +476,9 @@ class DocumentDef(Resource):
|
||||||
lots_view = app.auth.requires_auth(lots_view)
|
lots_view = app.auth.requires_auth(lots_view)
|
||||||
self.add_url_rule('/lots/', defaults=d, view_func=lots_view, methods=get)
|
self.add_url_rule('/lots/', defaults=d, view_func=lots_view, methods=get)
|
||||||
|
|
||||||
stock_view = StockDocumentView.as_view('stockDocumentView', definition=self, auth=app.auth)
|
stock_view = StockDocumentView.as_view(
|
||||||
|
'stockDocumentView', definition=self, auth=app.auth
|
||||||
|
)
|
||||||
stock_view = app.auth.requires_auth(stock_view)
|
stock_view = app.auth.requires_auth(stock_view)
|
||||||
self.add_url_rule('/stock/', defaults=d, view_func=stock_view, methods=get)
|
self.add_url_rule('/stock/', defaults=d, view_func=stock_view, methods=get)
|
||||||
|
|
||||||
|
@ -434,16 +486,18 @@ class DocumentDef(Resource):
|
||||||
self.add_url_rule('/check/', defaults={}, view_func=check_view, methods=get)
|
self.add_url_rule('/check/', defaults={}, view_func=check_view, methods=get)
|
||||||
|
|
||||||
stamps_view = StampsView.as_view('StampsView', definition=self, auth=app.auth)
|
stamps_view = StampsView.as_view('StampsView', definition=self, auth=app.auth)
|
||||||
self.add_url_rule('/stamps/', defaults={}, view_func=stamps_view, methods={'GET', 'POST'})
|
self.add_url_rule(
|
||||||
|
'/stamps/', defaults={}, view_func=stamps_view, methods={'GET', 'POST'}
|
||||||
|
)
|
||||||
|
|
||||||
actions_view = ActionsDocumentView.as_view('ActionsDocumentView',
|
actions_view = ActionsDocumentView.as_view(
|
||||||
definition=self,
|
'ActionsDocumentView', definition=self, auth=app.auth
|
||||||
auth=app.auth)
|
)
|
||||||
actions_view = app.auth.requires_auth(actions_view)
|
actions_view = app.auth.requires_auth(actions_view)
|
||||||
self.add_url_rule('/actions/', defaults=d, view_func=actions_view, methods=get)
|
self.add_url_rule('/actions/', defaults=d, view_func=actions_view, methods=get)
|
||||||
|
|
||||||
wbconf_view = WbConfDocumentView.as_view('WbConfDocumentView',
|
wbconf_view = WbConfDocumentView.as_view(
|
||||||
definition=self,
|
'WbConfDocumentView', definition=self, auth=app.auth
|
||||||
auth=app.auth)
|
)
|
||||||
wbconf_view = app.auth.requires_auth(wbconf_view)
|
wbconf_view = app.auth.requires_auth(wbconf_view)
|
||||||
self.add_url_rule('/wbconf/<string:wbtype>', view_func=wbconf_view, methods=get)
|
self.add_url_rule('/wbconf/<string:wbtype>', view_func=wbconf_view, methods=get)
|
||||||
|
|
Reference in New Issue