# Generated by Django 4.0.8 on 2023-08-02 19:58
import hashlib
import json
from django.conf import settings
from django.db import migrations


def migrate_fundraising(apps, schema_editor):
    MIS = apps.get_model('annoy', 'MediaInsertSet')
    EF = getattr(settings, 'EPUB_FUNDRAISING', None)
    if not EF:
        return
    etag = hashlib.sha1(json.dumps(EF).encode('utf-8')).hexdigest()
    for f in ('epub', 'mobi'):
        mis = MIS.objects.create(file_format=f, etag=etag)
        for i, t in enumerate(EF):
            mis.mediainserttext_set.create(ordering=i+1, text=t)


class Migration(migrations.Migration):

    dependencies = [
        ('annoy', '0013_mediainsertset_mediainserttext'),
    ]

    operations = [
        migrations.RunPython(
            migrate_fundraising,
            migrations.RunPython.noop
        )
    ]
