Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 658 lines (549 sloc) 26.263 kb
5413fc3 @garbas export script for plone2.0
garbas authored
1 ###############################################################################
2 ##### #####
3 ##### IMPORTANT, READ THIS !!! #####
4 ##### ------------------------ #####
5 ##### #####
6 ##### Bellow is the external method which you enable by adding it #####
7 ##### into your Plone site. #####
8 ##### #####
9 ###############################################################################
10
11 import os
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
12 import shutil
5413fc3 @garbas export script for plone2.0
garbas authored
13 import simplejson
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
14 from datetime import datetime
5413fc3 @garbas export script for plone2.0
garbas authored
15 from Acquisition import aq_base
16 from Products.CMFCore.utils import getToolByName
17
18 COUNTER = 1
a3c13be @garbas plonearticle attachement and images exported to json and prepared for…
garbas authored
19 HOMEDIR = '/Users/rok/Projects/yaco/unex_exported_data'
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
20 CLASSNAME_TO_SKIP_LAUD = ['ControllerPythonScript',
ece84a1 @garbas additional ignores
garbas authored
21 'ControllerPageTemplate', 'ControllerValidator', 'PythonScript', 'SQL', 'Connection',
22 'ZetadbScript', 'ExternalMethod', 'ZetadbSqlInsert', 'ZetadbMysqlda', 'SiteRoot',
5ff5a86 @msaelices Add new types to skip loudly.
msaelices authored
23 'ZetadbApplication', 'ZetadbZptInsert', 'I18NLayer', 'ZetadbZptView', 'BrowserIdManager',
24 'ZetadbScriptSelectMaster', 'ZetadbSqlSelect', ]
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
25 CLASSNAME_TO_SKIP = ['CatalogTool', 'MemberDataTool', 'SkinsTool', 'TypesTool',
26 'UndoTool', 'URLTool', 'WorkflowTool', 'DiscussionTool', 'MembershipTool',
27 'RegistrationTool', 'PropertiesTool', 'MetadataTool', 'SyndicationTool',
28 'PloneTool', 'NavigationTool', 'FactoryTool', 'FormTool', 'MigrationTool',
29 'CalendarTool', 'QuickInstallerTool', 'GroupsTool', 'GroupDataTool', 'MailHost',
30 'CookieCrumbler', 'ContentTypeRegistry', 'GroupUserFolder', 'CachingPolicyManager',
31 'InterfaceTool', 'PloneControlPanel', 'FormController', 'SiteErrorLog', 'SinTool',
32 'ArchetypeTool', 'RAMCacheManager', 'PloneArticleTool', 'SyndicationInformation',
ece84a1 @garbas additional ignores
garbas authored
33 'ActionIconsTool', 'AcceleratedHTTPCacheManager', 'ActionsTool', 'UIDCatalog',
9b3b01e skiping other classes
Pablo Caro Revuelta authored
34 'ReferenceCatalog', 'ContentPanelsTool', 'MimeTypesRegistry', 'LanguageTool',
35 'TransformTool']
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
36 ID_TO_SKIP = ['Members', ]
5413fc3 @garbas export script for plone2.0
garbas authored
37
38
39 def export_plone20(self):
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
40
5413fc3 @garbas export script for plone2.0
garbas authored
41 global COUNTER
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
42 global TMPDIR
43 global ID_TO_SKIP
44
5413fc3 @garbas export script for plone2.0
garbas authored
45 COUNTER = 1
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
46 TODAY = datetime.today()
ece84a1 @garbas additional ignores
garbas authored
47 TMPDIR = HOMEDIR+'/content_'+self.getId()+'_'+TODAY.strftime('%Y-%m-%d-%H-%M-%S')
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
48
ece84a1 @garbas additional ignores
garbas authored
49 id_to_skip = self.REQUEST.get('id_to_skip', None)
50 if id_to_skip is not None:
51 ID_TO_SKIP += id_to_skip.split(',')
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
52
53 if os.path.isdir(TMPDIR):
54 shutil.rmtree(TMPDIR)
55 else:
56 os.mkdir(TMPDIR)
5413fc3 @garbas export script for plone2.0
garbas authored
57
58 write(walk(self))
59
60 # TODO: we should return something more useful
ece84a1 @garbas additional ignores
garbas authored
61 return 'SUCCESS :: '+self.absolute_url()+'\n'
5413fc3 @garbas export script for plone2.0
garbas authored
62
63
64 def walk(folder):
65 for item_id in folder.objectIds():
66 item = folder[item_id]
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
67 if item.__class__.__name__ in CLASSNAME_TO_SKIP or \
68 item.getId() in ID_TO_SKIP:
69 continue
70 if item.__class__.__name__ in CLASSNAME_TO_SKIP_LAUD:
71 print '>> SKIPPING :: ['+item.__class__.__name__+'] '+item.absolute_url()
72 continue
5413fc3 @garbas export script for plone2.0
garbas authored
73 yield item
74 if getattr(item, 'objectIds', None) and \
75 item.objectIds():
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
76 for subitem in walk(item):
5413fc3 @garbas export script for plone2.0
garbas authored
77 yield subitem
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
78
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
79
6f25f86 @garbas wrong renaming
garbas authored
80 def write(items):
5413fc3 @garbas export script for plone2.0
garbas authored
81 global COUNTER
82
83 for item in items:
84 if item.__class__.__name__ not in CLASSNAME_TO_WAPPER_MAP.keys():
ece84a1 @garbas additional ignores
garbas authored
85 import pdb; pdb.set_trace()
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
86 raise Exception, 'No wrapper defined for "'+item.__class__.__name__+ \
5413fc3 @garbas export script for plone2.0
garbas authored
87 '" ('+item.absolute_url()+').'
9b3b01e skiping other classes
Pablo Caro Revuelta authored
88 try:
89 dictionary = CLASSNAME_TO_WAPPER_MAP[item.__class__.__name__](item)
90 write_to_jsonfile(dictionary)
91 COUNTER += 1
92 except:
93 import pdb; pdb.set_trace()
5413fc3 @garbas export script for plone2.0
garbas authored
94
95
6f25f86 @garbas wrong renaming
garbas authored
96 def write_to_jsonfile(item):
5413fc3 @garbas export script for plone2.0
garbas authored
97 global COUNTER
98
99 SUB_TMPDIR = os.path.join(TMPDIR, str(COUNTER/1000)) # 1000 files per folder, so we dont reach some fs limit
100 if not os.path.isdir(SUB_TMPDIR):
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
101 os.mkdir(SUB_TMPDIR)
5413fc3 @garbas export script for plone2.0
garbas authored
102
103 # we store data fields in separate files
104 datafield_counter = 1
105 if '__datafields__' in item.keys():
106 for datafield in item['__datafields__']:
d80baee @garbas first attempt of code
garbas authored
107 datafield_filepath = os.path.join(SUB_TMPDIR, str(COUNTER)+'.json-file-'+str(datafield_counter))
5413fc3 @garbas export script for plone2.0
garbas authored
108 f = open(datafield_filepath, 'wb')
109 f.write(item[datafield])
d80baee @garbas first attempt of code
garbas authored
110 item[datafield] = os.path.join(str(COUNTER/1000), str(COUNTER)+'.json-file-'+str(datafield_counter))
5413fc3 @garbas export script for plone2.0
garbas authored
111 f.close()
112 datafield_counter += 1
893267a Begining to export I18NLayer. Not running (skipping yet).
Pablo Caro Revuelta authored
113 item.pop(u'__datafields__')
98e343b @garbas plonearticle export ready for blueprint, fix of LinkWrapper
garbas authored
114 if '_plonearticle_attachments' in item:
115 for item2 in item['_plonearticle_attachments']:
116 datafield_filepath = os.path.join(SUB_TMPDIR, str(COUNTER)+'.json-file-'+str(datafield_counter))
117 f = open(datafield_filepath, 'wb')
118 f.write(item2['attachedFile'][0])
119 item2['attachedFile'][0] = os.path.join(str(COUNTER/1000), str(COUNTER)+'.json-file-'+str(datafield_counter))
120 f.close()
121 datafield_counter += 1
122 if '_plonearticle_images' in item:
123 for item2 in item['_plonearticle_images']:
124 datafield_filepath = os.path.join(SUB_TMPDIR, str(COUNTER)+'.json-file-'+str(datafield_counter))
125 f = open(datafield_filepath, 'wb')
126 try:
127 f.write(item2['attachedImage'][0])
128 except:
129 import pdb; pdb.set_trace()
130 item2['attachedImage'][0] = os.path.join(str(COUNTER/1000), str(COUNTER)+'.json-file-'+str(datafield_counter))
131 f.close()
132 datafield_counter += 1
5413fc3 @garbas export script for plone2.0
garbas authored
133
134 f = open(os.path.join(SUB_TMPDIR, str(COUNTER)+'.json'), 'wb')
135 simplejson.dump(item, f, indent=4)
136 f.close()
137
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
138
5413fc3 @garbas export script for plone2.0
garbas authored
139 def getPermissionMapping(acperm):
140 result = {}
141 for entry in acperm:
142 result[entry[0]] = entry[1]
143 return result
144
145
146 class BaseWrapper(dict):
147 """Wraps the dublin core metadata and pass it as tranmogrifier friendly style
148 """
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
149
5413fc3 @garbas export script for plone2.0
garbas authored
150 def __init__(self, obj):
151 self.obj = obj
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
152
5413fc3 @garbas export script for plone2.0
garbas authored
153 self.portal = getToolByName(obj, 'portal_url').getPortalObject()
154 self.portal_utils = getToolByName(obj, 'plone_utils')
155 self.charset = self.portal.portal_properties.site_properties.default_charset
156
157 if not self.charset: # newer seen it missing ... but users can change it
158 self.charset = 'utf-8'
159
160 self['__datafields__'] = []
e1996c3 @garbas added partialcommit blueprint, add check of file size in DataFields b…
garbas authored
161 self['_path'] = '/'.join(self.obj.getPhysicalPath())
5413fc3 @garbas export script for plone2.0
garbas authored
162
163 self['_type'] = self.obj.__class__.__name__
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
164
5413fc3 @garbas export script for plone2.0
garbas authored
165 self['id'] = obj.getId()
166 self['title'] = obj.title.decode(self.charset, 'ignore')
167 self['description'] = obj.description.decode(self.charset, 'ignore')
a9ac787 @enriquepablo finish the export of Dublin Core metadata
enriquepablo authored
168 self['language'] = obj.language
169 self['rights'] = obj.rights.decode(self.charset, 'ignore')
170 # for DC attrs that are tuples
171 for attr in ('subject', 'contributors'):
172 self[attr] = []
173 val_tuple = getattr(obj, attr, False)
174 if val_tuple:
175 for val in val_tuple:
176 self[attr].append(val.decode(self.charset, 'ignore'))
177 self[attr] = tuple(self[attr])
178 # for DC attrs that are DateTimes
179 datetimes_dict = {'creation_date': 'creation_date',
180 'modification_date': 'modification_date',
181 'expiration_date': 'expirationDate',
182 'effective_date': 'effectiveDate'}
183 for old_name, new_name in datetimes_dict.items():
184 val = getattr(obj, old_name, False)
185 if val:
186 self[new_name] = str(val)
5413fc3 @garbas export script for plone2.0
garbas authored
187
188 # workflow history
189 if hasattr(obj, 'workflow_history'):
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
190 workflow_history = obj.workflow_history.data
191 try:
192 for w in workflow_history:
193 for i, w2 in enumerate(workflow_history[w]):
194 workflow_history[w][i]['time'] = str(workflow_history[w][i]['time'])
195 workflow_history[w][i]['comments'] = workflow_history[w][i]['comments'].decode(self.charset, 'ignore')
196 except:
197 import pdb; pdb.set_trace()
198 self['_workflow_history'] = workflow_history
5413fc3 @garbas export script for plone2.0
garbas authored
199
200 # default view
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
201 _browser = '/'.join(self.portal_utils.browserDefault(aq_base(obj))[1])
5413fc3 @garbas export script for plone2.0
garbas authored
202 if _browser not in ['folder_listing']:
203 self['_layout'] = ''
204 self['_defaultpage'] = _browser
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
205 #elif obj.getId() != 'index_html':
206 # self['_layout'] = _browser
207 # self['_defaultpage'] = ''
5413fc3 @garbas export script for plone2.0
garbas authored
208
209 # format
210 self['_content_type'] = obj.Format()
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
211
212 # properties
5413fc3 @garbas export script for plone2.0
garbas authored
213 self['_properties'] = []
214 if getattr(aq_base(obj), 'propertyIds', False):
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
215 obj_base = aq_base(obj)
216 for pid in obj_base.propertyIds():
217 val = obj_base.getProperty(pid)
218 typ = obj_base.getPropertyType(pid)
5413fc3 @garbas export script for plone2.0
garbas authored
219 if typ == 'string':
220 if getattr(val, 'decode', False):
221 try:
222 val = val.decode(self.charset, 'ignore')
223 except UnicodeEncodeError:
224 val = unicode(val)
225 else:
226 val = unicode(val)
227 self['_properties'].append((pid, val,
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
228 obj_base.getPropertyType(pid)))
5413fc3 @garbas export script for plone2.0
garbas authored
229
230 # local roles
231 self['_ac_local_roles'] = {}
232 if getattr(obj, '__ac_local_roles__', False):
233 for key, val in obj.__ac_local_roles__.items():
234 if key is not None:
235 self['_ac_local_roles'][key] = val
236
237 self['_userdefined_roles'] = ()
238 if getattr(aq_base(obj), 'userdefined_roles', False):
239 self['_userdefined_roles'] = obj.userdefined_roles()
240
c3a198c @enriquepablo proper extraction of permission/role mappings for each object
enriquepablo authored
241 self['_permission_mapping'] = {}
242 if getattr(aq_base(obj), 'permission_settings', False):
243 roles = obj.validRoles()
244 ps = obj.permission_settings()
245 for perm in ps:
a581a23 @enriquepablo import of permission/role mappings for each object
enriquepablo authored
246 unchecked = 0
c3a198c @enriquepablo proper extraction of permission/role mappings for each object
enriquepablo authored
247 if not perm['acquire']:
a581a23 @enriquepablo import of permission/role mappings for each object
enriquepablo authored
248 unchecked = 1
c3a198c @enriquepablo proper extraction of permission/role mappings for each object
enriquepablo authored
249 new_roles = []
250 for role in perm['roles']:
251 if role['checked']:
252 role_idx = role['name'].index('r')+1
253 role_name = roles[int(role['name'][role_idx:])]
254 new_roles.append(role_name)
255 if unchecked or new_roles:
256 self['_permission_mapping'][perm['name']] = \
257 {'acquire': not unchecked,
258 'roles': new_roles}
259
260 # self['_ac_inherited_permissions'] = {}
261 # if getattr(aq_base(obj), 'ac_inherited_permissions', False):
262 # oldmap = getPermissionMapping(obj.ac_inherited_permissions(1))
263 # for key, values in oldmap.items():
264 # old_p = Permission(key, values, obj)
265 # self['_ac_inherited_permissions'][key] = old_p.getRoles()
5413fc3 @garbas export script for plone2.0
garbas authored
266
267 if getattr(aq_base(obj), 'getWrappedOwner', False):
268 self['_owner'] = (1, obj.getWrappedOwner().getId())
269 else:
270 # fallback
271 # not very nice but at least it works
272 # trying to get/set the owner via getOwner(), changeOwnership(...)
273 # did not work, at least not with plone 1.x, at 1.0.1, zope 2.6.2
274 self['_owner'] = (0, obj.getOwner(info = 1).getId())
275
9b3b01e skiping other classes
Pablo Caro Revuelta authored
276 def decode(self, s, encodings=('utf8', 'latin1', 'ascii')):
277 if self.charset:
278 test_encodings = (self.charset, ) + encodings
279 for encoding in test_encodings:
280 try:
281 return s.decode(encoding)
282 except UnicodeDecodeError:
283 pass
284 return s.decode(test_encodings[0], 'ignore')
285
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
286
5413fc3 @garbas export script for plone2.0
garbas authored
287 class DocumentWrapper(BaseWrapper):
288
289 def __init__(self, obj):
290 super(DocumentWrapper, self).__init__(obj)
291 self['text'] = obj.text.decode(self.charset, 'ignore')
292
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
293
294 class I18NFolderWrapper(BaseWrapper):
295
296 def __init__(self, obj):
297 super(I18NFolderWrapper, self).__init__(obj)
298 # We are ignoring another languages
299 lang = obj.getDefaultLanguage()
300 data = obj.folder_languages.get(lang, None)
301 if data is not None:
302 self['title'] = data['title'].decode(self.charset, 'ignore')
303 self['description'] = data['description'].decode(self.charset, 'ignore')
304 else:
305 print 'ERROR: Cannot get default data for I18NFolder "%s"' % self['_path']
306
307 # delete empty title in properties
308 for prop in self['_properties']:
309 propname, propvalue, proptitle = prop
310 if propname == "title":
311 self['_properties'].remove(prop)
312
313
314 # Not lose information: generate properites es_title, en_title, etc.
315 for lang in obj.folder_languages:
316 data = obj.folder_languages[lang]
317 for field in data:
318 self['_properties'].append(['%s_%s' % (lang, field),
319 data[field].decode(self.charset, 'ignore'),
320 'text'])
321
322
5413fc3 @garbas export script for plone2.0
garbas authored
323 class LinkWrapper(BaseWrapper):
324
325 def __init__(self, obj):
326 super(LinkWrapper, self).__init__(obj)
98e343b @garbas plonearticle export ready for blueprint, fix of LinkWrapper
garbas authored
327 self['remoteUrl'] = obj.remote_url
5413fc3 @garbas export script for plone2.0
garbas authored
328
329
330 class NewsItemWrapper(DocumentWrapper):
331
332 def __init__(self, obj):
333 super(NewsItemWrapper, self).__init__(obj)
334 self['text_format'] = obj.text_format
335
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
336
5413fc3 @garbas export script for plone2.0
garbas authored
337 class ListCriteriaWrapper(BaseWrapper):
338
339 def __init__(self, obj):
340 super(ListCriteriaWrapper, self).__init__(obj)
341 self['field'] = obj.field
342 self['value'] = obj.value
343 self['operator'] = obj.operator
344
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
345
5413fc3 @garbas export script for plone2.0
garbas authored
346 class StringCriteriaWrapper(BaseWrapper):
347
348 def __init__(self, obj):
349 super(StringCriteriaWrapper, self).__init__(obj)
350 self['field'] = obj.field
351 self['value'] = obj.value
352
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
353
5413fc3 @garbas export script for plone2.0
garbas authored
354 class SortCriteriaWrapper(BaseWrapper):
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
355
5413fc3 @garbas export script for plone2.0
garbas authored
356 def __init__(self, obj):
357 super(SortCriteriaWrapper, self).__init__(obj)
358 self['index'] = obj.index
359 self['reversed'] = obj.reversed
360
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
361
5413fc3 @garbas export script for plone2.0
garbas authored
362 class DateCriteriaWrapper(BaseWrapper):
363
364 def __init__(self, obj):
365 super(DateCriteriaWrapper, self).__init__(obj)
366 self['field'] = obj.field
367 self['value'] = obj.value
368 self['operation'] = obj.operation
369 self['daterange'] = obj.daterange
370
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
371
5413fc3 @garbas export script for plone2.0
garbas authored
372 class FileWrapper(BaseWrapper):
373
374 def __init__(self, obj):
375 super(FileWrapper, self).__init__(obj)
d80baee @garbas first attempt of code
garbas authored
376 self['__datafields__'].append('_datafield_file')
377 data = str(obj.data)
378 if len(data) != obj.getSize():
379 raise Exception, 'Problem while extracting data for File content type at '+obj.absolute_url()
380 self['_datafield_file'] = data
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
381
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
382
d80baee @garbas first attempt of code
garbas authored
383 class ImageWrapper(BaseWrapper):
384
385 def __init__(self, obj):
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
386 super(ImageWrapper, self).__init__(obj)
d80baee @garbas first attempt of code
garbas authored
387 self['__datafields__'].append('_datafield_image')
388 data = str(obj.data)
389 if len(data) != obj.getSize():
390 raise Exception, 'Problem while extracting data for Image content type at '+obj.absolute_url()
391 self['_datafield_image'] = data
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
392
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
393
5413fc3 @garbas export script for plone2.0
garbas authored
394 class EventWrapper(BaseWrapper):
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
395
5413fc3 @garbas export script for plone2.0
garbas authored
396 def __init__(self, obj):
397 super(EventWrapper, self).__init__(obj)
bc364ba @enriquepablo CMFEvents were not being correctly exported, (if we are gonna use col…
enriquepablo authored
398 self['startDate'] = str(obj.start_date)
399 self['endDate'] = str(obj.end_date)
5413fc3 @garbas export script for plone2.0
garbas authored
400 self['location'] = obj.location.decode(self.charset, 'ignore')
bc364ba @enriquepablo CMFEvents were not being correctly exported, (if we are gonna use col…
enriquepablo authored
401 self['contactName'] = obj.contact_name.decode(self.charset, 'ignore')
402 self['contactEmail'] = obj.contact_email
403 self['contactPhone'] = obj.contact_phone
404 self['eventUrl'] = obj.event_url
5413fc3 @garbas export script for plone2.0
garbas authored
405
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
406
5413fc3 @garbas export script for plone2.0
garbas authored
407 class ArchetypesWrapper(BaseWrapper):
408
409 def __init__(self, obj):
410 super(ArchetypesWrapper, self).__init__(obj)
411
412 fields = obj.schema.fields()
413 for field in fields:
414 type_ = field.__class__.__name__
415 if type_ in ['StringField', 'BooleanField', 'LinesField', 'IntegerField', 'TextField',
461f2db @enriquepablo this was wrong
enriquepablo authored
416 'SimpleDataGridField', 'FloatField', 'FixedPointField']:
5413fc3 @garbas export script for plone2.0
garbas authored
417 try:
418 value = field.get(obj)
419 except:
420 try:
421 value = field.getRaw(obj)
422 except:
423 if field.getStorage().__class__.__name__ == 'PostgreSQLStorage':
424 continue
425 else:
426 import pdb; pdb.set_trace()
427 if callable(value) is True:
428 value = value()
429 if value:
430 self[unicode(field.__name__)] = value
431 elif type_ in ['TALESString', 'ZPTField']:
432 value = field.getRaw(obj)
433 if value:
434 self[unicode(field.__name__)] = value
435 elif type_ in ['DateTimeField']:
436 value = str(field.get(obj))
437 if value:
438 self[unicode(field.__name__)] = value
439 elif type_ in ['ReferenceField']:
440 value = field.get(obj)
441 if value:
442 if field.multiValued:
443 self[unicode(field.__name__)] = ['/'+i.absolute_url() for i in value]
444 else:
445 self[unicode(field.__name__)] = value.absolute_url()
446 elif type_ in ['ImageField', 'FileField']:
447 fieldname = unicode('_data_'+field.__name__)
448 value = field.get(obj)
449 value2 = value
450 if type(value) is not str:
451 value = str(value.data)
452 if value:
453 size = value2.getSize()
454 self['__datafields__'].append(fieldname)
455 self[fieldname] = {
456 'data': value,
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
457 'size': size, }
5413fc3 @garbas export script for plone2.0
garbas authored
458 elif type_ in ['ComputedField']:
459 pass
460 else:
461 raise 'Unknown field type for ArchetypesWrapper.'
462
463 def _guessFilename(self, data, fname='', mimetype='', default=''):
464 """
465 Use the mimetype to guess the extension of the file/datafield if none exists.
466 This is not a 100% correct, but does not really matter.
467 In most cases it is nice that a word document has the doc extension, or that a picture has jpeg or bmp.
468 It is a bit more human readable. When the extension is wrong it can just be ignored by the import anyway.
469 """
470 if not fname:
471 return fname
472 obj = self.obj
473 mimetool = getToolByName(obj, 'mimetypes_registry')
474 imimetype = mimetool.lookupExtension(fname)
475 if mimetype and (imimetype is None): # no valid extension on fname
476 # find extensions for mimetype
477 classification = mimetool.classify(data, mimetype=mimetype)
478 extensions = getattr(classification, 'extensions', default)
479 extension = extensions[0] # just take the first one ... :-s
480 fname = '%s.%s' % (fname, extension)
481 return fname
482
9b3b01e skiping other classes
Pablo Caro Revuelta authored
483
893267a Begining to export I18NLayer. Not running (skipping yet).
Pablo Caro Revuelta authored
484 class I18NLayerWrapper(ArchetypesWrapper):
485
486 def __init__(self, obj):
487 super(I18NLayerWrapper, self).__init__(obj)
488 lang = obj.portal_properties.site_properties.default_language
489 if lang not in obj.objectIds():
490 print 'ERROR: Cannot get default data for I18NLayer "%s"' % self['_path']
491 else:
492 real = obj[lang]
493 self['title'] = real.title.decode(self.charset, 'ignore')
494 self['description'] = real.description.decode(self.charset, 'ignore')
495 self['text'] = real.text.decode(self.charset, 'ignore')
496
497 # Not lose information: generate properites es_title, en_title, etc.
498 # TODO: Export all archetypes, but I don't need now, only document important fields
499 for lang, content in obj.objectItems():
500 data = dict(title = content.title,
501 description = content.description,
502 text = content.text)
503 for field in data:
504 self['_properties'].append(['%s_%s' % (lang, field),
505 data[field].decode(self.charset, 'ignore'),
506 'text'])
507
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
508
5413fc3 @garbas export script for plone2.0
garbas authored
509 class ArticleWrapper(NewsItemWrapper):
510
511 def __init__(self, obj):
512 super(ArticleWrapper, self).__init__(obj)
513 try:
514 self['cooked_text'] = obj.cooked_text.decode(self.charset)
515 except:
516 self['cooked_text'] = obj.cooked_text.decode('latin-1')
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
517
98e343b @garbas plonearticle export ready for blueprint, fix of LinkWrapper
garbas authored
518 plonearticle_attachments = []
519 for item_id in obj.attachments_ids:
520 item = obj[item_id]
521 plonearticle_attachments.append({
522 'id': (item_id, {}),
523 'title': (item.title.decode(self.charset, 'ignore'), {}),
524 'description': (item.description.decode(self.charset, 'ignore'), {}),
525 'attachedFile': [item.getFile(), {}],
526 })
527 self['_plonearticle_attachments'] = plonearticle_attachments
528
529 plonearticle_images = []
530 for item_id in obj.images_ids:
531 item = obj[item_id]
532 plonearticle_images.append({
533 'id': (item_id, {}),
534 'title': (item.title.decode(self.charset, 'ignore'), {}),
535 'description': (item.description.decode(self.charset, 'ignore'), {}),
536 'attachedImage': [str(item.data), {}],
537 })
538 self['_plonearticle_images'] = plonearticle_images
5413fc3 @garbas export script for plone2.0
garbas authored
539
540
541 class ZPhotoWrapper(BaseWrapper):
542
543 def __init__(self, obj):
544 super(ZPhotoWrapper, self).__init__(obj)
545 self['show_exif'] = obj.show_exif
546 self['exif'] = obj.exif
547 self['iptc'] = obj.iptc
548 self['path'] = obj.path
549 self['dir'] = obj.dir
550 self['filename'] = obj.filename
551 #self['_thumbs'] = obj._thumbs
552 self['dict_info'] = obj.dict_info
553 self['format'] = obj.format
554 self['tmpdir'] = obj.tmpdir
555 self['backup'] = obj.backup
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
556
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
557
5413fc3 @garbas export script for plone2.0
garbas authored
558 class ZPhotoSlidesWrapper(BaseWrapper):
559
560 def __init__(self, obj):
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
561 super(ZPhotoSlidesWrapper, self).__init__(obj)
562 try:
563 self['update_date'] = str(obj.update_date)
564 self['show_postcard'] = obj.show_postcard
565 self['show_ARpostcard'] = obj.show_ARpostcard
566 self['show_rating'] = obj.show_rating
567 self['size'] = obj.size
568 self['max_size'] = obj.max_size
569 self['sort_field'] = obj.sort_field
570 self['allow_export'] = obj.allow_export
571 self['show_export'] = obj.show_export
572 #self['visits_log'] = obj.visits_log
573 self['non_hidden_pic'] = obj.non_hidden_pic
574 self['list_non_hidden_pic'] = obj.list_non_hidden_pic
575 self['rows'] = obj.rows
576 self['column'] = obj.column
577 self['zphoto_header'] = obj.zphoto_header
578 self['list_photo'] = obj.list_photo
579 self['zphoto_footer'] = obj.zphoto_footer
580 self['symbolic_photo'] = obj.symbolic_photo
581 self['keywords'] = obj.keywords
582 self['first_big'] = obj.first_big
583 self['show_automatic_slide_show'] = obj.show_automatic_slide_show
584 self['show_viewed'] = obj.show_viewed
585 self['show_exif'] = obj.show_exif
586 self['photo_space'] = obj.photo_space
587 self['last_modif'] = str(obj.last_modif)
588 self['show_iptc'] = obj.show_iptc
589 self['formats_available'] = obj.formats_available
590 self['default_photo_size'] = obj.default_photo_size
591 self['formats'] = obj.formats
592 self['actual_css'] = obj.actual_css
593 self['thumb_width'] = obj.thumb_width
594 self['thumb_height'] = obj.thumb_height
595 #self['list_rating'] = obj.list_rating
596 self['photo_folder'] = obj.photo_folder
597 self['tmpdir'] = obj.tmpdir
598 self['lib'] = obj.lib
599 self['convert'] = obj.convert
600 self['use_http_cache'] = obj.use_http_cache
893267a Begining to export I18NLayer. Not running (skipping yet).
Pablo Caro Revuelta authored
601 except Exception:
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
602 import pdb; pdb.set_trace()
5413fc3 @garbas export script for plone2.0
garbas authored
603
604
7587f6f @garbas export of content panels fixed
garbas authored
605 class ContentPanels(BaseWrapper):
606
607 def __init__(self, obj):
608 super(ContentPanels, self).__init__(obj)
609 self['_content_panels'] = obj.panelsConfig
610
611
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
612 class LocalFSWrapper(BaseWrapper):
613
614 def __init__(self, obj):
615 super(LocalFSWrapper, self).__init__(obj)
616 self['basepath'] = obj.basepath
5413fc3 @garbas export script for plone2.0
garbas authored
617
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
618
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
619 class ZopeObjectWrapper(BaseWrapper):
620
621 def __init__(self, obj):
622 super(ZopeObjectWrapper, self).__init__(obj)
9b3b01e skiping other classes
Pablo Caro Revuelta authored
623 self['document_src'] = self.decode(obj.document_src())
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
624 # self['__datafields__'].append('document_src')
5413fc3 @garbas export script for plone2.0
garbas authored
625
626 # TODO: should be also possible to set it with through parameters
627 CLASSNAME_TO_WAPPER_MAP = {
628 'LargePloneFolder': BaseWrapper,
629 'Folder': BaseWrapper,
630 'PloneSite': BaseWrapper,
631 'PloneFolder': BaseWrapper,
632 'Document': DocumentWrapper,
633 'File': FileWrapper,
d80baee @garbas first attempt of code
garbas authored
634 'Image': ImageWrapper,
5413fc3 @garbas export script for plone2.0
garbas authored
635 'Link': LinkWrapper,
636 'Event': EventWrapper,
637 'NewsItem': NewsItemWrapper,
638 'Favorite': LinkWrapper,
639 'Topic': BaseWrapper,
640 'ListCriterion': ListCriteriaWrapper,
641 'SimpleStringCriterion': StringCriteriaWrapper,
642 'SortCriterion': SortCriteriaWrapper,
643 'FriendlyDateCriterion': DateCriteriaWrapper,
644
645 # custom ones
0ffcac3 Better exporting of I18NFolder objects. Code cleaning, better
Pablo Caro Revuelta authored
646 'I18NFolder': I18NFolderWrapper,
893267a Begining to export I18NLayer. Not running (skipping yet).
Pablo Caro Revuelta authored
647 'I18NLayer': I18NLayerWrapper,
5413fc3 @garbas export script for plone2.0
garbas authored
648 'PloneArticle': ArticleWrapper,
649 'ZPhotoSlides': ZPhotoSlidesWrapper,
650 'ZPhoto': ZPhotoWrapper,
651 'PloneLocalFolderNG': ArchetypesWrapper,
11525f1 @garbas export script fixed to working state, also building full path of data…
garbas authored
652 'LocalFS': LocalFSWrapper,
7587f6f @garbas export of content panels fixed
garbas authored
653 'ContentPanels': ContentPanels,
18903a3 Export for dtmlmethod and page template
Pablo Caro Revuelta authored
654 'DTMLMethod': ZopeObjectWrapper,
655 'ZopePageTemplate': ZopeObjectWrapper,
5413fc3 @garbas export script for plone2.0
garbas authored
656
657 }
Something went wrong with that request. Please try again.