for bible
[wolnelektury.git] / src / annoy / migrations / 0014_fundraising.py
1 # Generated by Django 4.0.8 on 2023-08-02 19:58
2 import hashlib
3 import json
4 from django.conf import settings
5 from django.db import migrations
6
7
8 def migrate_fundraising(apps, schema_editor):
9     MIS = apps.get_model('annoy', 'MediaInsertSet')
10     EF = getattr(settings, 'EPUB_FUNDRAISING', None)
11     if not EF:
12         return
13     etag = hashlib.sha1(json.dumps(EF).encode('utf-8')).hexdigest()
14     for f in ('epub', 'mobi'):
15         mis = MIS.objects.create(file_format=f, etag=etag)
16         for i, t in enumerate(EF):
17             mis.mediainserttext_set.create(ordering=i+1, text=t)
18
19
20 class Migration(migrations.Migration):
21
22     dependencies = [
23         ('annoy', '0013_mediainsertset_mediainserttext'),
24     ]
25
26     operations = [
27         migrations.RunPython(
28             migrate_fundraising,
29             migrations.RunPython.noop
30         )
31     ]