mirror of
https://gitlab.com/sonalarora/tra_backend.git
synced 2025-12-17 18:29:08 +02:00
add dashboar module
This commit is contained in:
66
ks_dashboard_ninja/controllers/ks_dashboard_export.py
Normal file
66
ks_dashboard_ninja/controllers/ks_dashboard_export.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import io
|
||||
import json
|
||||
import operator
|
||||
|
||||
from odoo.addons.web.controllers.main import ExportFormat,serialize_exception
|
||||
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
from odoo.http import content_disposition,request
|
||||
|
||||
|
||||
class KsDashboardExport(ExportFormat, http.Controller):
|
||||
|
||||
def base(self, data, token):
|
||||
params = json.loads(data)
|
||||
header, dashboard_data = operator.itemgetter('header', 'dashboard_data')(params)
|
||||
return request.make_response(self.from_data(dashboard_data),
|
||||
headers=[('Content-Disposition',
|
||||
content_disposition(self.filename(header))),
|
||||
('Content-Type', self.content_type)],
|
||||
cookies={'fileToken': token})
|
||||
|
||||
|
||||
class KsDashboardJsonExport(KsDashboardExport, http.Controller):
|
||||
|
||||
@http.route('/ks_dashboard_ninja/export/dashboard_json', type='http', auth="user")
|
||||
@serialize_exception
|
||||
def index(self, data, token):
|
||||
return self.base(data, token)
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
return 'text/csv;charset=utf8'
|
||||
|
||||
def filename(self, base):
|
||||
return base + '.json'
|
||||
|
||||
def from_data(self, dashboard_data):
|
||||
fp = io.StringIO()
|
||||
fp.write(json.dumps(dashboard_data))
|
||||
|
||||
return fp.getvalue()
|
||||
|
||||
class KsItemJsonExport(KsDashboardExport, http.Controller):
|
||||
|
||||
@http.route('/ks_dashboard_ninja/export/item_json', type='http', auth="user")
|
||||
@serialize_exception
|
||||
def index(self, data, token):
|
||||
data = json.loads(data)
|
||||
item_id = data["item_id"]
|
||||
data['dashboard_data'] = request.env['ks_dashboard_ninja.board'].ks_export_item(item_id)
|
||||
data = json.dumps(data)
|
||||
return self.base(data, token)
|
||||
|
||||
@property
|
||||
def content_type(self):
|
||||
return 'text/csv;charset=utf8'
|
||||
|
||||
def filename(self, base):
|
||||
return base + '.json'
|
||||
|
||||
def from_data(self, dashboard_data):
|
||||
fp = io.StringIO()
|
||||
fp.write(json.dumps(dashboard_data))
|
||||
|
||||
return fp.getvalue()
|
||||
Reference in New Issue
Block a user