document stock
This commit is contained in:
parent
1b79f76e27
commit
114613ddf7
|
@ -126,6 +126,29 @@ class DevicesDocumentView(DeviceView):
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
class StockDocumentView(DeviceView):
|
||||||
|
# @cache(datetime.timedelta(minutes=1))
|
||||||
|
def find(self, args: dict):
|
||||||
|
query = self.query(args)
|
||||||
|
return self.generate_post_csv(query)
|
||||||
|
|
||||||
|
def generate_post_csv(self, query):
|
||||||
|
"""Get device query and put information in csv format."""
|
||||||
|
data = StringIO()
|
||||||
|
cw = csv.writer(data)
|
||||||
|
first = True
|
||||||
|
for device in query:
|
||||||
|
d = DeviceRow(device)
|
||||||
|
if first:
|
||||||
|
cw.writerow(d.keys())
|
||||||
|
first = False
|
||||||
|
cw.writerow(d.values())
|
||||||
|
output = make_response(data.getvalue())
|
||||||
|
output.headers['Content-Disposition'] = 'attachment; filename=export.csv'
|
||||||
|
output.headers['Content-type'] = 'text/csv'
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
class DocumentDef(Resource):
|
class DocumentDef(Resource):
|
||||||
__type__ = 'Document'
|
__type__ = 'Document'
|
||||||
SCHEMA = None
|
SCHEMA = None
|
||||||
|
@ -156,6 +179,10 @@ class DocumentDef(Resource):
|
||||||
devices_view = DevicesDocumentView.as_view('devicesDocumentView',
|
devices_view = DevicesDocumentView.as_view('devicesDocumentView',
|
||||||
definition=self,
|
definition=self,
|
||||||
auth=app.auth)
|
auth=app.auth)
|
||||||
|
|
||||||
|
stock_view = StockDocumentView.as_view('stockDocumentView', definition=self)
|
||||||
|
|
||||||
if self.AUTH:
|
if self.AUTH:
|
||||||
devices_view = app.auth.requires_auth(devices_view)
|
devices_view = app.auth.requires_auth(devices_view)
|
||||||
self.add_url_rule('/devices/', defaults=d, view_func=devices_view, methods=get)
|
self.add_url_rule('/devices/', defaults=d, view_func=devices_view, methods=get)
|
||||||
|
self.add_url_rule('/stock/', defaults=d, view_func=stock_view, methods=get)
|
||||||
|
|
Reference in New Issue