How to use the wagtailmedia.models.Media.objects function in wagtailmedia

To help you get started, we’ve selected a few wagtailmedia examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github praekeltfoundation / molo / molo / core / migrations / 0068_media_migration.py View on Github external
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()
github praekeltfoundation / molo / molo / core / migrations / 0001_squashed_0077_molo_page.py View on Github external
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()