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
Nikola Balog
erp5
Commits
82a9774f
Commit
82a9774f
authored
Jan 22, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: make OOo import compatible with python3
parent
9214ab1d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
59 deletions
+32
-59
product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getCategoriesSpreadSheetMapping.py
...l_skins/erp5_core/Base_getCategoriesSpreadSheetMapping.py
+7
-40
product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getSafeIdFromString.py
...teItem/portal_skins/erp5_core/Base_getSafeIdFromString.py
+23
-18
product/ERP5OOo/tests/testOOoImport.py
product/ERP5OOo/tests/testOOoImport.py
+2
-1
No files found.
product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getCategoriesSpreadSheetMapping.py
View file @
82a9774f
...
@@ -25,6 +25,7 @@ The returned mapping has the following structure:
...
@@ -25,6 +25,7 @@ The returned mapping has the following structure:
This scripts guarantees that the list of category info is sorted in such a
This scripts guarantees that the list of category info is sorted in such a
way that parent always precedes their children.
way that parent always precedes their children.
"""
"""
import
six
from
Products.ERP5Type.Message
import
translateString
from
Products.ERP5Type.Message
import
translateString
from
Products.ERP5OOo.OOoUtils
import
OOoParser
from
Products.ERP5OOo.OOoUtils
import
OOoParser
parser
=
OOoParser
()
parser
=
OOoParser
()
...
@@ -41,41 +42,7 @@ if invalid_spreadsheet_error_handler is None:
...
@@ -41,41 +42,7 @@ if invalid_spreadsheet_error_handler is None:
property_id_set
=
portal
.
portal_types
.
Category
.
getInstancePropertySet
()
property_id_set
=
portal
.
portal_types
.
Category
.
getInstancePropertySet
()
property_id_set
.
update
(
getattr
(
portal
.
portal_types
,
'Base Category'
).
getInstancePropertySet
())
property_id_set
.
update
(
getattr
(
portal
.
portal_types
,
'Base Category'
).
getInstancePropertySet
())
def
getIDFromString
(
string
=
None
):
getIDFromString
=
portal
.
Base_getSafeIdFromString
"""
This function transform a string to a safe and beautiful ID.
It is used here to create a safe category ID from a string.
But the code is not really clever...
"""
if
string
is
None
:
return
None
clean_id
=
''
translation_map
=
{
'a'
:
[
u'
\
xe0
'
,
u'
\
xe3
'
]
,
'e'
:
[
u'
\
xe9
'
,
u'
\
xe8
'
]
,
'i'
:
[
u'
\
xed
'
]
,
'u'
:
[
u'
\
xf9
'
]
,
'_'
:
[
' '
,
'+'
]
,
'-'
:
[
'-'
,
u'
\
u2013
'
]
,
'and'
:
[
'&'
]
}
# Replace odd chars by safe ascii
string
=
string
.
lower
()
string
=
string
.
strip
()
for
(
safe_char
,
char_list
)
in
translation_map
.
items
():
for
char
in
char_list
:
string
=
string
.
replace
(
char
,
safe_char
)
# Exclude all non alphanumeric chars
for
char
in
string
:
if
char
.
isalnum
()
or
char
in
translation_map
.
keys
():
clean_id
+=
char
# Delete leading and trailing char which are not alpha-numerics
# This prevent having IDs with starting underscores
while
len
(
clean_id
)
>
0
and
not
clean_id
[
0
].
isalnum
():
clean_id
=
clean_id
[
1
:]
while
len
(
clean_id
)
>
0
and
not
clean_id
[
-
1
].
isalnum
():
clean_id
=
clean_id
[:
-
1
]
return
clean_id
# if the file is not an open office format, try to convert it using oood
# if the file is not an open office format, try to convert it using oood
# FIXME: use portal_transforms
# FIXME: use portal_transforms
...
@@ -129,7 +96,7 @@ for table_name in spreadsheet_list.keys():
...
@@ -129,7 +96,7 @@ for table_name in spreadsheet_list.keys():
else
:
else
:
# If there is a new column with a header and the path definition has
# If there is a new column with a header and the path definition has
# started, that seems the path definition has ended
# started, that seems the path definition has ended
property_map
[
column_index
]
=
column_id
.
encode
(
'utf8'
)
property_map
[
column_index
]
=
column_id
.
encode
(
'utf8'
)
if
six
.
PY2
else
column_id
column_index
+=
1
column_index
+=
1
# Construct categories data (with absolute path) from table lines
# Construct categories data (with absolute path) from table lines
...
@@ -137,9 +104,9 @@ for table_name in spreadsheet_list.keys():
...
@@ -137,9 +104,9 @@ for table_name in spreadsheet_list.keys():
# 1 table = 1 base category
# 1 table = 1 base category
base_category_name
=
table_name
base_category_name
=
table_name
base_category_id
=
getIDFromString
(
base_category_name
)
base_category_id
=
getIDFromString
(
base_category_name
)
if
s
ame_type
(
base_category_name
,
u''
):
if
s
ix
.
PY2
and
isinstance
(
base_category_name
,
unicode
):
base_category_name
=
base_category_name
.
encode
(
'utf8'
)
base_category_name
=
base_category_name
.
encode
(
'utf8'
)
if
s
ame_type
(
base_category_id
,
u''
):
if
s
ix
.
PY2
and
isinstance
(
base_category_id
,
unicode
):
base_category_id
=
base_category_id
.
encode
(
'utf8'
)
base_category_id
=
base_category_id
.
encode
(
'utf8'
)
category_list
=
category_list_spreadsheet_mapping
.
setdefault
(
base_category_id
,
[])
category_list
=
category_list_spreadsheet_mapping
.
setdefault
(
base_category_id
,
[])
category_list
.
append
({
'path'
:
base_category_id
category_list
.
append
({
'path'
:
base_category_id
...
@@ -198,7 +165,7 @@ for table_name in spreadsheet_list.keys():
...
@@ -198,7 +165,7 @@ for table_name in spreadsheet_list.keys():
if
cell_id
not
in
(
''
,
None
):
if
cell_id
not
in
(
''
,
None
):
# Handle normal properties
# Handle normal properties
if
not
property_id
.
startswith
(
'path_'
):
if
not
property_id
.
startswith
(
'path_'
):
if
same_type
(
cell_data
,
u''
):
if
s
ix
.
PY2
and
s
ame_type
(
cell_data
,
u''
):
cell_data
=
cell_data
.
encode
(
'utf8'
)
cell_data
=
cell_data
.
encode
(
'utf8'
)
category_property_list
[
property_id
]
=
cell_data
category_property_list
[
property_id
]
=
cell_data
# Handle 'path' property
# Handle 'path' property
...
@@ -218,7 +185,7 @@ for table_name in spreadsheet_list.keys():
...
@@ -218,7 +185,7 @@ for table_name in spreadsheet_list.keys():
# Get the next depth
# Get the next depth
break
break
path
=
'/'
.
join
([
base_category_id
,]
+
absolute_path_element_list
[::
-
1
])
path
=
'/'
.
join
([
base_category_id
,]
+
absolute_path_element_list
[::
-
1
])
if
same_type
(
path
,
u''
):
if
s
ix
.
PY2
and
s
ame_type
(
path
,
u''
):
path
=
path
.
encode
(
'utf8'
)
path
=
path
.
encode
(
'utf8'
)
category_property_list
[
'path'
]
=
path
category_property_list
[
'path'
]
=
path
...
...
product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getSafeIdFromString.py
View file @
82a9774f
...
@@ -2,27 +2,32 @@
...
@@ -2,27 +2,32 @@
This function transform a string to a safe id.
This function transform a string to a safe id.
It is used here to create a safe category id from a string.
It is used here to create a safe category id from a string.
"""
"""
translation_map
=
{
"a"
:
[
'
\
xe0
'
]
,
"e"
:
[
'
\
xe9
'
,
'
\
xe8
'
]
}
clean_id
=
''
if
s
is
None
:
if
s
is
None
:
return
None
return
None
clean_id
=
''
translation_map
=
{
'a'
:
[
u'
\
xe0
'
,
u'
\
xe3
'
]
,
'e'
:
[
u'
\
xe9
'
,
u'
\
xe8
'
]
,
'i'
:
[
u'
\
xed
'
]
,
'u'
:
[
u'
\
xf9
'
]
,
'_'
:
[
' '
,
'+'
]
,
'-'
:
[
'-'
,
u'
\
u2013
'
]
,
'and'
:
[
'&'
]
}
# Replace odd chars by safe ascii
s
=
s
.
lower
()
s
=
s
.
lower
()
s
=
s
.
strip
()
s
=
s
.
strip
()
# oocalc inserts some strange chars when you press - key in a text cell.
for
(
safe_char
,
char_list
)
in
translation_map
.
items
():
# Following line is a workaround for this, because \u2013 does not exist in latin1
for
char
in
char_list
:
s
=
s
.
replace
(
u'
\
u2013
'
,
'-'
)
s
=
s
.
replace
(
char
,
safe_char
)
for
char
in
s
.
encode
(
'iso8859_1'
):
# Exclude all non alphanumeric chars
if
char
==
'_'
or
char
.
isalnum
():
for
char
in
s
:
if
char
.
isalnum
()
or
char
in
translation_map
.
keys
():
clean_id
+=
char
clean_id
+=
char
elif
char
.
isspace
()
or
char
in
(
'+'
,
'-'
):
# Delete leading and trailing char which are not alpha-numerics
clean_id
+=
'_'
# This prevent having IDs with starting underscores
else
:
while
len
(
clean_id
)
>
0
and
not
clean_id
[
0
].
isalnum
()
:
for
(
safe_char
,
char_list
)
in
translation_map
.
items
():
clean_id
=
clean_id
[
1
:]
if
char
in
char_list
:
while
len
(
clean_id
)
>
0
and
not
clean_id
[
-
1
].
isalnum
()
:
clean_id
+=
safe_char
clean_id
=
clean_id
[:
-
1
]
break
return
clean_id
return
clean_id
product/ERP5OOo/tests/testOOoImport.py
View file @
82a9774f
...
@@ -916,7 +916,8 @@ class TestOOoImport(TestOOoImportMixin):
...
@@ -916,7 +916,8 @@ class TestOOoImport(TestOOoImportMixin):
"""Test than OOoimport can parse a file with more than 40000 lines
"""Test than OOoimport can parse a file with more than 40000 lines
"""
"""
parser
=
OOoParser
()
parser
=
OOoParser
()
parser
.
openFile
(
open
(
makeFilePath
(
'import_big_spreadsheet.ods'
),
'rb'
))
with
open
(
makeFilePath
(
'import_big_spreadsheet.ods'
),
'rb'
)
as
f
:
parser
.
openFile
(
f
)
mapping
=
parser
.
getSpreadsheetsMapping
()
mapping
=
parser
.
getSpreadsheetsMapping
()
not_ok
=
1
not_ok
=
1
for
spread
,
values
in
six
.
iteritems
(
mapping
):
for
spread
,
values
in
six
.
iteritems
(
mapping
):
...
...
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