Legimi
[redakcja.git] / src / documents / migrations / 0001_initial.py
1 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 """
5 Adds all of the models previously in `catalogue` app.
6 This is purely a state migration. If at any point a decisiion
7 is made to remove previous `catalogue` migrations, this will need
8 to be converted to a real database migration.
9 """
10
11 import datetime
12 from django.conf import settings
13 import django.contrib.auth.models
14 import django.core.files.storage
15 from django.db import migrations, models
16 import django.db.models.deletion
17 import dvcs.models
18
19
20 class Migration(migrations.Migration):
21
22     initial = True
23
24     dependencies = [
25         ('auth', '0011_update_proxy_permissions'),
26         migrations.swappable_dependency(settings.AUTH_USER_MODEL),
27         ('cover', '0002_auto_20191002_1224'),
28         ('catalogue', '0005_auto_20200322_2114'),
29     ]
30
31     _state_operations = [
32         migrations.CreateModel(
33             name='Book',
34             fields=[
35                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
36                 ('title', models.CharField(db_index=True, max_length=255, verbose_name='title')),
37                 ('slug', models.SlugField(max_length=128, unique=True, verbose_name='slug')),
38                 ('public', models.BooleanField(db_index=True, default=True, verbose_name='public')),
39                 ('gallery', models.CharField(blank=True, max_length=255, verbose_name='scan gallery name')),
40                 ('parent_number', models.IntegerField(blank=True, db_index=True, editable=False, null=True, verbose_name='parent number')),
41                 ('_single', models.NullBooleanField(db_index=True, editable=False)),
42                 ('_new_publishable', models.NullBooleanField(editable=False)),
43                 ('_published', models.NullBooleanField(editable=False)),
44                 ('_on_track', models.IntegerField(blank=True, db_index=True, editable=False, null=True)),
45                 ('dc_slug', models.CharField(blank=True, db_index=True, editable=False, max_length=128, null=True)),
46                 ('dc_cover_image', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, to='cover.Image')),
47                 ('parent', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='children', to='documents.Book', verbose_name='parent')),
48             ],
49             options={
50                 'verbose_name': 'book',
51                 'verbose_name_plural': 'books',
52                 'db_table': 'catalogue_book',
53                 'ordering': ['title', 'slug'],
54             },
55         ),
56         migrations.CreateModel(
57             name='BookPublishRecord',
58             fields=[
59                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
60                 ('timestamp', models.DateTimeField(auto_now_add=True, verbose_name='time')),
61                 ('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='publish_log', to='documents.Book', verbose_name='book')),
62                 ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='user')),
63             ],
64             options={
65                 'verbose_name': 'book publish record',
66                 'verbose_name_plural': 'book publish records',
67                 'db_table': 'catalogue_bookpublishrecord',
68                 'ordering': ['-timestamp'],
69             },
70         ),
71         migrations.CreateModel(
72             name='Chunk',
73             fields=[
74                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
75                 ('number', models.IntegerField(verbose_name='number')),
76                 ('title', models.CharField(blank=True, max_length=255, verbose_name='title')),
77                 ('slug', models.SlugField(verbose_name='slug')),
78                 ('gallery_start', models.IntegerField(blank=True, default=1, null=True, verbose_name='gallery start')),
79                 ('_hidden', models.NullBooleanField(editable=False)),
80                 ('_changed', models.NullBooleanField(editable=False)),
81                 ('_new_publishable', models.NullBooleanField(editable=False)),
82                 ('book', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, to='documents.Book', verbose_name='book')),
83                 ('creator', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_chunk', to=settings.AUTH_USER_MODEL, verbose_name='creator')),
84             ],
85             options={
86                 'verbose_name': 'chunk',
87                 'verbose_name_plural': 'chunks',
88                 'db_table': 'catalogue_chunk',
89                 'ordering': ['number'],
90                 'permissions': [('can_pubmark', 'Can mark for publishing')],
91             },
92         ),
93         migrations.CreateModel(
94             name='ChunkChange',
95             fields=[
96                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
97                 ('author_name', models.CharField(blank=True, help_text='Used if author is not set.', max_length=128, null=True, verbose_name='author name')),
98                 ('author_email', models.CharField(blank=True, help_text='Used if author is not set.', max_length=128, null=True, verbose_name='author email')),
99                 ('revision', models.IntegerField(db_index=True, verbose_name='revision')),
100                 ('description', models.TextField(blank=True, default='', verbose_name='description')),
101                 ('created_at', models.DateTimeField(db_index=True, default=datetime.datetime.now, editable=False)),
102                 ('publishable', models.BooleanField(default=False, verbose_name='publishable')),
103                 ('data', models.FileField(storage=django.core.files.storage.FileSystemStorage(location=settings.CATALOGUE_REPO_PATH), upload_to=dvcs.models.data_upload_to, verbose_name='data')),
104                 ('author', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, verbose_name='author')),
105                 ('merge_parent', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='merge_children', to='documents.ChunkChange', verbose_name='merge parent')),
106                 ('parent', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='children', to='documents.ChunkChange', verbose_name='parent')),
107             ],
108             options={
109                 'verbose_name': 'change for: chunk',
110                 'verbose_name_plural': 'changes for: chunk',
111                 'db_table': 'catalogue_chunkchange',
112                 'ordering': ('created_at',),
113                 'abstract': False,
114             },
115         ),
116         migrations.CreateModel(
117             name='ChunkTag',
118             fields=[
119                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
120                 ('name', models.CharField(max_length=64, verbose_name='name')),
121                 ('slug', models.SlugField(blank=True, max_length=64, null=True, unique=True, verbose_name='slug')),
122                 ('ordering', models.IntegerField(verbose_name='ordering')),
123             ],
124             options={
125                 'verbose_name': 'tag for: chunk',
126                 'verbose_name_plural': 'tags for: chunk',
127                 'db_table': 'catalogue_chunktag',
128                 'ordering': ['ordering'],
129                 'abstract': False,
130             },
131         ),
132         migrations.CreateModel(
133             name='Image',
134             fields=[
135                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
136                 ('image', models.FileField(upload_to='catalogue/images', verbose_name='image')),
137                 ('title', models.CharField(blank=True, max_length=255, verbose_name='title')),
138                 ('slug', models.SlugField(unique=True, verbose_name='slug')),
139                 ('public', models.BooleanField(db_index=True, default=True, verbose_name='public')),
140                 ('_new_publishable', models.NullBooleanField(editable=False)),
141                 ('_published', models.NullBooleanField(editable=False)),
142                 ('_changed', models.NullBooleanField(editable=False)),
143                 ('creator', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_image', to=settings.AUTH_USER_MODEL, verbose_name='creator')),
144             ],
145             options={
146                 'verbose_name': 'image',
147                 'verbose_name_plural': 'images',
148                 'db_table': 'catalogue_image',
149                 'ordering': ['title'],
150                 'permissions': [('can_pubmark_image', 'Can mark images for publishing')],
151             },
152         ),
153         migrations.CreateModel(
154             name='ImageChange',
155             fields=[
156                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
157                 ('author_name', models.CharField(blank=True, help_text='Used if author is not set.', max_length=128, null=True, verbose_name='author name')),
158                 ('author_email', models.CharField(blank=True, help_text='Used if author is not set.', max_length=128, null=True, verbose_name='author email')),
159                 ('revision', models.IntegerField(db_index=True, verbose_name='revision')),
160                 ('description', models.TextField(blank=True, default='', verbose_name='description')),
161                 ('created_at', models.DateTimeField(db_index=True, default=datetime.datetime.now, editable=False)),
162                 ('publishable', models.BooleanField(default=False, verbose_name='publishable')),
163                 ('data', models.FileField(storage=django.core.files.storage.FileSystemStorage(location=settings.CATALOGUE_IMAGE_REPO_PATH), upload_to=dvcs.models.data_upload_to, verbose_name='data')),
164                 ('author', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, verbose_name='author')),
165                 ('merge_parent', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='merge_children', to='documents.ImageChange', verbose_name='merge parent')),
166                 ('parent', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='children', to='documents.ImageChange', verbose_name='parent')),
167             ],
168             options={
169                 'verbose_name': 'change for: image',
170                 'verbose_name_plural': 'changes for: image',
171                 'db_table': 'catalogue_imagechange',
172                 'ordering': ('created_at',),
173                 'abstract': False,
174             },
175         ),
176         migrations.CreateModel(
177             name='ImageTag',
178             fields=[
179                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
180                 ('name', models.CharField(max_length=64, verbose_name='name')),
181                 ('slug', models.SlugField(blank=True, max_length=64, null=True, unique=True, verbose_name='slug')),
182                 ('ordering', models.IntegerField(verbose_name='ordering')),
183             ],
184             options={
185                 'verbose_name': 'tag for: image',
186                 'verbose_name_plural': 'tags for: image',
187                 'db_table': 'catalogue_imagetag',
188                 'ordering': ['ordering'],
189                 'abstract': False,
190             },
191         ),
192         migrations.CreateModel(
193             name='Project',
194             fields=[
195                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
196                 ('name', models.CharField(max_length=255, unique=True, verbose_name='name')),
197                 ('notes', models.TextField(blank=True, null=True, verbose_name='notes')),
198             ],
199             options={
200                 'verbose_name': 'project',
201                 'verbose_name_plural': 'projects',
202                 'db_table': 'catalogue_project',
203                 'ordering': ['name'],
204             },
205         ),
206         migrations.CreateModel(
207             name='User',
208             fields=[
209             ],
210             options={
211                 'proxy': True,
212                 'indexes': [],
213                 'constraints': [],
214             },
215             bases=('auth.user',),
216             managers=[
217                 ('objects', django.contrib.auth.models.UserManager()),
218             ],
219         ),
220         migrations.CreateModel(
221             name='ImagePublishRecord',
222             fields=[
223                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
224                 ('timestamp', models.DateTimeField(auto_now_add=True, verbose_name='time')),
225                 ('change', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='publish_log', to='documents.ImageChange', verbose_name='change')),
226                 ('image', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='publish_log', to='documents.Image', verbose_name='image')),
227                 ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='user')),
228             ],
229             options={
230                 'verbose_name': 'image publish record',
231                 'verbose_name_plural': 'image publish records',
232                 'db_table': 'catalogue_imagepublishrecord',
233                 'ordering': ['-timestamp'],
234             },
235         ),
236         migrations.AddField(
237             model_name='imagechange',
238             name='tags',
239             field=models.ManyToManyField(related_name='change_set', to='documents.ImageTag', verbose_name='tags'),
240         ),
241         migrations.AddField(
242             model_name='imagechange',
243             name='tree',
244             field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='change_set', to='documents.Image', verbose_name='document'),
245         ),
246         migrations.AddField(
247             model_name='image',
248             name='head',
249             field=models.ForeignKey(blank=True, default=None, editable=False, help_text="This document's current head.", null=True, on_delete=django.db.models.deletion.SET_NULL, to='documents.ImageChange', verbose_name='head'),
250         ),
251         migrations.AddField(
252             model_name='image',
253             name='project',
254             field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='documents.Project'),
255         ),
256         migrations.AddField(
257             model_name='image',
258             name='stage',
259             field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='documents.ImageTag', verbose_name='stage'),
260         ),
261         migrations.AddField(
262             model_name='image',
263             name='user',
264             field=models.ForeignKey(blank=True, help_text='Work assignment.', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, verbose_name='user'),
265         ),
266         migrations.CreateModel(
267             name='ChunkPublishRecord',
268             fields=[
269                 ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
270                 ('book_record', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='documents.BookPublishRecord', verbose_name='book publish record')),
271                 ('change', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='publish_log', to='documents.ChunkChange', verbose_name='change')),
272             ],
273             options={
274                 'verbose_name': 'chunk publish record',
275                 'verbose_name_plural': 'chunk publish records',
276                 'db_table': 'catalogue_chunkpublishrecord',
277             },
278         ),
279         migrations.AddField(
280             model_name='chunkchange',
281             name='tags',
282             field=models.ManyToManyField(related_name='change_set', to='documents.ChunkTag', verbose_name='tags'),
283         ),
284         migrations.AddField(
285             model_name='chunkchange',
286             name='tree',
287             field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='change_set', to='documents.Chunk', verbose_name='document'),
288         ),
289         migrations.AddField(
290             model_name='chunk',
291             name='head',
292             field=models.ForeignKey(blank=True, default=None, editable=False, help_text="This document's current head.", null=True, on_delete=django.db.models.deletion.SET_NULL, to='documents.ChunkChange', verbose_name='head'),
293         ),
294         migrations.AddField(
295             model_name='chunk',
296             name='stage',
297             field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='documents.ChunkTag', verbose_name='stage'),
298         ),
299         migrations.AddField(
300             model_name='chunk',
301             name='user',
302             field=models.ForeignKey(blank=True, help_text='Work assignment.', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, verbose_name='user'),
303         ),
304         migrations.AddField(
305             model_name='book',
306             name='project',
307             field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='documents.Project'),
308         ),
309         migrations.AlterUniqueTogether(
310             name='imagechange',
311             unique_together={('tree', 'revision')},
312         ),
313         migrations.AlterUniqueTogether(
314             name='chunkchange',
315             unique_together={('tree', 'revision')},
316         ),
317         migrations.AlterUniqueTogether(
318             name='chunk',
319             unique_together={('book', 'slug'), ('book', 'number')},
320         ),
321     ]
322
323     operations = [
324         migrations.SeparateDatabaseAndState(
325             database_operations=[],
326             state_operations=_state_operations,
327         )
328     ]