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
amrani
erp5
Commits
09c476f8
Commit
09c476f8
authored
Mar 13, 2018
by
Ayush Tiwari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5_hal_json_style]: Add url_paramter_dict to contruct URLs in listbox fields
parent
bbedf149
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
144 additions
and
28 deletions
+144
-28
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
...rtal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
+42
-8
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_listbox_html.html
...ateItem/web_page_module/rjs_gadget_erp5_listbox_html.html
+23
-7
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_listbox_html.xml
...lateItem/web_page_module/rjs_gadget_erp5_listbox_html.xml
+3
-3
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_listbox_js.js
...emplateItem/web_page_module/rjs_gadget_erp5_listbox_js.js
+42
-6
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_listbox_js.xml
...mplateItem/web_page_module/rjs_gadget_erp5_listbox_js.xml
+3
-3
product/ERP5Form/ListBox.py
product/ERP5Form/ListBox.py
+31
-1
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/ERP5Document_getHateoas.py
View file @
09c476f8
...
...
@@ -1652,6 +1652,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# extract form field definition into `editable_field_dict`
editable_field_dict
=
{}
url_parameter_dict
=
{}
listbox_form
=
None
listbox_field_id
=
None
source_field_meta_type
=
source_field
.
meta_type
if
source_field
is
not
None
else
""
...
...
@@ -1662,6 +1663,16 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
listbox_field_id
=
source_field
.
id
listbox_form
=
getattr
(
traversed_document
,
source_field
.
aq_parent
.
id
)
url_parameter_dict
=
dict
(
source_field
.
get_value
(
'url_parameter_dict'
))
# support only selection_name for stat methods&url columns because any `selection` is deprecated
# and should be removed. Selection_name can be passed in catalog_kw by e.g. reports so it has precedence.
# Romain wants full backward compatibility so putting `selection` back in parameters
selection_name
=
catalog_kw
.
get
(
'selection_name'
,
source_field
.
get_value
(
'selection_name'
))
if
selection_name
and
'selection_name'
not
in
catalog_kw
:
catalog_kw
[
'selection_name'
]
=
selection_name
if
'selection'
not
in
catalog_kw
:
catalog_kw
[
'selection'
]
=
context
.
getPortalObject
().
portal_selections
.
getSelectionFor
(
selection_name
,
REQUEST
)
# field TALES expression evaluated by Base_getRelatedObjectParameter requires that
REQUEST
.
other
[
'form_id'
]
=
listbox_form
.
id
...
...
@@ -1769,6 +1780,35 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# given search_result. This name can unfortunately mean almost anything from
# a key name to Python Script with variable number of input parameters.
contents_item
[
select
]
=
getAttrFromAnything
(
search_result
,
select
,
property_getter
,
{
'brain'
:
search_result
})
if
url_parameter_dict
:
if
select
in
url_parameter_dict
:
contents_item
[
select
]
=
{
'column_value'
:
contents_item
[
select
],
'url_column'
:
True
}
generate_view
=
False
for
key
in
url_parameter_dict
[
select
]:
value
=
getattr
(
search_result
,
url_parameter_dict
[
select
][
key
],
None
)
if
key
==
'view'
:
generate_view
=
True
elif
callable
(
value
):
try
:
contents_item
[
select
][
key
]
=
value
(
selection
=
catalog_kw
[
'selection'
],
selection_name
=
catalog_kw
[
'selection_name'
],
column_id
=
select
,
index
=
result_index
)
except
(
TypeError
,
ValueError
):
contents_item
[
select
][
key
]
=
value
()
else
:
contents_item
[
select
][
key
]
=
url_parameter_dict
[
select
][
key
]
if
'jio_key'
not
in
contents_item
[
select
]
and
url_parameter_dict
[
select
]
and
'absolute_url'
not
in
contents_item
[
select
]:
contents_item
[
select
][
'jio_key'
]
=
traversed_document
.
getRelativeUrl
()
if
generate_view
:
contents_item
[
select
][
'view'
]
=
url_template_dict
[
"traverse_generator"
]
%
{
"root_url"
:
site_root
.
absolute_url
(),
"script_id"
:
script
.
id
,
"relative_url"
:
contents_item
[
select
][
'jio_key'
].
replace
(
"/"
,
"%2F"
),
"view"
:
url_parameter_dict
[
select
][
'view'
]
}
# endfor select
REQUEST
.
other
.
pop
(
'cell'
,
None
)
contents_list
.
append
(
contents_item
)
...
...
@@ -1801,6 +1841,8 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
if
count_method
!=
""
and
count_method
.
getMethodName
()
!=
list_method
:
count_kw
=
dict
(
catalog_kw
)
# Drop not needed parameters
count_kw
.
pop
(
'selection'
,
None
)
count_kw
.
pop
(
'selection_name'
,
None
)
count_kw
.
pop
(
"sort_on"
,
None
)
count_kw
.
pop
(
"limit"
,
None
)
count_method_result
=
getattr
(
traversed_document
,
count_method
.
getMethodName
())(
REQUEST
=
REQUEST
,
**
count_kw
)
...
...
@@ -1812,14 +1854,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# XXX: we should check whether they asked for it
stat_method
=
source_field
.
get_value
(
'stat_method'
)
stat_columns
=
source_field
.
get_value
(
'stat_columns'
)
# support only selection_name for stat methods because any `selection` is deprecated
# and should be removed. Selection_name can be passed in catalog_kw by e.g. reports so it has precedence.
# Romain wants full backward compatibility so putting `selection` back in parameters
selection_name
=
catalog_kw
.
get
(
'selection_name'
,
source_field
.
get_value
(
'selection_name'
))
if
selection_name
and
'selection_name'
not
in
catalog_kw
:
catalog_kw
[
'selection_name'
]
=
selection_name
if
'selection'
not
in
catalog_kw
:
catalog_kw
[
'selection'
]
=
context
.
getPortalObject
().
portal_selections
.
getSelectionFor
(
selection_name
,
REQUEST
)
contents_stat
=
{}
if
len
(
stat_columns
)
>
0
:
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_listbox_html.html
View file @
09c476f8
...
...
@@ -77,12 +77,20 @@
{{
#
if
editable
}}
<
div
class
=
"
editable_div
"
data
-
column
=
"
{{column}}
"
data
-
line
=
"
{{line}}
"
><
/div
>
{{
else
}}
{{
#
if
href
}}
<
a
href
=
"
{{href}}
"
class
=
"
ui-link
"
>
<
div
class
=
"
editable_div
"
data
-
column
=
"
{{column}}
"
data
-
line
=
"
{{line}}
"
><
/div
>
<
/a
>
{{
else
}}
<
div
class
=
"
editable_div
"
data
-
column
=
"
{{column}}
"
data
-
line
=
"
{{line}}
"
><
/div
>
{{
/
if
}}
{{
/if}
}
{{
else
}}
{{
#
if
href
}}
<
a
href
=
"
{{href}}
"
class
=
"
ui-link
"
>
{{
default
}}
<
/a
>
{{
else
}}
<
p
>
{{
default
}}
<
/p
>
{{
/
if
}}
{{
/if}
}
<
/td
>
{{
/
each
}}
...
...
@@ -117,12 +125,20 @@
{{
#
if
editable
}}
<
div
class
=
"
editable_div
"
data
-
column
=
"
{{column}}
"
data
-
line
=
"
{{line}}
"
><
/div
>
{{
else
}}
{{
#
if
href
}}
<
a
href
=
"
{{href}}
"
class
=
"
ui-link
"
>
<
div
class
=
"
editable_div
"
data
-
column
=
"
{{column}}
"
data
-
line
=
"
{{line}}
"
><
/div
>
<
/a
>
{{
else
}}
<
div
class
=
"
editable_div
"
data
-
column
=
"
{{column}}
"
data
-
line
=
"
{{line}}
"
><
/div
>
{{
/
if
}}
{{
/if}
}
{{
else
}}
{{
#
if
href
}}
<
a
href
=
"
{{href}}
"
class
=
"
ui-link
"
>
{{
default
}}
<
/a
>
{{
else
}}
<
p
>
{{
default
}}
<
/p
>
{{
/
if
}}
{{
/if}
}
<
/td
>
{{
/
each
}}
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_listbox_html.xml
View file @
09c476f8
...
...
@@ -234,7 +234,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
965.
63630.22597.59392
</string>
</value>
<value>
<string>
965.
9107.618.7594
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -252,8 +252,8 @@
</tuple>
<state>
<tuple>
<float>
15
20243676.3
7
</float>
<string>
UTC
</string>
<float>
15
18446005.9
7
</float>
<string>
GMT+1
</string>
</tuple>
</state>
</object>
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_listbox_js.js
View file @
09c476f8
...
...
@@ -468,9 +468,11 @@
.
push
(
function
()
{
var
lines
=
gadget
.
state
.
lines
,
promise_list
=
[],
url_promise_list
=
[],
allDocs_result
=
gadget
.
state
.
allDocs_result
,
counter
,
pagination_message
=
''
;
pagination_message
=
''
,
value
,
counter
;
column_list
=
JSON
.
parse
(
gadget
.
state
.
column_list_json
);
// for actual allDocs_result structure see ref:gadget_erp5_jio.js
...
...
@@ -496,17 +498,42 @@
}
})
);
for
(
j
=
0
;
j
<
column_list
.
length
;
j
+=
1
)
{
value
=
allDocs_result
.
data
.
rows
[
i
].
value
[
column_list
[
j
][
0
]]
||
""
;
if
(
value
.
url_column
)
{
if
(
value
.
jio_key
)
{
url_promise_list
.
push
(
gadget
.
getUrlFor
({
command
:
'
change
'
,
options
:
{
jio_key
:
value
.
jio_key
,
view
:
value
.
view
||
'
view
'
}
}));
}
else
if
(
value
.
absolute_url
)
{
url_promise_list
.
push
(
value
.
absolute_url
);
}
else
{
url_promise_list
.
push
(
false
);
}
}
}
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
(
promise_list
);
return
RSVP
.
all
([
RSVP
.
all
(
promise_list
),
RSVP
.
all
(
url_promise_list
)
]);
})
.
push
(
function
(
line_link_list
)
{
.
push
(
function
(
result_list
)
{
var
row_list
=
[],
value
,
cell_list
,
url_value
,
index
=
0
,
listbox_tbody_template
,
line_link_list
=
result_list
[
0
],
url_column_list
=
result_list
[
1
],
setNonEditable
=
function
(
cell
)
{
cell
.
editable
=
false
;
};
// reset list of UIDs of editable sub-documents
gadget
.
props
.
listbox_uid_dict
=
{
...
...
@@ -520,6 +547,15 @@
cell_list
=
[];
for
(
j
=
0
;
j
<
column_list
.
length
;
j
+=
1
)
{
value
=
allDocs_result
.
data
.
rows
[
i
].
value
[
column_list
[
j
][
0
]]
||
""
;
//url column
// get url value
if
(
value
.
url_column
)
{
url_value
=
url_column_list
[
index
];
value
=
value
.
column_value
||
""
;
index
+=
1
;
}
else
{
url_value
=
line_link_list
[
i
];
}
// value can be simply just a value in case of non-editable field
// thus we construct "field_json" manually and insert the value in "default"
if
(
value
.
constructor
!==
Object
)
{
...
...
@@ -528,7 +564,7 @@
'
default
'
:
value
};
}
value
.
href
=
line_link_list
[
i
]
;
value
.
href
=
url_value
;
value
.
editable
=
value
.
editable
&&
gadget
.
state
.
editable
;
value
.
line
=
i
;
value
.
column
=
j
;
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_listbox_js.xml
View file @
09c476f8
...
...
@@ -236,7 +236,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
96
6.8130.3423.18312
</string>
</value>
<value>
<string>
96
5.22051.43640.11997
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -254,8 +254,8 @@
</tuple>
<state>
<tuple>
<float>
15
20872134.75
</float>
<string>
UTC
</string>
<float>
15
18018366.8
</float>
<string>
GMT+1
</string>
</tuple>
</state>
</object>
...
...
product/ERP5Form/ListBox.py
View file @
09c476f8
...
...
@@ -52,6 +52,7 @@ from Products.PythonScripts.Utility import allow_class
from
Products.PageTemplates.PageTemplateFile
import
PageTemplateFile
from
warnings
import
warn
import
cgi
from
ZTUtils
import
make_query
DEFAULT_LISTBOX_DISPLAY_STYLE
=
'table'
DEFAULT_LISTBOX_PAGE_NAVIGATION_TEMPLATE
=
'ListBox_viewSliderPageNavigationRenderer'
...
...
@@ -350,6 +351,15 @@ class ListBoxWidget(Widget.Widget):
required
=
0
)
property_names
.
append
(
'url_columns'
)
url_parameter_dict
=
fields
.
ListTextAreaField
(
'url_parameter_dict'
,
title
=
"URL Parameter Dict"
,
description
=
(
"An optional dict of parameter which is used to construct a custom URL."
),
default
=
{},
required
=
0
)
property_names
.
append
(
'url_parameter_dict'
)
untranslatable_columns
=
fields
.
ListTextAreaField
(
'untranslatable_columns'
,
title
=
"Untranslatable Columns"
,
description
=
(
...
...
@@ -2291,6 +2301,7 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
brain
=
self
.
getBrain
()
encoding
=
renderer
.
getEncoding
()
url_column_dict
=
dict
(
renderer
.
getUrlColumnList
())
url_parameter_dict
=
renderer
.
field
.
get_value
(
'url_parameter_dict'
)
selection
=
renderer
.
getSelection
()
selection_name
=
renderer
.
getSelectionName
()
ignore_layout
=
int
(
request
.
get
(
'ignore_layout'
,
...
...
@@ -2322,9 +2333,28 @@ class ListBoxHTMLRendererLine(ListBoxRendererLine):
no_link
=
self
.
isSummary
()
url_method
=
None
url
=
None
if
url_parameter_dict
:
if
sql
in
url_parameter_dict
:
result_dict
=
url_parameter_dict
[
sql
].
copy
()
for
key
in
result_dict
:
value
=
getattr
(
brain
,
result_dict
[
key
],
None
)
if
key
!=
'view'
:
if
callable
(
value
):
try
:
result_dict
[
key
]
=
value
(
selection
=
selection
,
selection_name
=
selection
.
getName
(),
column_id
=
sql
,
index
=
self
.
index
)
except
TypeError
:
result_dict
[
key
]
=
value
()
if
result_dict
:
#this one is not good, should get restrivedocumet's path
if
'jio_key'
not
in
result_dict
:
url
=
request
.
physicalPathToURL
(
brain
.
getPath
())
else
:
url
=
self
.
getObject
().
getPortalObject
().
restrictedTraverse
(
result_dict
[
'jio_key'
]).
absolute_url
()
if
'parameter'
in
result_dict
:
url
=
'%s?%s'
%
(
url
,
make_query
(
result_dict
[
'parameter'
]))
# Find an URL method.
if
url_column_dict
.
has_key
(
sql
):
el
if
url_column_dict
.
has_key
(
sql
):
url_method_id
=
url_column_dict
.
get
(
sql
)
if
url_method_id
!=
sql
:
if
url_method_id
not
in
(
None
,
''
):
...
...
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