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
138
Merge Requests
138
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
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
ff55ef9e
Commit
ff55ef9e
authored
Jan 12, 2018
by
Tomáš Peterka
Committed by
Tomáš Peterka
Jan 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[hal_json] Ensure correct style selected when calling dialog method
parent
93aa3c0b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
35 deletions
+85
-35
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_callDialogMethod.py
...portal_skins/erp5_hal_json_style/Base_callDialogMethod.py
+85
-35
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_callDialogMethod.py
View file @
ff55ef9e
...
...
@@ -80,6 +80,25 @@ if dialog_method == 'Folder_delete':
selection_name
=
kw
[
'selection_name'
],
md5_object_uid_list
=
kw
[
'md5_object_uid_list'
])
def
handleFormError
(
form
,
validation_errors
):
"""Return correctly rendered form with all errors assigned to its fields."""
field_errors
=
form
.
ErrorFields
(
validation_errors
)
# Pack errors into the request
request
.
set
(
'field_errors'
,
field_errors
)
# Make sure editors are pushed back as values into the REQUEST object
for
f
in
form
.
get_fields
():
field_id
=
f
.
id
if
request
.
has_key
(
field_id
):
value
=
request
.
get
(
field_id
)
if
callable
(
value
):
value
(
request
)
if
silent_mode
:
return
context
.
ERP5Document_getHateoas
(
form
=
form
,
REQUEST
=
request
,
mode
=
'form'
),
'form'
request
.
RESPONSE
.
setStatus
(
400
)
return
context
.
ERP5Document_getHateoas
(
form
=
form
,
REQUEST
=
request
,
mode
=
'form'
)
form
=
getattr
(
context
,
dialog_id
)
# form can be a python script that returns the form
...
...
@@ -95,26 +114,29 @@ try:
request
.
set
(
'editable_mode'
,
1
)
form
.
validate_all_to_request
(
request
)
request
.
set
(
'editable_mode'
,
editable_mode
)
except
FormValidationError
,
validation_errors
:
# Pack errors into the request
field_errors
=
form
.
ErrorFields
(
validation_errors
)
request
.
set
(
'field_errors'
,
field_errors
)
# Make sure editors are pushed back as values into the REQUEST object
for
f
in
form
.
get_fields
():
field_id
=
f
.
id
if
request
.
has_key
(
field_id
):
value
=
request
.
get
(
field_id
)
if
callable
(
value
):
value
(
request
)
if
silent_mode
:
return
context
.
ERP5Document_getHateoas
(
form
=
form
,
REQUEST
=
request
,
mode
=
'form'
),
'form'
request
.
RESPONSE
.
setStatus
(
400
)
return
context
.
ERP5Document_getHateoas
(
form
=
form
,
REQUEST
=
request
,
mode
=
'form'
)
# Use REQUEST.redirect if possible. It will not be possible if at least one of these is true :
# * we got an import_file,
# * we got a listbox
# * a value is None or [] or (), because this is not supported by make_query
can_redirect
=
1
default_skin
=
context
.
getPortalObject
().
portal_skins
.
getDefaultSkin
()
allowed_styles
=
(
"ODT"
,
"ODS"
,
"Hal"
,
"HalRestricted"
)
if
getattr
(
getattr
(
context
,
dialog_method
),
'pt'
,
None
)
==
"report_view"
and
\
request
.
get
(
'your_portal_skin'
,
default_skin
)
not
in
allowed_styles
:
# RJS own validation - only ODS/ODT and Hal* skins work for reports
# 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
handleFormError
(
form
,
FormValidationError
([
ValidationError
(
error_key
=
None
,
field
=
form
.
get_field
(
'your_portal_skin'
),
error_text
=
translate
(
'Only ODT, ODS, Hal and HalRestricted skins are allowed for reports '
\
'in Preferences - User Interface - Report Style'
))
],
{}))
except
FormValidationError
as
validation_errors
:
return
handleFormError
(
form
,
validation_errors
)
MARKER
=
[]
# A recognisable default value. Use with 'is', not '=='.
listbox_id_list
=
[]
# There should not be more than one listbox - but this give us a way to check.
file_id_list
=
[]
# For uploaded files.
...
...
@@ -189,8 +211,23 @@ if dialog_method != update_method and clean_kw.get('deferred_style', 0):
# XXX Hardcoded Deferred style name
clean_kw
[
'portal_skin'
]
=
'Deferred'
dialog_form
=
getattr
(
context
,
dialog_method
)
page_template
=
getattr
(
dialog_form
,
'pt'
,
None
)
page_template
=
getattr
(
getattr
(
context
,
dialog_method
),
'pt'
,
None
)
if
page_template
==
'report_view'
:
# 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
handleFormError
(
form
,
FormValidationError
([
ValidationError
(
error_key
=
None
,
field
=
form
.
get_field
(
'your_deferred_style'
),
error_text
=
translate
(
'Deferred reports are possible only with preference '
\
'"Report Style" set to "ODT" or "ODS"'
))
],
{}))
# If the action form has report_view as it's method, it
if
page_template
!=
'report_view'
:
# use simple wrapper
...
...
@@ -215,6 +252,7 @@ if True:
request
.
set
(
'portal_skin'
,
new_skin_name
)
deferred_portal_skin
=
clean_kw
.
get
(
'deferred_portal_skin'
)
if
deferred_portal_skin
:
# has to be either ODS or ODT because only those contain `form_list`
request
.
set
(
'deferred_portal_skin'
,
deferred_portal_skin
)
# and to cleanup formulator's special key in request
# XXX unless we are in Folder_modifyWorkflowStatus which validates again !
...
...
@@ -223,15 +261,27 @@ if True:
if
str
(
key
).
startswith
(
'field'
)
or
str
(
key
).
startswith
(
'subfield'
):
request
.
form
.
pop
(
key
,
None
)
# If we cannot redirect, then call the form directly.
# now get dialog_method after skin re-selection and dialog_method mingling
dialog_form
=
getattr
(
context
,
dialog_method
)
# XXX: this is a hack that should not be needed anymore with the new listbox.
# set the URL in request, so that we can immediatly call method
# that depend on it (eg. Show All). This is really related to
# current ListBox implementation which edit Selection's last_url
# with the content of REQUEST.URL
request
.
set
(
'URL'
,
'%s/%s'
%
(
context
.
absolute_url
(),
dialog_method
))
# RJS: If we are in deferred mode - call the form directly and return
# dialog method is now `Base_activateSimpleView` - the only script in
# deferred portal_skins folder
if
clean_kw
.
get
(
'deferred_style'
,
0
):
return
dialog_form
(
**
kw
)
# deferred form should return redirect with a message
# RJS: If skin selection is different than Hal* then ERP5Document_getHateoas
# does not exist and we call form method directly
if
clean_kw
.
get
(
"portal_skin"
,
context
.
getPortalObject
().
portal_skins
.
getDefaultSkin
())
not
in
(
"Hal"
,
"HalRestricted"
):
return
dialog_form
(
**
kw
)
dialog_method
=
getattr
(
context
,
dialog_method
)
return
dialog_method
(
**
clean_kw
)
return
context
.
ERP5Document_getHateoas
(
REQUEST
=
request
,
form
=
dialog_form
,
mode
=
"form"
)
return
getattr
(
context
,
dialog_method
)(
**
kw
)
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