# Path: cpm_generic/migration_utils.py
# def get_image(apps, title, filepath):
#     """Get image object from a local file."""
# 
#     Image = get_image_model(apps)
#     Collection = apps.get_model('wagtailcore.Collection')
#     collection_id = Collection.objects.filter(depth=1)[0]
# 
#     image = Image(title=title, collection=collection_id)
#     with open(filepath, 'rb') as image_file:
#         image.file.save(name=os.path.basename(filepath),
#                         content=File(image_file))
#         image.save()
# 
#     return image


import os
from django.db import migrations
from cpm_generic.migration_utils import get_image
# -*- coding: utf-8 -*-
from __future__ import unicode_literals





def update_pavel_ivanov(apps, schema_editor):
    JuryMember = apps.get_model('cpm_data.JuryMember')

    try:
        pavel_ivanov = JuryMember.objects.get(name_en='Pavel Ivanov')
    except JuryMember.DoesNotExist:
        pass
    else:
        this_dir = os.path.dirname(__file__)
        filepath = os.path.join(this_dir, '0013', 'Pavel Ivanov.jpg')


# Path: cpm_generic/migration_utils.py
# def get_image(apps, title, filepath):
#     """Get image object from a local file."""
# 
#     Image = get_image_model(apps)
#     Collection = apps.get_model('wagtailcore.Collection')
#     collection_id = Collection.objects.filter(depth=1)[0]
# 
#     image = Image(title=title, collection=collection_id)
#     with open(filepath, 'rb') as image_file:
#         image.file.save(name=os.path.basename(filepath),
#                         content=File(image_file))
#         image.save()
# 
#     return image


# Path: cpm_data/migrations/0013_update_jury_pavel_ivanov.py
import os
from django.db import migrations
from cpm_generic.migration_utils import get_image

# -*- coding: utf-8 -*-
from __future__ import unicode_literals





def update_pavel_ivanov(apps, schema_editor):
    JuryMember = apps.get_model('cpm_data.JuryMember')

    try:
        pavel_ivanov = JuryMember.objects.get(name_en='Pavel Ivanov')
    except JuryMember.DoesNotExist:
        pass
    else:
        this_dir = os.path.dirname(__file__)
        filepath = os.path.join(this_dir, '0013', 'Pavel Ivanov.jpg')


        new_photo = get_image(apps, 'Pavel Ivanov', filepath)