Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
erp5
Commits
7f9f273f
Commit
7f9f273f
authored
1 year ago
by
Titouan Soulard
Committed by
Romain Courteaud
1 month ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_action_information_api: move API content to script
parent
1f3c2fb2
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
40 deletions
+46
-40
bt5/erp5_action_information_api/DocumentTemplateItem/portal_components/document.erp5.ActionInformationAPI.py
...m/portal_components/document.erp5.ActionInformationAPI.py
+11
-36
bt5/erp5_action_information_api/SkinTemplateItem/portal_skins/erp5_action_information_api/ActionInformationAPI_api_slap.py
...5_action_information_api/ActionInformationAPI_api_slap.py
+35
-4
No files found.
bt5/erp5_action_information_api/DocumentTemplateItem/portal_components/document.erp5.ActionInformationAPI.py
View file @
7f9f273f
...
...
@@ -119,49 +119,24 @@ class ActionInformationAPI(XMLObject):
def
handleRequest
(
self
,
request
):
portal
=
self
.
getPortalObject
()
(
hyperdocument
,
actions
)
=
self
.
getTypeInfo
().
getDefaultViewFor
(
self
,
view
=
self
.
getApiTypeReference
())(
self
,
portal
,
request
)
response
=
request
.
RESPONSE
view_ref
=
self
.
getApiTypeReference
()
request_content_type
=
request
.
getHeader
(
"content-type"
)
if
view_ref
is
None
:
raise
NotImplementedError
(
"Cannot find matching view"
)
if
request_content_type
and
request_content_type
!=
"application/json"
:
raise
NotImplementedError
(
"Cannot serve Content-Type {}"
.
format
(
request_content_type
))
response
.
setHeader
(
"Content-Type"
,
"application/json"
)
if
request
.
get
(
"method"
).
lower
()
!=
"post"
:
return
hyperdocument
request_json
=
request
.
get
(
"BODY"
)
if
not
request_json
:
return
hyperdocument
request_body
=
json
.
loads
(
request_json
)
request_schema
=
request_body
.
get
(
"$schemaDocument"
)
request_object_ref
=
request_body
.
get
(
"reference"
)
if
not
request_schema
or
not
request_object_ref
:
return
hyperdocument
found_action
=
""
for
schema_url
in
actions
:
if
schema_url
in
request_schema
:
found_action
=
actions
[
schema_url
]
break
if
not
found_action
:
raise
NotFound
(
"Schema {} unavailable"
.
format
(
request_schema
))
portal_type
=
found_action
.
getParentValue
().
getId
()
request_object
=
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
portal_type
,
id
=
request_object_ref
)
if
not
request_object
:
raise
NotFound
(
"Object {} not found"
.
format
(
request_object_ref
))
action_output
=
request_object
.
getTypeInfo
().
getDefaultViewFor
(
request_object
,
view
=
found_action
.
getProperty
(
"reference"
))(
request_body
)
action_output
[
"status"
]
=
200
return
json
.
dumps
(
action_output
,
indent
=
2
).
encode
()
request
.
RESPONSE
.
setHeader
(
"Content-Type"
,
"application/json"
)
raw_reponse
=
self
.
getTypeInfo
().
getDefaultViewFor
(
self
,
view
=
view_ref
)(
self
,
portal
,
request
)
return
json
.
dumps
(
raw_reponse
,
indent
=
2
).
encode
()
def
publishTraverse
(
self
,
request
,
name
):
if
request
.
method
.
upper
()
in
(
'PUT'
,
'DELETE'
):
# PUT and DELETE methods, because they are handled as WebDAV before custom hooks are called
return
ActionInformationAPIPublisher
(
self
,
request
)
adapter
=
DefaultPublishTraverse
(
self
,
request
)
try
:
obj
=
adapter
.
publishTraverse
(
request
,
name
)
...
...
This diff is collapsed.
Click to expand it.
bt5/erp5_action_information_api/SkinTemplateItem/portal_skins/erp5_action_information_api/ActionInformationAPI_api_slap.py
View file @
7f9f273f
import
json
from
zExceptions
import
NotFound
url
=
request
.
getURL
()
base_url_absolute
=
portal
.
portal_callables
.
absolute_url
().
strip
()
...
...
@@ -11,7 +12,7 @@ raw_action_list = portal.portal_catalog(
)
links
=
[]
action
_dict
=
{}
action
s
=
{}
for
item
in
raw_action_list
:
# XXX: for now, expects reference to be the same as action URL
...
...
@@ -24,8 +25,38 @@ for item in raw_action_list:
"url"
:
url
})
action
_dict
[
base_url_relative
+
action_url
+
"/getInputJSONSchema"
]
=
item
action
s
[
base_url_relative
+
action_url
+
"/getInputJSONSchema"
]
=
item
hyperdocument
=
json
.
dumps
({
"links"
:
links
},
indent
=
2
).
encode
()
hyperdocument
=
{
"links"
:
links
}
return
(
hyperdocument
,
action_dict
)
if
request
.
get
(
"method"
).
lower
()
!=
"post"
:
return
hyperdocument
request_json
=
request
.
get
(
"BODY"
)
if
not
request_json
:
return
hyperdocument
request_body
=
json
.
loads
(
request_json
)
request_schema
=
request_body
.
get
(
"$schemaDocument"
)
request_object_ref
=
request_body
.
get
(
"reference"
)
if
not
request_schema
or
not
request_object_ref
:
return
hyperdocument
found_action
=
""
for
schema_url
in
actions
:
if
schema_url
in
request_schema
:
found_action
=
actions
[
schema_url
]
break
if
not
found_action
:
raise
NotFound
(
"Schema {} unavailable"
.
format
(
request_schema
))
portal_type
=
found_action
.
getParentValue
().
getId
()
request_object
=
portal
.
portal_catalog
.
getResultValue
(
portal_type
=
portal_type
,
id
=
request_object_ref
)
if
not
request_object
:
raise
NotFound
(
"Object {} not found"
.
format
(
request_object_ref
))
action_output
=
request_object
.
getTypeInfo
().
getDefaultViewFor
(
request_object
,
view
=
found_action
.
getProperty
(
"reference"
))(
request_body
)
action_output
[
"status"
]
=
200
return
action_output
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment