mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
#I9QR3B app_auto_backup增加从界面下载删除备份库的功能 V17.0
This commit is contained in:
30
app_auto_backup/controllers/main.py
Normal file
30
app_auto_backup/controllers/main.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from odoo import http, _
|
||||
from odoo.http import request, content_disposition
|
||||
from odoo.exceptions import AccessError, UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AppAutoBackup(http.Controller):
|
||||
|
||||
@http.route("/download/backupfile/<path:file_path>", type="http", auth="user")
|
||||
def download_backupfile(self, file_path, **kw):
|
||||
if os.path.exists(file_path):
|
||||
try:
|
||||
with open(file_path, 'rb') as file:
|
||||
file_content = file.read()
|
||||
file_name = file_path.split("/")[-1]
|
||||
headers = [
|
||||
('Content-Type', 'application/octet-stream'),
|
||||
('Content-Disposition', content_disposition(file_name)),
|
||||
]
|
||||
return request.make_response(file_content, headers)
|
||||
except Exception as e:
|
||||
raise UserError(e)
|
||||
else:
|
||||
return 'File not found'
|
||||
Reference in New Issue
Block a user