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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Łukasz Nowak
erp5
Commits
7c638a4f
Commit
7c638a4f
authored
Dec 19, 2016
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Catalog.CatalogTool: Truncate string instead of preparing offsets.
Simplifies extension. Also, factorise constants a bit.
parent
9572fc1f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
16 deletions
+13
-16
product/ERP5Catalog/CatalogTool.py
product/ERP5Catalog/CatalogTool.py
+13
-16
No files found.
product/ERP5Catalog/CatalogTool.py
View file @
7c638a4f
...
@@ -57,8 +57,8 @@ from zLOG import LOG, PROBLEM, WARNING, INFO
...
@@ -57,8 +57,8 @@ from zLOG import LOG, PROBLEM, WARNING, INFO
ACQUIRE_PERMISSION_VALUE
=
[]
ACQUIRE_PERMISSION_VALUE
=
[]
DYNAMIC_METHOD_NAME
=
'z_related_'
DYNAMIC_METHOD_NAME
=
'z_related_'
DYNAMIC_METHOD_NAME_LEN
=
len
(
DYNAMIC_METHOD_NAME
)
DYNAMIC_METHOD_NAME_LEN
=
len
(
DYNAMIC_METHOD_NAME
)
STRICT_
DYNAMIC_METHOD_NAME
=
DYNAMIC_METHOD_NAME
+
'strict_'
STRICT_
METHOD_NAME
=
'strict_'
STRICT_
DYNAMIC_METHOD_NAME_LEN
=
len
(
STRICT_DYNAMIC
_METHOD_NAME
)
STRICT_
METHOD_NAME_LEN
=
len
(
STRICT
_METHOD_NAME
)
RELATED_DYNAMIC_METHOD_NAME
=
'_related'
RELATED_DYNAMIC_METHOD_NAME
=
'_related'
# Negative as it's used as a slice end offset
# Negative as it's used as a slice end offset
RELATED_DYNAMIC_METHOD_NAME_LEN
=
-
len
(
RELATED_DYNAMIC_METHOD_NAME
)
RELATED_DYNAMIC_METHOD_NAME_LEN
=
-
len
(
RELATED_DYNAMIC_METHOD_NAME
)
...
@@ -941,7 +941,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
...
@@ -941,7 +941,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
)
)
base_cat_id_set
.
discard
(
'parent'
)
base_cat_id_set
.
discard
(
'parent'
)
default_string
=
'default_'
default_string
=
'default_'
strict_string
=
'strict_'
strict_string
=
STRICT_METHOD_NAME
related_string
=
'related_'
related_string
=
'related_'
column_map
=
self
.
getSQLCatalog
(
sql_catalog_id
).
getColumnMap
()
column_map
=
self
.
getSQLCatalog
(
sql_catalog_id
).
getColumnMap
()
for
key
in
key_list
:
for
key
in
key_list
:
...
@@ -953,7 +953,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
...
@@ -953,7 +953,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
if
key
.
startswith
(
strict_string
):
if
key
.
startswith
(
strict_string
):
strict
=
1
strict
=
1
key
=
key
[
len
(
strict_string
):]
key
=
key
[
len
(
strict_string
):]
prefix
=
prefix
+
strict_string
prefix
+=
strict_string
split_key
=
key
.
split
(
'_'
)
split_key
=
key
.
split
(
'_'
)
for
i
in
xrange
(
len
(
split_key
)
-
1
,
0
,
-
1
):
for
i
in
xrange
(
len
(
split_key
)
-
1
,
0
,
-
1
):
expected_base_cat_id
=
'_'
.
join
(
split_key
[
0
:
i
])
expected_base_cat_id
=
'_'
.
join
(
split_key
[
0
:
i
])
...
@@ -975,10 +975,10 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
...
@@ -975,10 +975,10 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
(
''
if
is_uid
else
',catalog'
)
+
(
''
if
is_uid
else
',catalog'
)
+
'/'
+
'/'
+
end_key
+
end_key
+
'/
z_related_'
+
'/
'
+
DYNAMIC_METHOD_NAME
+
(
'strict_'
if
strict
else
''
)
+
(
STRICT_METHOD_NAME
if
strict
else
''
)
+
expected_base_cat_id
+
expected_base_cat_id
+
(
'_related'
if
related
else
''
)
(
RELATED_DYNAMIC_METHOD_NAME
if
related
else
''
)
)
)
return
related_key_list
return
related_key_list
...
@@ -991,18 +991,15 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
...
@@ -991,18 +991,15 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
result
=
None
result
=
None
if
name
.
startswith
(
DYNAMIC_METHOD_NAME
)
and
\
if
name
.
startswith
(
DYNAMIC_METHOD_NAME
)
and
\
not
name
.
endswith
(
ZOPE_SECURITY_SUFFIX
):
not
name
.
endswith
(
ZOPE_SECURITY_SUFFIX
):
base_name
=
name
[
DYNAMIC_METHOD_NAME_LEN
:]
kw
=
{}
kw
=
{}
if
name
.
endswith
(
RELATED_DYNAMIC_METHOD_NAME
):
if
base_
name
.
endswith
(
RELATED_DYNAMIC_METHOD_NAME
):
end_offset
=
RELATED_DYNAMIC_METHOD_NAME_LEN
base_name
=
base_name
[:
RELATED_DYNAMIC_METHOD_NAME_LEN
]
kw
[
'related'
]
=
1
kw
[
'related'
]
=
1
else
:
if
base_name
.
startswith
(
STRICT_METHOD_NAME
):
end_offset
=
None
base_name
=
base_name
[
STRICT_METHOD_NAME_LEN
:]
if
name
.
startswith
(
STRICT_DYNAMIC_METHOD_NAME
):
start_offset
=
STRICT_DYNAMIC_METHOD_NAME_LEN
kw
[
'strict_membership'
]
=
1
kw
[
'strict_membership'
]
=
1
else
:
method
=
RelatedBaseCategory
(
base_name
,
**
kw
)
start_offset
=
DYNAMIC_METHOD_NAME_LEN
method
=
RelatedBaseCategory
(
name
[
start_offset
:
end_offset
],
**
kw
)
setattr
(
self
.
__class__
,
name
,
method
)
setattr
(
self
.
__class__
,
name
,
method
)
# This getattr has 2 purposes:
# This getattr has 2 purposes:
# - wrap in acquisition context
# - wrap in acquisition context
...
...
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