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
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
020473fa
Commit
020473fa
authored
Dec 12, 2013
by
Arnaud Fontaine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reindent code following removal of Business Template format version 0.
parent
c1746228
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
705 additions
and
721 deletions
+705
-721
product/ERP5/Document/BusinessTemplate.py
product/ERP5/Document/BusinessTemplate.py
+670
-685
product/ERP5/Tool/TemplateTool.py
product/ERP5/Tool/TemplateTool.py
+35
-36
No files found.
product/ERP5/Document/BusinessTemplate.py
View file @
020473fa
...
@@ -472,22 +472,21 @@ class BaseTemplateItem(Implicit, Persistent):
...
@@ -472,22 +472,21 @@ class BaseTemplateItem(Implicit, Persistent):
XXX: -12 used here is -len('TemplateItem')
XXX: -12 used here is -len('TemplateItem')
"""
"""
modified_object_list
=
{}
modified_object_list
=
{}
if
1
:
for
path
in
self
.
_objects
:
for
path
in
self
.
_objects
:
if
installed_item
.
_objects
.
has_key
(
path
):
if
installed_item
.
_objects
.
has_key
(
path
):
# compare objects to see it there are changes
# compare objects to see it there are changes
new_obj_xml
=
self
.
generateXml
(
path
=
path
)
new_obj_xml
=
self
.
generateXml
(
path
=
path
)
old_obj_xml
=
installed_item
.
generateXml
(
path
=
path
)
old_obj_xml
=
installed_item
.
generateXml
(
path
=
path
)
if
new_obj_xml
!=
old_obj_xml
:
if
new_obj_xml
!=
old_obj_xml
:
modified_object_list
.
update
({
path
:
[
'Modified'
,
self
.
__class__
.
__name__
[:
-
12
]]})
modified_object_list
.
update
({
path
:
[
'Modified'
,
self
.
__class__
.
__name__
[:
-
12
]]})
# else, compared versions are identical, don't overwrite the old one
# else, compared versions are identical, don't overwrite the old one
else
:
# new object
else
:
# new object
modified_object_list
.
update
({
path
:
[
'New'
,
self
.
__class__
.
__name__
[:
-
12
]]})
modified_object_list
.
update
({
path
:
[
'New'
,
self
.
__class__
.
__name__
[:
-
12
]]})
# list removed objects
# list removed objects
old_keys
=
installed_item
.
_objects
.
keys
()
old_keys
=
installed_item
.
_objects
.
keys
()
for
path
in
old_keys
:
for
path
in
old_keys
:
if
path
not
in
self
.
_objects
:
if
path
not
in
self
.
_objects
:
modified_object_list
.
update
({
path
:
[
'Removed'
,
self
.
__class__
.
__name__
[:
-
12
]]})
modified_object_list
.
update
({
path
:
[
'Removed'
,
self
.
__class__
.
__name__
[:
-
12
]]})
return
modified_object_list
return
modified_object_list
def
install
(
self
,
context
,
trashbin
,
**
kw
):
def
install
(
self
,
context
,
trashbin
,
**
kw
):
...
@@ -817,43 +816,42 @@ class ObjectTemplateItem(BaseTemplateItem):
...
@@ -817,43 +816,42 @@ class ObjectTemplateItem(BaseTemplateItem):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
modified_object_list
=
{}
modified_object_list
=
{}
if
1
:
upgrade_list
=
[]
upgrade_list
=
[]
type_name
=
self
.
__class__
.
__name__
.
split
(
'TemplateItem'
)[
-
2
]
type_name
=
self
.
__class__
.
__name__
.
split
(
'TemplateItem'
)[
-
2
]
for
path
,
obj
in
self
.
_objects
.
iteritems
():
for
path
,
obj
in
self
.
_objects
.
iteritems
():
if
installed_item
.
_objects
.
has_key
(
path
):
if
installed_item
.
_objects
.
has_key
(
path
):
upgrade_list
.
append
((
path
,
installed_item
.
_objects
[
path
]))
upgrade_list
.
append
((
path
,
installed_item
.
_objects
[
path
]))
else
:
# new object
else
:
# new object
modified_object_list
[
path
]
=
'New'
,
type_name
modified_object_list
[
path
]
=
'New'
,
type_name
# update _p_jar property of objects cleaned by removeProperties
# update _p_jar property of objects cleaned by removeProperties
transaction
.
savepoint
(
optimistic
=
True
)
transaction
.
savepoint
(
optimistic
=
True
)
for
path
,
old_object
in
upgrade_list
:
for
path
,
old_object
in
upgrade_list
:
# compare object to see it there is changes
# compare object to see it there is changes
new_object
=
self
.
_objects
[
path
]
new_object
=
self
.
_objects
[
path
]
new_io
=
StringIO
()
new_io
=
StringIO
()
old_io
=
StringIO
()
old_io
=
StringIO
()
OFS
.
XMLExportImport
.
exportXML
(
new_object
.
_p_jar
,
new_object
.
_p_oid
,
new_io
)
OFS
.
XMLExportImport
.
exportXML
(
new_object
.
_p_jar
,
new_object
.
_p_oid
,
new_io
)
new_obj_xml
=
new_io
.
getvalue
()
new_obj_xml
=
new_io
.
getvalue
()
try
:
try
:
OFS
.
XMLExportImport
.
exportXML
(
old_object
.
_p_jar
,
old_object
.
_p_oid
,
old_io
)
OFS
.
XMLExportImport
.
exportXML
(
old_object
.
_p_jar
,
old_object
.
_p_oid
,
old_io
)
old_obj_xml
=
old_io
.
getvalue
()
old_obj_xml
=
old_io
.
getvalue
()
except
(
ImportError
,
UnicodeDecodeError
),
e
:
# module is already
except
(
ImportError
,
UnicodeDecodeError
),
e
:
# module is already
# removed etc.
# removed etc.
old_obj_xml
=
'(%s: %s)'
%
(
e
.
__class__
.
__name__
,
e
)
old_obj_xml
=
'(%s: %s)'
%
(
e
.
__class__
.
__name__
,
e
)
new_io
.
close
()
new_io
.
close
()
old_io
.
close
()
old_io
.
close
()
if
new_obj_xml
!=
old_obj_xml
:
if
new_obj_xml
!=
old_obj_xml
:
if
context
.
isKeepObject
(
path
):
modified_object_list
[
path
]
=
'Modified but should be kept'
,
type_name
else
:
modified_object_list
[
path
]
=
'Modified'
,
type_name
# get removed object
for
path
in
set
(
installed_item
.
_objects
)
-
set
(
self
.
_objects
):
if
context
.
isKeepObject
(
path
):
if
context
.
isKeepObject
(
path
):
modified_object_list
[
path
]
=
'
Remov
ed but should be kept'
,
type_name
modified_object_list
[
path
]
=
'
Modifi
ed but should be kept'
,
type_name
else
:
else
:
modified_object_list
[
path
]
=
'Removed'
,
type_name
modified_object_list
[
path
]
=
'Modified'
,
type_name
# get removed object
for
path
in
set
(
installed_item
.
_objects
)
-
set
(
self
.
_objects
):
if
context
.
isKeepObject
(
path
):
modified_object_list
[
path
]
=
'Removed but should be kept'
,
type_name
else
:
modified_object_list
[
path
]
=
'Removed'
,
type_name
return
modified_object_list
return
modified_object_list
def
_backupObject
(
self
,
action
,
trashbin
,
container_path
,
object_id
,
**
kw
):
def
_backupObject
(
self
,
action
,
trashbin
,
container_path
,
object_id
,
**
kw
):
...
@@ -999,332 +997,332 @@ class ObjectTemplateItem(BaseTemplateItem):
...
@@ -999,332 +997,332 @@ class ObjectTemplateItem(BaseTemplateItem):
self.beforeInstall()
self.beforeInstall()
update_dict = kw.get('
object_to_update
')
update_dict = kw.get('
object_to_update
')
force = kw.get('
force
')
force = kw.get('
force
')
if 1:
def recurse(hook, document, prefix=''):
my_prefix = '
%
s
/%
s
' % (prefix, document.id)
if (hook(document, my_prefix)):
for subdocument in document.objectValues():
recurse(hook, subdocument, my_prefix)
def saveHook(document, prefix):
uid = getattr(aq_base(document), '
uid
', None)
if uid is None:
return 0
else:
saved_uid_dict[prefix] = uid
return 1
def restoreHook(document, prefix):
uid = saved_uid_dict.get(prefix)
if uid is None:
return 0
else:
document.uid = uid
return 1
groups = {}
old_groups = {}
portal = context.getPortalObject()
# set safe activities execution order
original_reindex_parameters = self.setSafeReindexationMode(context)
object_key_list = self._getObjectKeyList()
for path in object_key_list:
__traceback_info__ = path
# We do not need to perform any backup because the object was
# created during the Business Template installation
if update_dict.get(path) == '
migrate
':
continue
if update_dict.has_key(path) or force:
def recurse(hook, document, prefix=''):
# get action for the oject
my_prefix = '
%
s
/%
s
' % (prefix, document.id)
action = '
backup
'
if (hook(document, my_prefix)):
if not force:
for subdocument in document.objectValues():
action = update_dict[path]
recurse(hook, subdocument, my_prefix)
if action == '
nothing
':
def saveHook(document, prefix):
continue
uid = getattr(aq_base(document), '
uid
', None)
# get subobjects in path
if uid is None:
path_list = path.split('
/
')
return 0
container_path = path_list[:-1]
else:
object_id = path_list[-1]
saved_uid_dict[prefix] = uid
try:
return 1
container = self.unrestrictedResolveValue(portal, container_path)
def restoreHook(document, prefix):
except KeyError:
uid = saved_uid_dict.get(prefix)
# parent object can be set to nothing, in this case just go on
if uid is None:
container_url = '
/
'.join(container_path)
return 0
if update_dict.get(container_url) == '
nothing
':
else:
continue
document.uid = uid
# If container'
s
container
is
portal_catalog
,
return 1
# then automatically create the container.
groups = {}
elif
len
(
container_path
)
>
1
and
container_path
[
-
2
]
==
'portal_catalog'
:
old_groups = {}
# The id match, but better double check with the meta type
portal = context.getPortalObject()
# while avoiding the impact of systematic check
# set safe activities execution order
container_container
=
portal
.
unrestrictedTraverse
(
container_path
[:
-
1
])
original_reindex_parameters = self.setSafeReindexationMode(context)
if
container_container
.
meta_type
==
'ERP5 Catalog'
:
object_key_list = self._getObjectKeyList()
container_container
.
manage_addProduct
[
'ZSQLCatalog'
].
manage_addSQLCatalog
(
id
=
container_path
[
-
1
],
title
=
''
)
for path in object_key_list:
if
len
(
container_container
.
objectIds
())
==
1
:
__traceback_info__ = path
container_container
.
default_sql_catalog_id
=
container_path
[
-
1
]
# We do not need to perform any backup because the object was
container
=
portal
.
unrestrictedTraverse
(
container_path
)
# created during the Business Template installation
else
:
if update_dict.get(path) == '
migrate
':
raise
continue
saved_uid_dict
=
{}
subobjects_dict
=
{}
if update_dict.has_key(path) or force:
portal_type_dict
=
{}
# get action for the oject
old_obj
=
container
.
_getOb
(
object_id
,
None
)
action = '
backup
'
object_existed
=
old_obj
is
not
None
if not force:
if
object_existed
:
action = update_dict[path]
if
context
.
isKeepObject
(
path
)
and
force
:
if action == '
nothing
':
# do nothing if the object is specified in keep list in
continue
# force mode.
# get subobjects in path
continue
path_list = path.split('
/
')
# Object already exists
container_path = path_list[:-1]
recurse
(
saveHook
,
old_obj
)
object_id = path_list[-1]
if
getattr
(
aq_base
(
old_obj
),
'groups'
,
None
)
is
not
None
:
try:
# we must keep original order groups
container = self.unrestrictedResolveValue(portal, container_path)
# from old form in case we keep some
except KeyError:
# old widget, thus we can readd them in
# parent object can be set to nothing, in this case just go on
# the right order group
container_url = '
/
'.join(container_path)
old_groups
[
path
]
=
deepcopy
(
old_obj
.
groups
)
if update_dict.get(container_url) == '
nothing
':
subobjects_dict
=
self
.
_backupObject
(
action
,
trashbin
,
continue
container_path
,
object_id
)
# If container'
s
container
is
portal_catalog
,
# in case of portal types, we want to keep some properties
# then automatically create the container.
if
interfaces
.
ITypeProvider
.
providedBy
(
container
):
elif
len
(
container_path
)
>
1
and
container_path
[
-
2
]
==
'portal_catalog'
:
for
attr
in
(
'allowed_content_types'
,
# The id match, but better double check with the meta type
'hidden_content_type_list'
,
# while avoiding the impact of systematic check
'property_sheet_list'
,
container_container
=
portal
.
unrestrictedTraverse
(
container_path
[:
-
1
])
'base_category_list'
):
if
container_container
.
meta_type
==
'ERP5 Catalog'
:
portal_type_dict
[
attr
]
=
getattr
(
old_obj
,
attr
,
())
container_container
.
manage_addProduct
[
'ZSQLCatalog'
].
manage_addSQLCatalog
(
id
=
container_path
[
-
1
],
title
=
''
)
portal_type_dict
[
'workflow_chain'
]
=
\
if
len
(
container_container
.
objectIds
())
==
1
:
getChainByType
(
context
)[
1
].
get
(
'chain_'
+
object_id
,
''
)
container_container
.
default_sql_catalog_id
=
container_path
[
-
1
]
container
.
manage_delObjects
([
object_id
])
container
=
portal
.
unrestrictedTraverse
(
container_path
)
# unindex here when it is a broken object
else
:
if
isinstance
(
old_obj
,
Broken
):
raise
new_obj
=
self
.
_objects
[
path
]
saved_uid_dict
=
{}
# check isIndexable with new one, because the old one is broken
subobjects_dict
=
{}
if
new_obj
.
isIndexable
():
portal_type_dict
=
{}
self
.
unindexBrokenObject
(
path
)
old_obj
=
container
.
_getOb
(
object_id
,
None
)
object_existed
=
old_obj
is
not
None
# install object
if
object_existed
:
obj
=
self
.
_objects
[
path
]
if
context
.
isKeepObject
(
path
)
and
force
:
# XXX Following code make Python Scripts compile twice, because
# do nothing if the object is specified in keep list in
# _getCopy returns a copy without the result of the compilation.
# force mode.
# A solution could be to add a specific _getCopy method to
continue
# Python Scripts.
# Object already exists
if
getattr
(
aq_base
(
obj
),
'groups'
,
None
)
is
not
None
:
recurse
(
saveHook
,
old_obj
)
if
getattr
(
aq_base
(
old_obj
),
'groups'
,
None
)
is
not
None
:
# we must keep original order groups
# we must keep original order groups
# because they change when we add subobjects
# from old form in case we keep some
groups
[
path
]
=
deepcopy
(
obj
.
groups
)
# old widget, thus we can readd them in
# copy the object
# the right order group
if
(
getattr
(
aq_base
(
obj
),
'_mt_index'
,
None
)
is
not
None
and
old_groups
[
path
]
=
deepcopy
(
old_obj
.
groups
)
obj
.
_count
()
==
0
):
subobjects_dict
=
self
.
_backupObject
(
action
,
trashbin
,
# some btrees were exported in a corrupted state. They're empty but
container_path
,
object_id
)
# their metadata-index (._mt_index) contains entries which in
# in case of portal types, we want to keep some properties
# Zope 2.12 are used for .objectIds(), .objectValues() and
if
interfaces
.
ITypeProvider
.
providedBy
(
container
):
# .objectItems(). In these cases, force the
for
attr
in
(
'allowed_content_types'
,
LOG
(
'Products.ERP5.Document.BusinessTemplate'
,
WARNING
,
'hidden_content_type_list'
,
'Cleaning corrupted BTreeFolder2 object at %r.'
%
(
path
,))
'property_sheet_list'
,
obj
.
_initBTrees
()
'base_category_list'
):
obj
=
obj
.
_getCopy
(
container
)
portal_type_dict
[
attr
]
=
getattr
(
old_obj
,
attr
,
())
self
.
removeProperties
(
obj
,
0
)
portal_type_dict
[
'workflow_chain'
]
=
\
__traceback_info__
=
(
container
,
object_id
,
obj
)
getChainByType
(
context
)[
1
].
get
(
'chain_'
+
object_id
,
''
)
container
.
_setObject
(
object_id
,
obj
)
container
.
manage_delObjects
([
object_id
])
obj
=
container
.
_getOb
(
object_id
)
# unindex here when it is a broken object
if
isinstance
(
old_obj
,
Broken
):
if
not
object_existed
:
new_obj
=
self
.
_objects
[
path
]
# A new object was added, call the hook
# check isIndexable with new one, because the old one is broken
self
.
onNewObject
(
obj
)
if
new_obj
.
isIndexable
():
self
.
unindexBrokenObject
(
path
)
# mark a business template installation so in 'PortalType_afterClone' scripts
# we can implement logical for reseting or not attributes (i.e reference).
# install object
self
.
REQUEST
.
set
(
'is_business_template_installation'
,
1
)
obj
=
self
.
_objects
[
path
]
# We set isIndexable to 0 before calling
# XXX Following code make Python Scripts compile twice, because
# manage_afterClone in order to not call recursiveReindex, this is
# _getCopy returns a copy without the result of the compilation.
# useless because we will already reindex every created object, so
# A solution could be to add a specific _getCopy method to
# we avoid duplication of reindexation
# Python Scripts.
obj
.
isIndexable
=
ConstantGetter
(
'isIndexable'
,
value
=
False
)
if
getattr
(
aq_base
(
obj
),
'groups'
,
None
)
is
not
None
:
# START:part of ERP5Type.CopySupport.manage_afterClone
# we must keep original order groups
# * reset uid
# because they change when we add subobjects
# * reset owner
groups
[
path
]
=
deepcopy
(
obj
.
groups
)
# * do not reset workflow
# copy the object
# * do not call recursively
if
(
getattr
(
aq_base
(
obj
),
'_mt_index'
,
None
)
is
not
None
and
# * do not call type-based afterClone script
obj
.
_count
()
==
0
):
#
# some btrees were exported in a corrupted state. They're empty but
# Change uid attribute so that Catalog thinks object was not yet catalogued
# their metadata-index (._mt_index) contains entries which in
aq_base
(
obj
).
uid
=
portal
.
portal_catalog
.
newUid
()
# Zope 2.12 are used for .objectIds(), .objectValues() and
# Give the Owner local role to the current user, zope only does this if no
# .objectItems(). In these cases, force the
# local role has been defined on the object, which breaks ERP5Security
LOG
(
'Products.ERP5.Document.BusinessTemplate'
,
WARNING
,
if
getattr
(
aq_base
(
obj
),
'__ac_local_roles__'
,
None
)
is
not
None
:
'Cleaning corrupted BTreeFolder2 object at %r.'
%
(
path
,))
user
=
getSecurityManager
().
getUser
()
obj
.
_initBTrees
()
if
user
is
not
None
:
obj
=
obj
.
_getCopy
(
container
)
userid
=
user
.
getId
()
self
.
removeProperties
(
obj
,
0
)
if
userid
is
not
None
:
__traceback_info__
=
(
container
,
object_id
,
obj
)
#remove previous owners
container
.
_setObject
(
object_id
,
obj
)
local_role_dict
=
obj
.
__ac_local_roles__
obj
=
container
.
_getOb
(
object_id
)
removable_role_key_list
=
[]
for
key
,
value
in
local_role_dict
.
items
():
if
not
object_existed
:
if
'Owner'
in
value
:
# A new object was added, call the hook
value
.
remove
(
'Owner'
)
self
.
onNewObject
(
obj
)
if
len
(
value
)
==
0
:
removable_role_key_list
.
append
(
key
)
# mark a business template installation so in 'PortalType_afterClone' scripts
# there is no need to keep emptied keys after cloning, it makes
# we can implement logical for reseting or not attributes (i.e reference).
# unstable local roles -- if object is cloned it can be different when
self
.
REQUEST
.
set
(
'is_business_template_installation'
,
1
)
# after being just added
# We set isIndexable to 0 before calling
for
key
in
removable_role_key_list
:
# manage_afterClone in order to not call recursiveReindex, this is
local_role_dict
.
pop
(
key
)
# useless because we will already reindex every created object, so
#add new owner
# we avoid duplication of reindexation
l
=
local_role_dict
.
setdefault
(
userid
,
[])
obj
.
isIndexable
=
ConstantGetter
(
'isIndexable'
,
value
=
False
)
l
.
append
(
'Owner'
)
# START:part of ERP5Type.CopySupport.manage_afterClone
# END:part of ERP5Type.CopySupport.manage_afterClone
# * reset uid
del
obj
.
isIndexable
# * reset owner
if
getattr
(
aq_base
(
obj
),
'reindexObject'
,
None
)
is
not
None
:
# * do not reset workflow
obj
.
reindexObject
()
# * do not call recursively
obj
.
wl_clearLocks
()
# * do not call type-based afterClone script
if
portal_type_dict
:
#
# set workflow chain
# Change uid attribute so that Catalog thinks object was not yet catalogued
wf_chain
=
portal_type_dict
.
pop
(
'workflow_chain'
)
aq_base
(
obj
).
uid
=
portal
.
portal_catalog
.
newUid
()
chain_dict
=
getChainByType
(
context
)[
1
]
# Give the Owner local role to the current user, zope only does this if no
default_chain
=
''
# local role has been defined on the object, which breaks ERP5Security
chain_dict
[
'chain_%s'
%
(
object_id
)]
=
wf_chain
if
getattr
(
aq_base
(
obj
),
'__ac_local_roles__'
,
None
)
is
not
None
:
context
.
portal_workflow
.
manage_changeWorkflows
(
default_chain
,
props
=
chain_dict
)
user
=
getSecurityManager
().
getUser
()
# restore some other properties
if
user
is
not
None
:
obj
.
__dict__
.
update
(
portal_type_dict
)
userid
=
user
.
getId
()
# import sub objects if there is
if
userid
is
not
None
:
if
subobjects_dict
:
#remove previous owners
# get a jar
local_role_dict
=
obj
.
__ac_local_roles__
connection
=
self
.
getConnection
(
obj
)
removable_role_key_list
=
[]
# import subobjects
for
key
,
value
in
local_role_dict
.
items
():
for
subobject_id
,
subobject_data
in
subobjects_dict
.
iteritems
():
if
'Owner'
in
value
:
try
:
value
.
remove
(
'Owner'
)
if
obj
.
_getOb
(
subobject_id
,
None
)
is
None
:
if
len
(
value
)
==
0
:
subobject_data
.
seek
(
0
)
removable_role_key_list
.
append
(
key
)
subobject
=
connection
.
importFile
(
subobject_data
)
# there is no need to keep emptied keys after cloning, it makes
obj
.
_setObject
(
subobject_id
,
subobject
)
# unstable local roles -- if object is cloned it can be different when
except
AttributeError
:
# after being just added
# XXX this may happen when an object which can contain
for
key
in
removable_role_key_list
:
# sub-objects (e.g. ERP5 Form) has been replaced with
local_role_dict
.
pop
(
key
)
# an object which cannot (e.g. External Method).
#add new owner
LOG
(
'BusinessTemplate'
,
WARNING
,
l
=
local_role_dict
.
setdefault
(
userid
,
[])
'could not restore %r in %r'
%
(
subobject_id
,
obj
))
l
.
append
(
'Owner'
)
if
obj
.
meta_type
in
(
'Z SQL Method'
,):
# END:part of ERP5Type.CopySupport.manage_afterClone
fixZSQLMethod
(
portal
,
obj
)
del
obj
.
isIndexable
# portal transforms specific initialization
if
getattr
(
aq_base
(
obj
),
'reindexObject'
,
None
)
is
not
None
:
elif
obj
.
meta_type
in
(
'Transform'
,
'TransformsChain'
):
obj
.
reindexObject
()
assert
container
.
meta_type
==
'Portal Transforms'
obj
.
wl_clearLocks
()
# skip transforms that couldn't have been initialized
if
portal_type_dict
:
if
obj
.
title
!=
'BROKEN'
:
# set workflow chain
container
.
_mapTransform
(
obj
)
wf_chain
=
portal_type_dict
.
pop
(
'workflow_chain'
)
elif
obj
.
meta_type
in
(
'ERP5 Ram Cache'
,
chain_dict
=
getChainByType
(
context
)[
1
]
'ERP5 Distributed Ram Cache'
,):
default_chain
=
''
assert
container
.
meta_type
in
(
'ERP5 Cache Factory'
,
chain_dict
[
'chain_%s'
%
(
object_id
)]
=
wf_chain
'ERP5 Cache Bag'
)
context
.
portal_workflow
.
manage_changeWorkflows
(
default_chain
,
props
=
chain_dict
)
container
.
getParentValue
().
updateCache
()
# restore some other properties
elif
(
container
.
meta_type
==
'CMF Skins Tool'
)
and
\
obj
.
__dict__
.
update
(
portal_type_dict
)
(
old_obj
is
not
None
):
# import sub objects if there is
# Keep compatibility with previous export format of
if
subobjects_dict
:
# business_template_registered_skin_selections
# get a jar
# and do not modify exported value
connection
=
self
.
getConnection
(
obj
)
if
obj
.
getProperty
(
'business_template_registered_skin_selections'
,
# import subobjects
None
)
is
None
:
for
subobject_id
,
subobject_data
in
subobjects_dict
.
iteritems
():
# Keep previous value of register skin selection for skin folder
try
:
skin_selection_list
=
old_obj
.
getProperty
(
if
obj
.
_getOb
(
subobject_id
,
None
)
is
None
:
'business_template_registered_skin_selections'
,
None
)
subobject_data
.
seek
(
0
)
if
skin_selection_list
is
not
None
:
subobject
=
connection
.
importFile
(
subobject_data
)
if
isinstance
(
skin_selection_list
,
basestring
):
obj
.
_setObject
(
subobject_id
,
subobject
)
skin_selection_list
=
skin_selection_list
.
split
(
' '
)
except
AttributeError
:
obj
.
_setProperty
(
# XXX this may happen when an object which can contain
'business_template_registered_skin_selections'
,
# sub-objects (e.g. ERP5 Form) has been replaced with
skin_selection_list
,
type
=
'tokens'
)
# an object which cannot (e.g. External Method).
# in case the portal ids, we want keep the property dict
LOG
(
'BusinessTemplate'
,
WARNING
,
elif
interfaces
.
IIdGenerator
.
providedBy
(
obj
)
and
\
'could not restore %r in %r'
%
(
subobject_id
,
obj
))
old_obj
is
not
None
:
if
obj
.
meta_type
in
(
'Z SQL Method'
,):
for
dict_name
in
(
'last_max_id_dict'
,
'last_id_dict'
):
fixZSQLMethod
(
portal
,
obj
)
# Keep previous last id dict
# portal transforms specific initialization
if
getattr
(
old_obj
,
dict_name
,
None
)
is
not
None
:
elif
obj
.
meta_type
in
(
'Transform'
,
'TransformsChain'
):
old_dict
=
getattr
(
old_obj
,
dict_name
,
None
)
assert
container
.
meta_type
==
'Portal Transforms'
setattr
(
obj
,
dict_name
,
old_dict
)
# skip transforms that couldn't have been initialized
if
obj
.
title
!=
'BROKEN'
:
recurse
(
restoreHook
,
obj
)
container
.
_mapTransform
(
obj
)
# now put original order group
elif
obj
.
meta_type
in
(
'ERP5 Ram Cache'
,
# we remove object not added in forms
'ERP5 Distributed Ram Cache'
,):
# we put old objects we have kept
assert
container
.
meta_type
in
(
'ERP5 Cache Factory'
,
for
path
,
new_groups_dict
in
groups
.
iteritems
():
'ERP5 Cache Bag'
)
if
not
old_groups
.
has_key
(
path
):
container
.
getParentValue
().
updateCache
()
# installation of a new form
elif
(
container
.
meta_type
==
'CMF Skins Tool'
)
and
\
obj
=
portal
.
unrestrictedTraverse
(
path
)
(
old_obj
is
not
None
):
obj
.
groups
=
new_groups_dict
# Keep compatibility with previous export format of
else
:
# business_template_registered_skin_selections
# upgrade of a form
# and do not modify exported value
old_groups_dict
=
old_groups
[
path
]
if
obj
.
getProperty
(
'business_template_registered_skin_selections'
,
obj
=
portal
.
unrestrictedTraverse
(
path
)
None
)
is
None
:
# first check that all widgets are in new order
# Keep previous value of register skin selection for skin folder
# excetp the one that had to be removed
skin_selection_list
=
old_obj
.
getProperty
(
widget_id_list
=
obj
.
objectIds
()
'business_template_registered_skin_selections'
,
None
)
for
widget_id
in
widget_id_list
:
if
skin_selection_list
is
not
None
:
widget_path
=
path
+
'/'
+
widget_id
if
isinstance
(
skin_selection_list
,
basestring
):
if
update_dict
.
has_key
(
widget_path
)
and
update_dict
[
widget_path
]
in
(
'remove'
,
'save_and_remove'
):
skin_selection_list
=
skin_selection_list
.
split
(
' '
)
continue
obj
.
_setProperty
(
widget_in_form
=
0
'business_template_registered_skin_selections'
,
for
group_id
,
group_value_list
in
new_groups_dict
.
iteritems
():
skin_selection_list
,
type
=
'tokens'
)
if
widget_id
in
group_value_list
:
# in case the portal ids, we want keep the property dict
widget_in_form
=
1
elif
interfaces
.
IIdGenerator
.
providedBy
(
obj
)
and
\
break
old_obj
is
not
None
:
# if not, add it in the same groups
for
dict_name
in
(
'last_max_id_dict'
,
'last_id_dict'
):
# defined on the former form
# Keep previous last id dict
previous_group_id
=
None
if
getattr
(
old_obj
,
dict_name
,
None
)
is
not
None
:
if
not
widget_in_form
:
old_dict
=
getattr
(
old_obj
,
dict_name
,
None
)
for
old_group_id
,
old_group_values
in
old_groups_dict
.
iteritems
():
setattr
(
obj
,
dict_name
,
old_dict
)
if
widget_id
in
old_group_values
:
previous_group_id
=
old_group_id
recurse
(
restoreHook
,
obj
)
# if we find same group in new one, add widget to it
# now put original order group
if
previous_group_id
is
not
None
and
new_groups_dict
.
has_key
(
previous_group_id
):
# we remove object not added in forms
new_groups_dict
[
previous_group_id
].
append
(
widget_id
)
# we put old objects we have kept
# otherwise use a specific group
for
path
,
new_groups_dict
in
groups
.
iteritems
():
else
:
if
not
old_groups
.
has_key
(
path
):
if
new_groups_dict
.
has_key
(
'not_assigned'
):
# installation of a new form
new_groups_dict
[
'not_assigned'
].
append
(
widget_id
)
obj
=
portal
.
unrestrictedTraverse
(
path
)
else
:
obj
.
groups
=
new_groups_dict
new_groups_dict
[
'not_assigned'
]
=
[
widget_id
,]
else
:
obj
.
group_list
=
list
(
obj
.
group_list
)
+
[
'not_assigned'
]
# upgrade of a form
# second check all widget_id in order are in form
old_groups_dict
=
old_groups
[
path
]
obj
=
portal
.
unrestrictedTraverse
(
path
)
# first check that all widgets are in new order
# excetp the one that had to be removed
widget_id_list
=
obj
.
objectIds
()
for
widget_id
in
widget_id_list
:
widget_path
=
path
+
'/'
+
widget_id
if
update_dict
.
has_key
(
widget_path
)
and
update_dict
[
widget_path
]
in
(
'remove'
,
'save_and_remove'
):
continue
widget_in_form
=
0
for
group_id
,
group_value_list
in
new_groups_dict
.
iteritems
():
for
group_id
,
group_value_list
in
new_groups_dict
.
iteritems
():
for
widget_id
in
tuple
(
group_value_list
):
if
widget_id
in
group_value_list
:
if
widget_id
not
in
widget_id_list
:
widget_in_form
=
1
# if we don't find the widget id in the form
break
# remove it fro the group
# if not, add it in the same groups
group_value_list
.
remove
(
widget_id
)
# defined on the former form
# now set new group object
previous_group_id
=
None
obj
.
groups
=
new_groups_dict
if
not
widget_in_form
:
# restore previous activities execution order
for
old_group_id
,
old_group_values
in
old_groups_dict
.
iteritems
():
context
.
setPlacelessDefaultReindexParameters
(
**
original_reindex_parameters
)
if
widget_id
in
old_group_values
:
# Do not forget to delete all remaining objects if asked by user
previous_group_id
=
old_group_id
# Fetch all sub objects path recursively
# if we find same group in new one, add widget to it
recursive_path_list
=
[]
if
previous_group_id
is
not
None
and
new_groups_dict
.
has_key
(
previous_group_id
):
def
fillRecursivePathList
(
from_path_list
):
new_groups_dict
[
previous_group_id
].
append
(
widget_id
)
for
from_path
in
from_path_list
:
# otherwise use a specific group
container
=
portal
.
unrestrictedTraverse
(
from_path
,
None
)
if
container
is
not
None
:
if
from_path
in
recursive_path_list
:
continue
recursive_path_list
.
append
(
from_path
)
# Check that container support iteration of sub_content_id
if
getattr
(
aq_base
(
container
),
'objectIds'
,
None
)
is
not
None
:
fillRecursivePathList
([
'%s/%s'
%
(
from_path
,
sub_content_id
)
for
\
sub_content_id
in
container
.
objectIds
()])
fillRecursivePathList
(
object_key_list
)
for
recursive_path
in
recursive_path_list
:
if
recursive_path
in
update_dict
:
action
=
update_dict
[
recursive_path
]
if
action
in
(
'remove'
,
'save_and_remove'
):
document
=
self
.
unrestrictedResolveValue
(
portal
,
recursive_path
,
None
)
if
document
is
None
:
# It happens if the parent of target path is removed before
continue
if
getattr
(
aq_base
(
document
),
'getParentValue'
,
None
)
is
not
None
:
# regular ERP5 object
parent
=
document
.
getParentValue
()
else
:
else
:
parent
=
document
.
aq_parent
if
new_groups_dict
.
has_key
(
'not_assigned'
):
document_id
=
document
.
getId
()
new_groups_dict
[
'not_assigned'
].
append
(
widget_id
)
container_path_list
=
recursive_path
.
split
(
'/'
)[:
-
1
]
else
:
self
.
_backupObject
(
action
,
trashbin
,
container_path_list
,
new_groups_dict
[
'not_assigned'
]
=
[
widget_id
,]
document_id
)
obj
.
group_list
=
list
(
obj
.
group_list
)
+
[
'not_assigned'
]
parent
.
manage_delObjects
([
document_id
])
# second check all widget_id in order are in form
for
group_id
,
group_value_list
in
new_groups_dict
.
iteritems
():
for
widget_id
in
tuple
(
group_value_list
):
if
widget_id
not
in
widget_id_list
:
# if we don't find the widget id in the form
# remove it fro the group
group_value_list
.
remove
(
widget_id
)
# now set new group object
obj
.
groups
=
new_groups_dict
# restore previous activities execution order
context
.
setPlacelessDefaultReindexParameters
(
**
original_reindex_parameters
)
# Do not forget to delete all remaining objects if asked by user
# Fetch all sub objects path recursively
recursive_path_list
=
[]
def
fillRecursivePathList
(
from_path_list
):
for
from_path
in
from_path_list
:
container
=
portal
.
unrestrictedTraverse
(
from_path
,
None
)
if
container
is
not
None
:
if
from_path
in
recursive_path_list
:
continue
recursive_path_list
.
append
(
from_path
)
# Check that container support iteration of sub_content_id
if
getattr
(
aq_base
(
container
),
'objectIds'
,
None
)
is
not
None
:
fillRecursivePathList
([
'%s/%s'
%
(
from_path
,
sub_content_id
)
for
\
sub_content_id
in
container
.
objectIds
()])
fillRecursivePathList
(
object_key_list
)
for
recursive_path
in
recursive_path_list
:
if
recursive_path
in
update_dict
:
action
=
update_dict
[
recursive_path
]
if
action
in
(
'remove'
,
'save_and_remove'
):
document
=
self
.
unrestrictedResolveValue
(
portal
,
recursive_path
,
None
)
if
document
is
None
:
# It happens if the parent of target path is removed before
continue
if
getattr
(
aq_base
(
document
),
'getParentValue'
,
None
)
is
not
None
:
# regular ERP5 object
parent
=
document
.
getParentValue
()
else
:
parent
=
document
.
aq_parent
document_id
=
document
.
getId
()
container_path_list
=
recursive_path
.
split
(
'/'
)[:
-
1
]
self
.
_backupObject
(
action
,
trashbin
,
container_path_list
,
document_id
)
parent
.
manage_delObjects
([
document_id
])
self
.
afterInstall
()
self
.
afterInstall
()
...
@@ -1835,21 +1833,20 @@ class RegisteredSkinSelectionTemplateItem(BaseTemplateItem):
...
@@ -1835,21 +1833,20 @@ class RegisteredSkinSelectionTemplateItem(BaseTemplateItem):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
modified_object_list
=
{}
modified_object_list
=
{}
if
1
:
for
path
in
self
.
_objects
:
for
path
in
self
.
_objects
:
if
installed_item
.
_objects
.
has_key
(
path
):
if
installed_item
.
_objects
.
has_key
(
path
):
# compare object to see it there is changes
# compare object to see it there is changes
new_object
=
self
.
_objects
[
path
]
new_object
=
self
.
_objects
[
path
]
old_object
=
installed_item
.
_objects
[
path
]
old_object
=
installed_item
.
_objects
[
path
]
if
new_object
!=
old_object
:
if
new_object
!=
old_object
:
modified_object_list
.
update
({
path
:
[
'Modified'
,
self
.
__class__
.
__name__
[:
-
12
]]})
modified_object_list
.
update
({
path
:
[
'Modified'
,
self
.
__class__
.
__name__
[:
-
12
]]})
else
:
# new object
else
:
# new object
modified_object_list
.
update
({
path
:
[
'New'
,
self
.
__class__
.
__name__
[:
-
12
]]})
modified_object_list
.
update
({
path
:
[
'New'
,
self
.
__class__
.
__name__
[:
-
12
]]})
# get removed object
# get removed object
old_keys
=
installed_item
.
_objects
.
keys
()
old_keys
=
installed_item
.
_objects
.
keys
()
for
path
in
old_keys
:
for
path
in
old_keys
:
if
path
not
in
self
.
_objects
:
if
path
not
in
self
.
_objects
:
modified_object_list
.
update
({
path
:
[
'Removed'
,
self
.
__class__
.
__name__
[:
-
12
]]})
modified_object_list
.
update
({
path
:
[
'Removed'
,
self
.
__class__
.
__name__
[:
-
12
]]})
return
modified_object_list
return
modified_object_list
def
_importFile
(
self
,
file_name
,
file
):
def
_importFile
(
self
,
file_name
,
file
):
...
@@ -2022,40 +2019,39 @@ class WorkflowTemplateItem(ObjectTemplateItem):
...
@@ -2022,40 +2019,39 @@ class WorkflowTemplateItem(ObjectTemplateItem):
return
modified_workflow_dict
return
modified_workflow_dict
def
install
(
self
,
context
,
trashbin
,
**
kw
):
def
install
(
self
,
context
,
trashbin
,
**
kw
):
if
1
:
portal
=
context
.
getPortalObject
()
portal
=
context
.
getPortalObject
()
update_dict
=
kw
.
get
(
'object_to_update'
)
update_dict
=
kw
.
get
(
'object_to_update'
)
force
=
kw
.
get
(
'force'
)
force
=
kw
.
get
(
'force'
)
# sort to add objects before their subobjects
# sort to add objects before their subobjects
for
path
in
sorted
(
self
.
_objects
):
for
path
in
sorted
(
self
.
_objects
):
if
force
:
if
force
:
action
=
'backup'
action
=
'backup'
else
:
else
:
action
=
update_dict
.
get
(
'/'
.
join
(
path
.
split
(
'/'
)[:
2
]))
action
=
update_dict
.
get
(
'/'
.
join
(
path
.
split
(
'/'
)[:
2
]))
if
action
in
(
None
,
'nothing'
):
if
action
in
(
None
,
'nothing'
):
continue
container_path
=
path
.
split
(
'/'
)[:
-
1
]
object_id
=
path
.
split
(
'/'
)[
-
1
]
try
:
container
=
self
.
unrestrictedResolveValue
(
portal
,
container_path
)
except
KeyError
:
# parent object can be set to nothing, in this case just go on
container_url
=
'/'
.
join
(
container_path
)
if
update_dict
.
has_key
(
container_url
):
if
update_dict
[
container_url
]
==
'nothing'
:
continue
continue
container_path
=
path
.
split
(
'/'
)[:
-
1
]
raise
object_id
=
path
.
split
(
'/'
)[
-
1
]
container_ids
=
container
.
objectIds
()
try
:
if
object_id
in
container_ids
:
# Object already exists
container
=
self
.
unrestrictedResolveValue
(
portal
,
container_path
)
self
.
_backupObject
(
action
,
trashbin
,
container_path
,
object_id
,
keep_subobjects
=
1
)
except
KeyError
:
container
.
manage_delObjects
([
object_id
])
# parent object can be set to nothing, in this case just go on
obj
=
self
.
_objects
[
path
]
container_url
=
'/'
.
join
(
container_path
)
obj
=
obj
.
_getCopy
(
container
)
if
update_dict
.
has_key
(
container_url
):
self
.
removeProperties
(
obj
,
0
)
if
update_dict
[
container_url
]
==
'nothing'
:
container
.
_setObject
(
object_id
,
obj
)
continue
obj
=
container
.
_getOb
(
object_id
)
raise
obj
.
manage_afterClone
(
obj
)
container_ids
=
container
.
objectIds
()
obj
.
wl_clearLocks
()
if
object_id
in
container_ids
:
# Object already exists
self
.
_backupObject
(
action
,
trashbin
,
container_path
,
object_id
,
keep_subobjects
=
1
)
container
.
manage_delObjects
([
object_id
])
obj
=
self
.
_objects
[
path
]
obj
=
obj
.
_getCopy
(
container
)
self
.
removeProperties
(
obj
,
0
)
container
.
_setObject
(
object_id
,
obj
)
obj
=
container
.
_getOb
(
object_id
)
obj
.
manage_afterClone
(
obj
)
obj
.
wl_clearLocks
()
def
uninstall
(
self
,
context
,
**
kw
):
def
uninstall
(
self
,
context
,
**
kw
):
object_path
=
kw
.
get
(
'object_path'
,
None
)
object_path
=
kw
.
get
(
'object_path'
,
None
)
...
@@ -2359,34 +2355,33 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem):
...
@@ -2359,34 +2355,33 @@ class PortalTypeWorkflowChainTemplateItem(BaseTemplateItem):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
modified_object_list
=
{}
modified_object_list
=
{}
if
1
:
new_dict
=
PersistentMapping
()
new_dict
=
PersistentMapping
()
# Fix key from installed bt if necessary
# Fix key from installed bt if necessary
for
key
,
value
in
installed_item
.
_objects
.
iteritems
():
for
key
,
value
in
installed_item
.
_objects
.
iteritems
():
if
not
'portal_type_workflow_chain/'
in
key
:
if
not
'portal_type_workflow_chain/'
in
key
:
key
=
'portal_type_workflow_chain/%s'
%
(
key
)
key
=
'portal_type_workflow_chain/%s'
%
(
key
)
new_dict
[
key
]
=
value
new_dict
[
key
]
=
value
if
new_dict
:
if
new_dict
:
installed_item
.
_objects
=
new_dict
installed_item
.
_objects
=
new_dict
for
path
in
self
.
_objects
:
for
path
in
self
.
_objects
:
if
path
in
installed_item
.
_objects
:
if
path
in
installed_item
.
_objects
:
# compare object to see it there is changes
# compare object to see it there is changes
new_object
=
self
.
_objects
[
path
]
new_object
=
self
.
_objects
[
path
]
old_object
=
installed_item
.
_objects
[
path
]
old_object
=
installed_item
.
_objects
[
path
]
if
isinstance
(
new_object
,
str
):
if
isinstance
(
new_object
,
str
):
new_object
=
new_object
.
split
(
self
.
_chain_string_separator
)
new_object
=
new_object
.
split
(
self
.
_chain_string_separator
)
if
isinstance
(
old_object
,
str
):
if
isinstance
(
old_object
,
str
):
old_object
=
old_object
.
split
(
self
.
_chain_string_separator
)
old_object
=
old_object
.
split
(
self
.
_chain_string_separator
)
new_object
.
sort
()
new_object
.
sort
()
old_object
.
sort
()
old_object
.
sort
()
if
new_object
!=
old_object
:
if
new_object
!=
old_object
:
modified_object_list
.
update
({
path
:
[
'Modified'
,
self
.
getTemplateTypeName
()]})
modified_object_list
.
update
({
path
:
[
'Modified'
,
self
.
getTemplateTypeName
()]})
else
:
# new object
else
:
# new object
modified_object_list
.
update
({
path
:
[
'New'
,
self
.
getTemplateTypeName
()]})
modified_object_list
.
update
({
path
:
[
'New'
,
self
.
getTemplateTypeName
()]})
# get removed object
# get removed object
for
path
in
installed_item
.
_objects
:
for
path
in
installed_item
.
_objects
:
if
path
not
in
self
.
_objects
:
if
path
not
in
self
.
_objects
:
modified_object_list
.
update
({
path
:
[
'Removed'
,
self
.
getTemplateTypeName
()]})
modified_object_list
.
update
({
path
:
[
'Removed'
,
self
.
getTemplateTypeName
()]})
return
modified_object_list
return
modified_object_list
def
_importFile
(
self
,
file_name
,
file
):
def
_importFile
(
self
,
file_name
,
file
):
...
@@ -2465,30 +2460,29 @@ class PortalTypeAllowedContentTypeTemplateItem(BaseTemplateItem):
...
@@ -2465,30 +2460,29 @@ class PortalTypeAllowedContentTypeTemplateItem(BaseTemplateItem):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
modified_object_list
=
{}
modified_object_list
=
{}
if
1
:
new_dict
=
PersistentMapping
()
new_dict
=
PersistentMapping
()
# fix key if necessary in installed bt for diff
# fix key if necessary in installed bt for diff
for
key
,
value
in
installed_item
.
_objects
.
iteritems
():
for
key
,
value
in
installed_item
.
_objects
.
iteritems
():
if
self
.
class_property
not
in
key
:
if
self
.
class_property
not
in
key
:
key
=
'%s/%s'
%
(
self
.
class_property
,
key
)
key
=
'%s/%s'
%
(
self
.
class_property
,
key
)
new_dict
[
key
]
=
value
new_dict
[
key
]
=
value
if
new_dict
:
if
new_dict
:
installed_item
.
_objects
=
new_dict
installed_item
.
_objects
=
new_dict
for
path
in
self
.
_objects
:
for
path
in
self
.
_objects
:
if
path
in
installed_item
.
_objects
:
if
path
in
installed_item
.
_objects
:
# compare object to see it there is changes
# compare object to see it there is changes
new_object
=
self
.
_objects
[
path
]
new_object
=
self
.
_objects
[
path
]
old_object
=
installed_item
.
_objects
[
path
]
old_object
=
installed_item
.
_objects
[
path
]
new_object
.
sort
()
new_object
.
sort
()
old_object
.
sort
()
old_object
.
sort
()
if
new_object
!=
old_object
:
if
new_object
!=
old_object
:
modified_object_list
.
update
({
path
:
[
'Modified'
,
self
.
getTemplateTypeName
()]})
modified_object_list
.
update
({
path
:
[
'Modified'
,
self
.
getTemplateTypeName
()]})
else
:
# new object
else
:
# new object
modified_object_list
.
update
({
path
:
[
'New'
,
self
.
getTemplateTypeName
()]})
modified_object_list
.
update
({
path
:
[
'New'
,
self
.
getTemplateTypeName
()]})
# get removed object
# get removed object
for
path
in
installed_item
.
_objects
:
for
path
in
installed_item
.
_objects
:
if
path
not
in
self
.
_objects
:
if
path
not
in
self
.
_objects
:
modified_object_list
.
update
({
path
:
[
'Removed'
,
self
.
getTemplateTypeName
()]})
modified_object_list
.
update
({
path
:
[
'Removed'
,
self
.
getTemplateTypeName
()]})
return
modified_object_list
return
modified_object_list
def
_importFile
(
self
,
file_name
,
file
):
def
_importFile
(
self
,
file_name
,
file
):
...
@@ -2749,12 +2743,11 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
...
@@ -2749,12 +2743,11 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
# Restore filter
# Restore filter
if
self
.
_is_filtered_archive
.
get
(
method_id
,
0
):
if
self
.
_is_filtered_archive
.
get
(
method_id
,
0
):
expression
=
self
.
_filter_expression_archive
[
method_id
]
expression
=
self
.
_filter_expression_archive
[
method_id
]
if
1
:
if
expression
and
expression
.
strip
():
if
expression
and
expression
.
strip
():
# only compile non-empty expressions
# only compile non-empty expressions
expr_instance
=
Expression
(
expression
)
expr_instance
=
Expression
(
expression
)
else
:
else
:
expr_instance
=
None
expr_instance
=
None
catalog
.
filter_dict
[
method_id
]
=
PersistentMapping
()
catalog
.
filter_dict
[
method_id
]
=
PersistentMapping
()
catalog
.
filter_dict
[
method_id
][
'filtered'
]
=
1
catalog
.
filter_dict
[
method_id
][
'filtered'
]
=
1
catalog
.
filter_dict
[
method_id
][
'expression'
]
=
expression
catalog
.
filter_dict
[
method_id
][
'expression'
]
=
expression
...
@@ -2961,76 +2954,75 @@ class ActionTemplateItem(ObjectTemplateItem):
...
@@ -2961,76 +2954,75 @@ class ActionTemplateItem(ObjectTemplateItem):
def
install
(
self
,
context
,
trashbin
,
**
kw
):
def
install
(
self
,
context
,
trashbin
,
**
kw
):
update_dict
=
kw
.
get
(
'object_to_update'
)
update_dict
=
kw
.
get
(
'object_to_update'
)
force
=
kw
.
get
(
'force'
)
force
=
kw
.
get
(
'force'
)
if
1
:
portal_type_dict
=
{}
portal_type_dict
=
{}
p
=
context
.
getPortalObject
()
p
=
context
.
getPortalObject
()
for
id
in
self
.
_objects
.
keys
():
for
id
in
self
.
_objects
.
keys
():
if
update_dict
.
has_key
(
id
)
or
force
:
if
update_dict
.
has_key
(
id
)
or
force
:
if
not
force
:
if
not
force
:
action
=
update_dict
[
id
]
action
=
update_dict
[
id
]
if
action
==
'nothing'
:
if
action
==
'nothing'
:
continue
obj
=
self
.
_objects
[
id
]
path
,
id
=
id
.
rsplit
(
'/'
,
1
)
container
=
p
.
unrestrictedTraverse
(
path
)
if
interfaces
.
ITypeProvider
.
providedBy
(
aq_parent
(
aq_inner
(
container
))):
# XXX future BT should use 'reference' instead of 'id'
reference
=
getattr
(
obj
,
'reference'
,
None
)
or
obj
.
id
portal_type_dict
.
setdefault
(
path
,
{})[
reference
]
=
obj
continue
continue
obj
=
self
.
_objects
[
id
]
# Following code is for actions outside Types Tool.
path
,
id
=
id
.
rsplit
(
'/'
,
1
)
# It will be removed when they are also converted to ERP5 actions.
from
Products.CMFCore.interfaces
import
IActionProvider
if
not
IActionProvider
.
providedBy
(
container
):
# some tools stopped being ActionProviders in CMF 2.x. Drop the
# action into portal_actions.
LOG
(
'Products.ERP5.Document.BusinessTemplate'
,
WARNING
,
'Redirected action import'
,
'Attempted to store action %r in %r which is no longer an '
'IActionProvided. Storing action on portal_actions instead'
%
(
id
,
path
))
container
=
p
.
portal_actions
obj
,
action
=
container
,
obj
action_list
=
obj
.
listActions
()
for
index
in
range
(
len
(
action_list
)):
if
action_list
[
index
].
id
==
id
:
# remove previous action
obj
.
deleteActions
(
selections
=
(
index
,))
action_text
=
action
.
action
if
isinstance
(
action_text
,
Expression
):
action_text
=
action_text
.
text
obj
.
addAction
(
id
=
action
.
id
,
name
=
action
.
title
,
action
=
action_text
,
condition
=
action
.
getCondition
()
,
permission
=
action
.
permissions
,
category
=
action
.
category
,
visible
=
action
.
visible
,
icon
=
getattr
(
action
,
'icon'
,
None
)
\
and
action
.
icon
.
text
or
''
,
priority
=
action
.
priority
,
description
=
action
.
description
)
# sort action based on the priority define on it
# XXX suppose that priority are properly on actions
new_priority
=
action
.
priority
action_list
=
obj
.
listActions
()
move_down_list
=
[]
for
index
in
range
(
len
(
action_list
)):
action
=
action_list
[
index
]
if
action
.
priority
>
new_priority
:
move_down_list
.
append
(
str
(
index
))
obj
.
moveDownActions
(
selections
=
tuple
(
move_down_list
))
for
path
,
action_dict
in
portal_type_dict
.
iteritems
():
container
=
p
.
unrestrictedTraverse
(
path
)
container
=
p
.
unrestrictedTraverse
(
path
)
container
.
manage_delObjects
([
obj
.
id
for
obj
in
container
.
getActionInformationList
()
if
interfaces
.
ITypeProvider
.
providedBy
(
aq_parent
(
aq_inner
(
container
))):
if
obj
.
getReference
()
in
action_dict
])
# XXX future BT should use 'reference' instead of 'id'
for
name
,
obj
in
action_dict
.
iteritems
():
reference
=
getattr
(
obj
,
'reference'
,
None
)
or
obj
.
id
container
.
_importOldAction
(
obj
).
aq_base
portal_type_dict
.
setdefault
(
path
,
{})[
reference
]
=
obj
continue
# Following code is for actions outside Types Tool.
# It will be removed when they are also converted to ERP5 actions.
from
Products.CMFCore.interfaces
import
IActionProvider
if
not
IActionProvider
.
providedBy
(
container
):
# some tools stopped being ActionProviders in CMF 2.x. Drop the
# action into portal_actions.
LOG
(
'Products.ERP5.Document.BusinessTemplate'
,
WARNING
,
'Redirected action import'
,
'Attempted to store action %r in %r which is no longer an '
'IActionProvided. Storing action on portal_actions instead'
%
(
id
,
path
))
container
=
p
.
portal_actions
obj
,
action
=
container
,
obj
action_list
=
obj
.
listActions
()
for
index
in
range
(
len
(
action_list
)):
if
action_list
[
index
].
id
==
id
:
# remove previous action
obj
.
deleteActions
(
selections
=
(
index
,))
action_text
=
action
.
action
if
isinstance
(
action_text
,
Expression
):
action_text
=
action_text
.
text
obj
.
addAction
(
id
=
action
.
id
,
name
=
action
.
title
,
action
=
action_text
,
condition
=
action
.
getCondition
()
,
permission
=
action
.
permissions
,
category
=
action
.
category
,
visible
=
action
.
visible
,
icon
=
getattr
(
action
,
'icon'
,
None
)
\
and
action
.
icon
.
text
or
''
,
priority
=
action
.
priority
,
description
=
action
.
description
)
# sort action based on the priority define on it
# XXX suppose that priority are properly on actions
new_priority
=
action
.
priority
action_list
=
obj
.
listActions
()
move_down_list
=
[]
for
index
in
range
(
len
(
action_list
)):
action
=
action_list
[
index
]
if
action
.
priority
>
new_priority
:
move_down_list
.
append
(
str
(
index
))
obj
.
moveDownActions
(
selections
=
tuple
(
move_down_list
))
for
path
,
action_dict
in
portal_type_dict
.
iteritems
():
container
=
p
.
unrestrictedTraverse
(
path
)
container
.
manage_delObjects
([
obj
.
id
for
obj
in
container
.
getActionInformationList
()
if
obj
.
getReference
()
in
action_dict
])
for
name
,
obj
in
action_dict
.
iteritems
():
container
.
_importOldAction
(
obj
).
aq_base
def
uninstall
(
self
,
context
,
**
kw
):
def
uninstall
(
self
,
context
,
**
kw
):
p
=
context
.
getPortalObject
()
p
=
context
.
getPortalObject
()
...
@@ -3248,24 +3240,23 @@ class SitePropertyTemplateItem(BaseTemplateItem):
...
@@ -3248,24 +3240,23 @@ class SitePropertyTemplateItem(BaseTemplateItem):
def
install
(
self
,
context
,
trashbin
,
**
kw
):
def
install
(
self
,
context
,
trashbin
,
**
kw
):
update_dict
=
kw
.
get
(
'object_to_update'
)
update_dict
=
kw
.
get
(
'object_to_update'
)
force
=
kw
.
get
(
'force'
)
force
=
kw
.
get
(
'force'
)
if
1
:
p
=
context
.
getPortalObject
()
p
=
context
.
getPortalObject
()
for
path
in
self
.
_objects
.
keys
():
for
path
in
self
.
_objects
.
keys
():
if
update_dict
.
has_key
(
path
)
or
force
:
if
update_dict
.
has_key
(
path
)
or
force
:
if
not
force
:
if
not
force
:
action
=
update_dict
[
path
]
action
=
update_dict
[
path
]
if
action
==
'nothing'
:
if
action
==
'nothing'
:
continue
continue
dir
,
id
=
posixpath
.
split
(
path
)
dir
,
id
=
posixpath
.
split
(
path
)
prop_type
,
property
=
self
.
_objects
[
path
]
prop_type
,
property
=
self
.
_objects
[
path
]
if
p
.
hasProperty
(
id
):
if
p
.
hasProperty
(
id
):
if
p
.
getPropertyType
(
id
)
!=
prop_type
:
if
p
.
getPropertyType
(
id
)
!=
prop_type
:
p
.
_delProperty
(
id
)
p
.
_delProperty
(
id
)
p
.
_setProperty
(
id
,
property
,
type
=
prop_type
)
else
:
p
.
_updateProperty
(
id
,
property
)
else
:
p
.
_setProperty
(
id
,
property
,
type
=
prop_type
)
p
.
_setProperty
(
id
,
property
,
type
=
prop_type
)
else
:
p
.
_updateProperty
(
id
,
property
)
else
:
p
.
_setProperty
(
id
,
property
,
type
=
prop_type
)
def
uninstall
(
self
,
context
,
**
kw
):
def
uninstall
(
self
,
context
,
**
kw
):
p
=
context
.
getPortalObject
()
p
=
context
.
getPortalObject
()
...
@@ -3491,34 +3482,33 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem):
...
@@ -3491,34 +3482,33 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
modified_object_list
=
{}
modified_object_list
=
{}
if
1
:
# fix key if necessary in installed bt for diff
# fix key if necessary in installed bt for diff
extra_prefix
=
self
.
__class__
.
__name__
+
'/'
extra_prefix
=
self
.
__class__
.
__name__
+
'/'
for
key
in
installed_item
.
_objects
.
keys
():
for
key
in
installed_item
.
_objects
.
keys
():
if
key
.
startswith
(
extra_prefix
):
if
key
.
startswith
(
extra_prefix
):
new_key
=
key
[
len
(
extra_prefix
):]
new_key
=
key
[
len
(
extra_prefix
):]
installed_item
.
_objects
[
new_key
]
=
installed_item
.
_objects
[
key
]
installed_item
.
_objects
[
new_key
]
=
installed_item
.
_objects
[
key
]
del
installed_item
.
_objects
[
key
]
del
installed_item
.
_objects
[
key
]
for
path
in
self
.
_objects
:
for
path
in
self
.
_objects
:
if
installed_item
.
_objects
.
has_key
(
path
):
if
installed_item
.
_objects
.
has_key
(
path
):
# compare object to see if there is changes
# compare object to see if there is changes
new_obj_code
=
self
.
_objects
[
path
]
new_obj_code
=
self
.
_objects
[
path
]
old_obj_code
=
installed_item
.
_objects
[
path
]
old_obj_code
=
installed_item
.
_objects
[
path
]
if
new_obj_code
!=
old_obj_code
:
if
new_obj_code
!=
old_obj_code
:
# Note: Magical way to have unique paths
modified_object_list
.
update
(
{
self
.
_getKey
(
path
)
:
[
'Modified'
,
self
.
__class__
.
__name__
[:
-
12
]]})
else
:
# new object
# Note: Magical way to have unique paths
modified_object_list
.
update
(
{
self
.
_getKey
(
path
)
:
[
'New'
,
self
.
__class__
.
__name__
[:
-
12
]]})
# get removed object
old_keys
=
installed_item
.
_objects
.
keys
()
for
path
in
old_keys
:
if
path
not
in
self
.
_objects
:
# Note: Magical way to have unique paths
# Note: Magical way to have unique paths
modified_object_list
.
update
(
modified_object_list
.
update
(
{
self
.
_getKey
(
path
)
:
[
'Removed'
,
self
.
__class__
.
__name__
[:
-
12
]]})
{
self
.
_getKey
(
path
)
:
[
'Modified'
,
self
.
__class__
.
__name__
[:
-
12
]]})
else
:
# new object
# Note: Magical way to have unique paths
modified_object_list
.
update
(
{
self
.
_getKey
(
path
)
:
[
'New'
,
self
.
__class__
.
__name__
[:
-
12
]]})
# get removed object
old_keys
=
installed_item
.
_objects
.
keys
()
for
path
in
old_keys
:
if
path
not
in
self
.
_objects
:
# Note: Magical way to have unique paths
modified_object_list
.
update
(
{
self
.
_getKey
(
path
)
:
[
'Removed'
,
self
.
__class__
.
__name__
[:
-
12
]]})
return
modified_object_list
return
modified_object_list
def
_resetDynamicModules
(
self
):
def
_resetDynamicModules
(
self
):
...
@@ -3539,35 +3529,34 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem):
...
@@ -3539,35 +3529,34 @@ class FilesystemDocumentTemplateItem(BaseTemplateItem):
def
install
(
self
,
context
,
trashbin
,
**
kw
):
def
install
(
self
,
context
,
trashbin
,
**
kw
):
update_dict
=
kw
.
get
(
'object_to_update'
)
update_dict
=
kw
.
get
(
'object_to_update'
)
force
=
kw
.
get
(
'force'
)
force
=
kw
.
get
(
'force'
)
if
1
:
need_reset
=
isinstance
(
self
,
FilesystemDocumentTemplateItem
)
need_reset
=
isinstance
(
self
,
FilesystemDocumentTemplateItem
)
for
key
in
self
.
_objects
.
keys
():
for
key
in
self
.
_objects
.
keys
():
# to achieve non data migration fresh installation parameters
# to achieve non data migration fresh installation parameters
# differ from upgrade parameteres, so here the check have to be
# differ from upgrade parameteres, so here the check have to be
# care of both cases
# care of both cases
upgraded_key
=
self
.
_getKey
(
key
)
upgraded_key
=
self
.
_getKey
(
key
)
if
update_dict
.
has_key
(
key
)
or
update_dict
.
has_key
(
upgraded_key
)
\
if
update_dict
.
has_key
(
key
)
or
update_dict
.
has_key
(
upgraded_key
)
\
or
force
:
or
force
:
if
not
force
:
if
not
force
:
action
=
update_dict
.
get
(
key
,
update_dict
.
get
(
upgraded_key
))
action
=
update_dict
.
get
(
key
,
update_dict
.
get
(
upgraded_key
))
if
action
==
'nothing'
:
if
action
==
'nothing'
:
continue
text
=
self
.
_objects
[
key
]
path
,
name
=
posixpath
.
split
(
key
)
try
:
self
.
local_file_writer_name
(
name
,
text
,
create
=
0
)
except
IOError
,
error
:
LOG
(
self
.
__class__
.
__name__
,
WARNING
,
"Cannot install class %r on file system"
%
name
)
if
error
.
errno
:
raise
continue
if
self
.
local_file_importer_name
is
None
:
continue
continue
if
need_reset
:
text
=
self
.
_objects
[
key
]
self
.
_resetDynamicModules
()
path
,
name
=
posixpath
.
split
(
key
)
need_reset
=
False
try
:
self
.
local_file_importer_name
(
name
)
self
.
local_file_writer_name
(
name
,
text
,
create
=
0
)
except
IOError
,
error
:
LOG
(
self
.
__class__
.
__name__
,
WARNING
,
"Cannot install class %r on file system"
%
name
)
if
error
.
errno
:
raise
continue
if
self
.
local_file_importer_name
is
None
:
continue
if
need_reset
:
self
.
_resetDynamicModules
()
need_reset
=
False
self
.
local_file_importer_name
(
name
)
def
remove
(
self
,
context
,
**
kw
):
def
remove
(
self
,
context
,
**
kw
):
"""Conversion of magically uniqued paths to real ones"""
"""Conversion of magically uniqued paths to real ones"""
...
@@ -4112,23 +4101,22 @@ class RoleTemplateItem(BaseTemplateItem):
...
@@ -4112,23 +4101,22 @@ class RoleTemplateItem(BaseTemplateItem):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
modified_object_list
=
{}
modified_object_list
=
{}
if
1
:
# BBB it might be necessary to change the data structure.
# BBB it might be necessary to change the data structure.
obsolete_key
=
self
.
__class__
.
__name__
+
'/role_list'
obsolete_key
=
self
.
__class__
.
__name__
+
'/role_list'
if
obsolete_key
in
installed_item
.
_objects
:
if
obsolete_key
in
installed_item
.
_objects
:
for
role
in
installed_item
.
_objects
[
obsolete_key
]:
for
role
in
installed_item
.
_objects
[
obsolete_key
]:
installed_item
.
_objects
[
role
]
=
1
installed_item
.
_objects
[
role
]
=
1
del
installed_item
.
_objects
[
obsolete_key
]
del
installed_item
.
_objects
[
obsolete_key
]
for
role
in
self
.
_objects
:
for
role
in
self
.
_objects
:
if
installed_item
.
_objects
.
has_key
(
role
):
if
installed_item
.
_objects
.
has_key
(
role
):
continue
continue
else
:
# only show new roles
else
:
# only show new roles
modified_object_list
.
update
({
role
:
[
'New'
,
'Role'
]})
modified_object_list
.
update
({
role
:
[
'New'
,
'Role'
]})
# get removed roles
# get removed roles
old_roles
=
installed_item
.
_objects
.
keys
()
old_roles
=
installed_item
.
_objects
.
keys
()
for
role
in
old_roles
:
for
role
in
old_roles
:
if
role
not
in
self
.
_objects
:
if
role
not
in
self
.
_objects
:
modified_object_list
.
update
({
role
:
[
'Removed'
,
self
.
__class__
.
__name__
[:
-
12
]]})
modified_object_list
.
update
({
role
:
[
'Removed'
,
self
.
__class__
.
__name__
[:
-
12
]]})
return
modified_object_list
return
modified_object_list
def
install
(
self
,
context
,
trashbin
,
**
kw
):
def
install
(
self
,
context
,
trashbin
,
**
kw
):
...
@@ -4235,12 +4223,11 @@ class CatalogKeyTemplateItemBase(BaseTemplateItem):
...
@@ -4235,12 +4223,11 @@ class CatalogKeyTemplateItemBase(BaseTemplateItem):
return
return
catalog_key_list
=
list
(
getattr
(
catalog
,
self
.
key_list_attr
,
[]))
catalog_key_list
=
list
(
getattr
(
catalog
,
self
.
key_list_attr
,
[]))
if
1
:
if
len
(
self
.
_objects
.
keys
())
==
0
:
# needed because of pop()
if
len
(
self
.
_objects
.
keys
())
==
0
:
# needed because of pop()
return
return
keys
=
[]
keys
=
[]
for
k
in
self
.
_objects
.
values
().
pop
():
# because of list of list
for
k
in
self
.
_objects
.
values
().
pop
():
# because of list of list
keys
.
append
(
k
)
keys
.
append
(
k
)
update_dict
=
kw
.
get
(
'object_to_update'
)
update_dict
=
kw
.
get
(
'object_to_update'
)
force
=
kw
.
get
(
'force'
)
force
=
kw
.
get
(
'force'
)
if
force
or
self
.
_getUpdateDictAction
(
update_dict
)
!=
'nothing'
:
if
force
or
self
.
_getUpdateDictAction
(
update_dict
)
!=
'nothing'
:
...
@@ -4408,21 +4395,20 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
...
@@ -4408,21 +4395,20 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
def
preinstall
(
self
,
context
,
installed_item
,
**
kw
):
modified_object_list
=
{}
modified_object_list
=
{}
if
1
:
for
path
in
self
.
_objects
:
for
path
in
self
.
_objects
:
if
installed_item
.
_objects
.
has_key
(
path
):
if
installed_item
.
_objects
.
has_key
(
path
):
# compare object to see if there is changes
# compare object to see if there is changes
new_obj_code
=
self
.
_objects
[
path
]
new_obj_code
=
self
.
_objects
[
path
]
old_obj_code
=
installed_item
.
_objects
[
path
]
old_obj_code
=
installed_item
.
_objects
[
path
]
if
new_obj_code
!=
old_obj_code
:
if
new_obj_code
!=
old_obj_code
:
modified_object_list
.
update
({
path
:
[
'Modified'
,
self
.
__class__
.
__name__
[:
-
12
]]})
modified_object_list
.
update
({
path
:
[
'Modified'
,
self
.
__class__
.
__name__
[:
-
12
]]})
else
:
# new object
else
:
# new object
modified_object_list
.
update
({
path
:
[
'New'
,
self
.
__class__
.
__name__
[:
-
12
]]})
modified_object_list
.
update
({
path
:
[
'New'
,
self
.
__class__
.
__name__
[:
-
12
]]})
# get removed object
# get removed object
old_keys
=
installed_item
.
_objects
.
keys
()
old_keys
=
installed_item
.
_objects
.
keys
()
for
path
in
old_keys
:
for
path
in
old_keys
:
if
path
not
in
self
.
_objects
:
if
path
not
in
self
.
_objects
:
modified_object_list
.
update
({
path
:
[
'Removed'
,
self
.
__class__
.
__name__
[:
-
12
]]})
modified_object_list
.
update
({
path
:
[
'Removed'
,
self
.
__class__
.
__name__
[:
-
12
]]})
return
modified_object_list
return
modified_object_list
def
_splitKey
(
self
,
key
):
def
_splitKey
(
self
,
key
):
...
@@ -4454,37 +4440,36 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
...
@@ -4454,37 +4440,36 @@ class MessageTranslationTemplateItem(BaseTemplateItem):
localizer
=
context
.
getPortalObject
().
Localizer
localizer
=
context
.
getPortalObject
().
Localizer
update_dict
=
kw
.
get
(
'object_to_update'
,
{})
update_dict
=
kw
.
get
(
'object_to_update'
,
{})
force
=
kw
.
get
(
'force'
)
force
=
kw
.
get
(
'force'
)
if
1
:
for
key
in
sorted
(
self
.
_objects
.
keys
()):
for
key
in
sorted
(
self
.
_objects
.
keys
()):
if
update_dict
.
has_key
(
key
)
or
force
:
if
update_dict
.
has_key
(
key
)
or
force
:
if
not
force
:
if
not
force
:
action
=
update_dict
[
key
]
action
=
update_dict
[
key
]
if
action
==
'nothing'
:
if
action
==
'nothing'
:
continue
continue
lang
,
catalog
=
self
.
_splitKey
(
key
)
lang
,
catalog
=
self
.
_splitKey
(
key
)
if
catalog
is
None
:
if
catalog
is
None
:
name
=
self
.
_objects
[
key
]
name
=
self
.
_objects
[
key
]
for
lang_dict
in
localizer
.
get_all_languages
():
for
lang_dict
in
localizer
.
get_all_languages
():
if
lang_dict
[
'code'
]
==
lang
:
if
lang_dict
[
'code'
]
==
lang
:
# When the Localizer has the language as a user-defined
# When the Localizer has the language as a user-defined
# language, make sure that the name is updated.
# language, make sure that the name is updated.
old_name
=
localizer
.
get_user_defined_language_name
(
lang
)
old_name
=
localizer
.
get_user_defined_language_name
(
lang
)
if
old_name
is
not
None
and
old_name
!=
name
:
if
old_name
is
not
None
and
old_name
!=
name
:
localizer
.
_del_user_defined_language
(
lang
)
localizer
.
_del_user_defined_language
(
lang
)
localizer
.
_add_user_defined_language
(
name
,
lang
)
localizer
.
_add_user_defined_language
(
name
,
lang
)
break
break
else
:
# if the Localizer does not know the language code, it must be
# defined as a user-defined language.
localizer
.
_add_user_defined_language
(
name
,
lang
)
if
lang
not
in
localizer
.
get_languages
():
localizer
.
manage_addLanguage
(
lang
)
else
:
else
:
po
=
self
.
_objects
[
key
]
# if the Localizer does not know the language code, it must be
if
lang
not
in
localizer
.
get_languages
():
# defined as a user-defined language.
localizer
.
manage_addLanguage
(
lang
)
localizer
.
_add_user_defined_language
(
name
,
lang
)
self
.
_importCatalogLanguage
(
localizer
,
catalog
,
lang
,
po
)
if
lang
not
in
localizer
.
get_languages
():
localizer
.
manage_addLanguage
(
lang
)
else
:
po
=
self
.
_objects
[
key
]
if
lang
not
in
localizer
.
get_languages
():
localizer
.
manage_addLanguage
(
lang
)
self
.
_importCatalogLanguage
(
localizer
,
catalog
,
lang
,
po
)
def
uninstall
(
self
,
context
,
remove_translations
=
False
,
**
kw
):
def
uninstall
(
self
,
context
,
remove_translations
=
False
,
**
kw
):
if
not
remove_translations
:
if
not
remove_translations
:
...
...
product/ERP5/Tool/TemplateTool.py
View file @
020473fa
...
@@ -307,42 +307,41 @@ class TemplateTool (BaseTool):
...
@@ -307,42 +307,41 @@ class TemplateTool (BaseTool):
file
.
seek
(
0
)
file
.
seek
(
0
)
magic
=
file
.
read
(
5
)
magic
=
file
.
read
(
5
)
if
1
:
# XXX: should really check for a magic and offer a falback if it
# XXX: should really check for a magic and offer a falback if it
# doens't correspond to anything handled.
# doens't correspond to anything handled.
tar
=
tarfile
.
open
(
path
,
'r:gz'
)
tar
=
tarfile
.
open
(
path
,
'r:gz'
)
dir_name
=
tar
.
members
[
0
].
name
.
split
(
posixpath
.
sep
,
1
)[
0
]
dir_name
=
tar
.
members
[
0
].
name
.
split
(
posixpath
.
sep
,
1
)[
0
]
try
:
try
:
# create bt object
# create bt object
bt
=
self
.
newContent
(
portal_type
=
'Business Template'
,
id
=
id
)
bt
=
self
.
newContent
(
portal_type
=
'Business Template'
,
id
=
id
)
prop_dict
=
{}
prop_dict
=
{}
for
prop
in
bt
.
propertyMap
():
for
prop
in
bt
.
propertyMap
():
prop_type
=
prop
[
'type'
]
prop_type
=
prop
[
'type'
]
pid
=
prop
[
'id'
]
pid
=
prop
[
'id'
]
prop_path
=
posixpath
.
join
(
dir_name
,
'bt'
,
pid
)
prop_path
=
posixpath
.
join
(
dir_name
,
'bt'
,
pid
)
try
:
try
:
info
=
tar
.
getmember
(
prop_path
)
info
=
tar
.
getmember
(
prop_path
)
value
=
tar
.
extractfile
(
info
).
read
()
value
=
tar
.
extractfile
(
info
).
read
()
except
KeyError
:
except
KeyError
:
value
=
None
value
=
None
if
value
is
'None'
:
if
value
is
'None'
:
# At export time, we used to export non-existent properties:
# At export time, we used to export non-existent properties:
# str(obj.getProperty('non-existing')) == 'None'
# str(obj.getProperty('non-existing')) == 'None'
# Discard them
# Discard them
continue
continue
if
prop_type
in
(
'text'
,
'string'
):
if
prop_type
in
(
'text'
,
'string'
):
prop_dict
[
pid
]
=
value
or
''
prop_dict
[
pid
]
=
value
or
''
elif
prop_type
in
(
'int'
,
'boolean'
):
elif
prop_type
in
(
'int'
,
'boolean'
):
prop_dict
[
pid
]
=
value
or
0
prop_dict
[
pid
]
=
value
or
0
elif
prop_type
in
(
'lines'
,
'tokens'
):
elif
prop_type
in
(
'lines'
,
'tokens'
):
prop_dict
[
pid
[:
-
5
]]
=
(
value
or
''
).
splitlines
()
prop_dict
[
pid
[:
-
5
]]
=
(
value
or
''
).
splitlines
()
prop_dict
.
pop
(
'id'
,
''
)
prop_dict
.
pop
(
'id'
,
''
)
bt
.
edit
(
**
prop_dict
)
bt
.
edit
(
**
prop_dict
)
# import all other files from bt
# import all other files from bt
with
open
(
path
,
'rb'
)
as
fobj
:
with
open
(
path
,
'rb'
)
as
fobj
:
bt
.
importFile
(
file
=
fobj
)
bt
.
importFile
(
file
=
fobj
)
finally
:
finally
:
tar
.
close
()
tar
.
close
()
return
bt
return
bt
security
.
declareProtected
(
Permissions
.
ManagePortal
,
'manage_download'
)
security
.
declareProtected
(
Permissions
.
ManagePortal
,
'manage_download'
)
...
...
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