add call to convert existing files to blob files

This commit is contained in:
Frédéric Péters 2011-10-18 14:59:19 +02:00
parent 336f494e4d
commit 6cf0433ed0
2 changed files with 22 additions and 0 deletions

View File

@ -35,4 +35,11 @@
permission="cmf.ManagePortal"
/>
<browser:view
name="updatetoblobs"
for="*"
class=".migration.UpdateToBlobs"
permission="cmf.ManagePortal"
/>
</configure>

View File

@ -467,3 +467,18 @@ class FixRelatedDocs(BrowserView):
setattr(object, attr, [v])
class UpdateToBlobs(BrowserView):
def __call__(self):
catalog = getToolByName(self.context, 'portal_catalog')
for brain in catalog.search({'portal_type': ['bqrD', 'bulletintravauxD'}):
object = brain.getObject()
for attr in ("fichier", "document_imprime"):
try:
v = getattr(object, attr)
except AttributeError:
continue
if v is None:
continue
print 'transforming file in', object.id
newv = NamedFile(v.data, filemane=v.filename)
setattr(object, attr, newv)