Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def convert_media_to_molo_media(apps, schema_editor):
db_alias = schema_editor.connection.alias
try:
# Django 1.9
emit_post_migrate_signal(2, False, db_alias)
except TypeError:
# Django < 1.9
try:
# Django 1.8
emit_post_migrate_signal(2, False, 'default', db_alias)
except TypeError: # Django < 1.8
emit_post_migrate_signal([], 2, False, 'default', db_alias)
for media in Media.objects.all():
if media.type == 'video':
new_media = MoloMedia.objects.create(
title=media.title, file=media.file, duration=media.duration,
type=media.type, width=media.width, height=media.height,
thumbnail=media.thumbnail)
else:
new_media = MoloMedia.objects.create(
title=media.title, file=media.file, duration=media.duration,
type=media.type)
media.file = None
media.save()
for article in ArticlePage.objects.all():
for block in article.body:
if block.block_type is 'media' and block.value is media.id:
block.value = new_media.id
article.save()
def convert_media_to_molo_media(apps, schema_editor):
db_alias = schema_editor.connection.alias
try:
# Django 1.9
emit_post_migrate_signal(2, False, db_alias)
except TypeError:
# Django < 1.9
try:
# Django 1.8
emit_post_migrate_signal(2, False, 'default', db_alias)
except TypeError: # Django < 1.8
emit_post_migrate_signal([], 2, False, 'default', db_alias)
from molo.core.models import MoloMedia, ArticlePage
from wagtailmedia.models import Media
for media in Media.objects.all():
if media.type == 'video':
new_media = MoloMedia.objects.create(
title=media.title, file=media.file, duration=media.duration,
type=media.type, width=media.width, height=media.height,
thumbnail=media.thumbnail)
else:
new_media = MoloMedia.objects.create(
title=media.title, file=media.file, duration=media.duration,
type=media.type)
media.file = None
media.save()
for article in ArticlePage.objects.all():
for block in article.body:
if block.block_type is 'media' and block.value is media.id:
block.value = new_media.id
article.save()