-
-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathfs_folder_controller.py
More file actions
167 lines (152 loc) · 5.25 KB
/
Copy pathfs_folder_controller.py
File metadata and controls
167 lines (152 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
import os
from werkzeug.exceptions import NotFound
from odoo import http
from odoo.http import request
from odoo.tools import str2bool
_logger = logging.getLogger(__name__)
class FsFolderController(http.Controller):
@http.route(
"/fs_folder/get_file/<string:res_model>/<int:res_id>/<string:field_name>",
type="http",
auth="user",
methods=["GET"],
)
def get_file(self, res_id, res_model, field_name, path, download=False, **kwargs):
download = str2bool(download)
response = request.env["fs.folder.field.web.api"]._get_http_stream_response(
res_id, res_model, field_name, path, download, **kwargs
)
if not response:
raise NotFound()
return response
@http.route(
"/fs_folder/get_children/<string:res_model>/<int:res_id>/<string:field_name>",
type="jsonrpc",
auth="user",
methods=["POST"],
)
def get_children(self, res_id, res_model, field_name, path=""):
result = request.env["fs.folder.field.web.api"].get_children(
res_id, res_model, field_name, path
)
if not path:
return result
return [{**item, "name": item["name"][len(path) + 1 :]} for item in result]
@http.route(
"/fs_folder/add_folder/<string:res_model>/<int:res_id>/<string:field_name>",
type="jsonrpc",
auth="user",
methods=["POST"],
)
def add_folder(self, res_id, res_model, field_name, path, name):
request.env["fs.folder.field.web.api"].create_folder(
res_id, res_model, field_name, os.path.join(path, name)
)
@http.route(
"/fs_folder/delete/<string:res_model>/<int:res_id>/<string:field_name>",
type="jsonrpc",
auth="user",
methods=["POST"],
)
def delete(self, res_id, res_model, field_name, path, name):
request.env["fs.folder.field.web.api"].delete(
res_id, res_model, field_name, os.path.join(path, name), recursive=True
)
@http.route(
"/fs_folder/move/<string:res_model>/<int:res_id>/<string:field_name>",
type="jsonrpc",
auth="user",
methods=["POST"],
)
def move_file(self, res_id, res_model, field_name, path, origin_path, record):
if path == origin_path:
return
return request.env["fs.folder.field.web.api"].rename(
res_id,
res_model,
field_name,
os.path.join(origin_path, record),
os.path.join(path, record),
recursive=True,
)
@http.route(
"/fs_folder/copy/<string:res_model>/<int:res_id>/<string:field_name>",
type="jsonrpc",
auth="user",
methods=["POST"],
)
def copy_file(self, res_id, res_model, field_name, path, origin_path, record):
if path == origin_path:
return
return request.env["fs.folder.field.web.api"].copy_item(
res_id,
res_model,
field_name,
os.path.join(origin_path, record),
os.path.join(path, record),
recursive=True,
)
@http.route(
"/fs_folder/rename/<string:res_model>/<int:res_id>/<string:field_name>",
type="jsonrpc",
auth="user",
methods=["POST"],
)
def rename(self, res_id, res_model, field_name, path, name, new_name):
request.env["fs.folder.field.web.api"].rename(
res_id,
res_model,
field_name,
os.path.join(path, name),
os.path.join(path, new_name),
)
@http.route(
"/fs_folder/upload/<string:res_model>/<int:res_id>/<string:field_name>",
type="jsonrpc",
auth="user",
methods=["POST"],
)
def upload(self, res_id, res_model, field_name, path, name, data):
request.env["fs.folder.field.web.api"].upload_file(
res_id,
res_model,
field_name,
path,
name,
data,
)
@http.route(
"/fs_folder/initialize/<string:res_model>/<int:res_id>/<string:field_name>",
type="jsonrpc",
auth="user",
methods=["POST"],
)
def initialize(self, res_id, res_model, field_name):
request.env["fs.folder.field.web.api"].initialize_field_value(
res_id, res_model, field_name
)
@http.route(
"/fs_folder/unlink_folder/<string:res_model>/<int:res_id>/<string:field_name>",
type="jsonrpc",
auth="user",
methods=["POST"],
)
def unlink_folder(self, res_id, res_model, field_name):
request.env["fs.folder.field.web.api"].remove_field_value(
res_id, res_model, field_name
)
@http.route(
"/fs_folder/delete_folder/<string:res_model>/<int:res_id>/<string:field_name>",
type="jsonrpc",
auth="user",
methods=["POST"],
)
def delete_folder(self, res_id, res_model, field_name):
request.env["fs.folder.field.web.api"].delete(
res_id, res_model, field_name, "/", recursive=True
)
request.env["fs.folder.field.web.api"].remove_field_value(
res_id, res_model, field_name
)