<s> from __future__ import unicode_literals <EOL> from django . db import migrations <EOL> def get_image_permissions ( apps ) : <EOL> Permission = apps . get_model ( '<STR_LIT>' ) <EOL> ContentType = apps . get_model ( '<STR_LIT>' ) <EOL> image_content_type , _created = ContentType . objects . get_or_create ( <EOL> model = '<STR_LIT:image>' , <EOL> app_label = '<STR_LIT>' , <EOL> ) <EOL> return Permission . objects . filter ( <EOL> content_type = image_content_type , <EOL> codename__in = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> def copy_image_permissions_to_collections ( apps , schema_editor ) : <EOL> Collection = apps . get_model ( '<STR_LIT>' ) <EOL> Group = apps . get_model ( '<STR_LIT>' ) <EOL> GroupCollectionPermission = apps . get_model ( '<STR_LIT>' ) <EOL> root_collection = Collection . objects . get ( depth = <NUM_LIT:1> ) <EOL> for permission in get_image_permissions ( apps ) : <EOL> for group in Group . objects . filter ( permissions = permission ) : <EOL> GroupCollectionPermission . objects . create ( <EOL> group = group , <EOL> collection = root_collection , <EOL> permission = permission <EOL> ) <EOL> def remove_image_permissions_from_collections ( apps , schema_editor ) : <EOL> GroupCollectionPermission = apps . get_model ( '<STR_LIT>' ) <EOL> image_permissions = get_image_permissions ( apps ) <EOL> GroupCollectionPermission . objects . filter ( permission__in = image_permissions ) . delete ( ) <EOL> class Migration ( migrations . Migration ) : <EOL> dependencies = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> operations = [ <EOL> migrations . RunPython ( <EOL> copy_image_permissions_to_collections , <EOL> remove_image_permissions_from_collections ) , <EOL> ] </s>
