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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Matevz Golob
erp5
Commits
5004e51c
Commit
5004e51c
authored
Feb 27, 2018
by
Tomáš Peterka
Committed by
Tomáš Peterka
Feb 28, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[hal_json] Replace Base_returnFailureWithMessage with more generic Base_renderMessage
/reviewed-on
nexedi/erp5!598
parent
2f1f2953
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
11 deletions
+43
-11
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_callDialogMethod.py
...portal_skins/erp5_hal_json_style/Base_callDialogMethod.py
+7
-4
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_renderMessage.py
...em/portal_skins/erp5_hal_json_style/Base_renderMessage.py
+30
-0
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_renderMessage.xml
...m/portal_skins/erp5_hal_json_style/Base_renderMessage.xml
+2
-2
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Workflow_statusModify.py
...portal_skins/erp5_hal_json_style/Workflow_statusModify.py
+4
-5
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_callDialogMethod.py
View file @
5004e51c
...
...
@@ -15,6 +15,7 @@ def isFieldType(field, type_name):
from
Products.Formulator.Errors
import
FormValidationError
,
ValidationError
from
ZTUtils
import
make_query
# Kato: I do not understand why we throw away REQUEST from parameters (hidden in **kw)
# and use container.REQUEST just to introduce yet another global state. Maybe because
# container.REQUEST is used in other places.
...
...
@@ -98,9 +99,10 @@ try:
# Form is OK, it's just this field - style so we return back form-wide error
# for which we don't have support out-of-the-box thus we manually craft it
# XXX TODO: Form-wide validation errors
return
context
.
Base_returnFailureWith
Message
(
return
Base_render
Message
(
translate
(
'Only ODT, ODS, Hal and HalRestricted skins are allowed for reports '
\
'in Preferences - User Interface - Report Style'
))
'in Preferences - User Interface - Report Style'
),
level
=
WARNING
)
except
FormValidationError
as
validation_errors
:
# Pack errors into the request
...
...
@@ -198,9 +200,10 @@ if dialog_method != update_method and clean_kw.get('deferred_style', 0):
# Limit Reports in Deferred style to known working styles
if
request_form
.
get
(
'your_portal_skin'
,
None
)
not
in
(
"ODT"
,
"ODS"
):
# RJS own validation - deferred option works here only with ODS/ODT skins
return
Base_re
turnFailureWith
Message
(
return
Base_re
nder
Message
(
translate
(
'Deferred reports are possible only with preference '
\
'"Report Style" set to "ODT" or "ODS"'
))
'"Report Style" set to "ODT" or "ODS"'
),
level
=
WARNING
)
# If the action form has report_view as it's method, it
if
page_template
!=
'report_view'
:
...
...
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_re
turnFailureWith
Message.py
→
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_re
nder
Message.py
View file @
5004e51c
"""
Script to return json for response header while displying failure
Return JSON with message to be displayed and set according HTTP STATUS for message severity.
:param message: {str}
:param level: {str | int} use ERP5Type.Log levels or simply strings like "info", "warning", or "error"
"""
import
json
from
Products.ERP5Type.Log
import
WARNING
,
ERROR
if
isinstance
(
level
,
(
str
,
unicode
)):
if
level
.
lower
()
==
"error"
:
response_code
=
500
elif
level
.
lower
().
startswith
(
"warn"
):
response_code
=
403
else
:
response_code
=
200
else
:
if
level
==
ERROR
:
response_code
=
500
elif
level
==
WARNING
:
response_code
=
403
else
:
response_code
=
200
response
=
request
.
RESPONSE
if
request
is
not
None
else
context
.
REQUEST
.
RESPONSE
# Set the response code and header info in the response
response
.
setStatus
(
int
(
response_code
)
)
response
.
setStatus
(
response_code
)
response
.
setHeader
(
"Content-type"
,
"application/json; charset=utf-8"
)
return
json
.
dumps
({
"portal_status_message"
:
str
(
message
)})
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_re
turnFailureWith
Message.xml
→
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_re
nder
Message.xml
View file @
5004e51c
...
...
@@ -50,11 +50,11 @@
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
message,
response_code=500
, request=None
</string>
</value>
<value>
<string>
message,
level="error"
, request=None
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
Base_re
turnFailureWith
Message
</string>
</value>
<value>
<string>
Base_re
nder
Message
</string>
</value>
</item>
</dictionary>
</pickle>
...
...
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Workflow_statusModify.py
View file @
5004e51c
...
...
@@ -2,7 +2,8 @@ from Products.CMFCore.WorkflowCore import WorkflowException
from
Products.Formulator.Errors
import
FormValidationError
from
Products.DCWorkflow.DCWorkflow
import
ValidationFailed
from
Products.ERP5Type.Message
import
translateString
from
Products.ERP5Type.Log
import
log
from
Products.ERP5Type.Log
import
log
,
WARNING
portal
=
context
.
getPortalObject
()
request
=
kw
.
get
(
"REQUEST"
,
None
)
or
context
.
REQUEST
...
...
@@ -69,7 +70,6 @@ try:
doaction_param_list
[
'workflow_action'
],
**
doaction_param_list
)
except
ValidationFailed
,
error_message
:
response_code
=
403
if
getattr
(
error_message
,
'msg'
,
None
):
# use of Message class to store message+mapping+domain
message
=
error_message
.
msg
...
...
@@ -79,12 +79,11 @@ except ValidationFailed, error_message:
message
=
str
(
message
)
else
:
message
=
str
(
error_message
)
return
context
.
Base_re
turnFailureWithMessage
(
message
,
response_code
,
request
)
return
context
.
Base_re
nderMessage
(
message
,
WARNING
,
request
)
except
WorkflowException
as
error_message
:
response_code
=
403
if
str
(
error_message
)
==
"No workflow provides the '${action_id}' action."
:
message
=
translateString
(
"Workflow state may have been updated by other user. Please try again."
)
return
context
.
Base_re
turnFailureWithMessage
(
message
,
response_code
,
request
)
return
context
.
Base_re
nderMessage
(
message
,
WARNING
,
request
)
else
:
raise
else
:
...
...
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