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
d4b63a3d
Commit
d4b63a3d
authored
Dec 29, 2017
by
Tomáš Peterka
Committed by
Tomáš Peterka
Jan 08, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[hal_json] Pass correct request to form fields for value resolution
parent
777c5e6c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
+15
-8
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
...rtal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
+15
-8
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
View file @
d4b63a3d
...
...
@@ -309,9 +309,11 @@ url_template_dict = {
default_document_uri_template
=
url_template_dict
[
"jio_get_template"
]
Base_translateString
=
context
.
getPortalObject
().
Base_translateString
def
getRealRelativeUrl
(
document
):
return
'/'
.
join
(
portal
.
portal_url
.
getRelativeContentPath
(
document
))
def
getFormRelativeUrl
(
form
):
return
portal
.
portal_catalog
(
portal_type
=
"ERP5 Form"
,
...
...
@@ -321,12 +323,17 @@ def getFormRelativeUrl(form):
select_dict
=
{
'relative_url'
:
None
}
)[
0
].
relative_url
def
getFieldDefault
(
traversed_document
,
field
,
key
,
value
=
None
):
# REQUEST.get(field.id, field.get_value("default"))
result
=
traversed_document
.
Field_getDefaultValue
(
field
,
key
,
value
,
REQUEST
)
if
getattr
(
result
,
'translate'
,
None
)
is
not
None
:
result
=
"%s"
%
result
return
result
def
getFieldDefault
(
form
,
field
,
key
,
value
=
None
):
"""Get available value for `field` preferably in python-object from REQUEST or from field's default."""
if
value
is
None
:
value
=
(
REQUEST
.
form
.
get
(
field
.
id
,
REQUEST
.
form
.
get
(
key
,
None
))
or
field
.
get_value
(
'default'
,
request
=
REQUEST
,
REQUEST
=
REQUEST
))
if
field
.
has_value
(
"unicode"
)
and
field
.
get_value
(
"unicode"
)
and
isinstance
(
value
,
'unicode'
):
value
=
unicode
(
value
,
self
.
get_form_encoding
())
if
getattr
(
value
,
'translate'
,
None
)
is
not
None
:
return
"%s"
%
value
return
value
def
renderField
(
traversed_document
,
field
,
form
,
value
=
None
,
meta_type
=
None
,
key
=
None
,
key_prefix
=
None
,
selection_params
=
None
):
...
...
@@ -358,7 +365,7 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
# fields have default value and can be required (unlike boxes)
result
.
update
({
"required"
:
field
.
get_value
(
"required"
)
if
field
.
has_value
(
"required"
)
else
None
,
"default"
:
getFieldDefault
(
traversed_document
,
field
,
result
[
"key"
]
,
value
),
"default"
:
getFieldDefault
(
form
,
field
,
key
,
value
),
})
if
meta_type
==
"ProxyField"
:
...
...
@@ -423,7 +430,7 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
"hide_day"
:
field
.
get_value
(
'hide_day'
),
"hidden_day_is_last_day"
:
field
.
get_value
(
'hidden_day_is_last_day'
),
})
date_value
=
getFieldDefault
(
traversed_document
,
field
,
result
[
"key"
]
,
value
)
date_value
=
getFieldDefault
(
form
,
field
,
key
,
value
)
if
not
date_value
and
field
.
get_value
(
'default_now'
):
date_value
=
DateTime
()
if
same_type
(
date_value
,
DateTime
()):
...
...
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