Commit 020473fa authored by Arnaud Fontaine's avatar Arnaud Fontaine

Reindent code following removal of Business Template format version 0.

parent c1746228
This diff is collapsed.
...@@ -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' )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment