Created
April 23, 2014 14:29
-
-
Save thet/11217449 to your computer and use it in GitHub Desktop.
plone.app.contenttypes migration helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def attr_migrator(old, new, old_name, new_name): | |
field = old.getField(old_name) | |
if not field: | |
return | |
val = field.get(old) | |
val_str = str(val) | |
if old_name == 'teacher': | |
if not isinstance(val, list): | |
val = [] | |
teachers = [] | |
for it in val: | |
teachers.append(IUUID(it)) | |
val = teachers | |
logger.info( | |
"Migrating attribute: %s, value: %s" % ( | |
new_name, | |
len(val_str) > 10 and '%s...' % val_str[:10] or val_str | |
) | |
) | |
setattr(new, new_name, val) | |
def image_migrator(old, new): | |
# from plone.app.contenttypes.migrate.migration | |
old_image = old.getField('image').get(old) | |
if old_image == '': | |
return | |
filename = safe_unicode(old_image.filename) | |
old_image_data = old_image.data | |
if safe_hasattr(old_image_data, 'data'): | |
old_image_data = old_image_data.data | |
namedblobimage = NamedBlobImage(data=old_image_data, | |
filename=filename) | |
new.image = namedblobimage | |
caption_field = old.getField('imageCaption', None) | |
if caption_field: | |
new.image_caption = safe_unicode(caption_field.get(old)) | |
logger.info("Migrating image %s" % filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment