From 61e9916d2287a31a55605e5e7eb9268a86e3c6db Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 3 Oct 2022 11:33:18 +0200 Subject: [PATCH] Remove compatibility kludges around EbookField. --- src/catalogue/fields.py | 21 ++----------------- src/catalogue/migrations/0001_initial.py | 18 ++++++++-------- .../migrations/0020_book_cover_api_thumb.py | 2 +- .../migrations/0021_auto_20171222_1404.py | 4 ++-- .../migrations/0028_book_cover_ebookpoint.py | 4 ++-- .../migrations/0034_auto_20220310_1251.py | 2 +- 6 files changed, 17 insertions(+), 34 deletions(-) diff --git a/src/catalogue/fields.py b/src/catalogue/fields.py index aaa322d1a..1efc7697e 100644 --- a/src/catalogue/fields.py +++ b/src/catalogue/fields.py @@ -69,18 +69,8 @@ class EbookField(models.FileField): librarian2_api = False ZIP = None - def __init__(self, verbose_name_=None, with_etag=True, etag_field_name=None, **kwargs): - # This is just for compatibility with older migrations, - # where first argument was for ebook format. - # Can be scrapped if old migrations are updated/removed. - verbose_name = verbose_name_ or _("%s file") % self.ext - kwargs.setdefault('verbose_name', verbose_name_ ) - - # Another compatibility fix: - # old migrations use EbookField directly, creating etag fields. - if type(self) is EbookField: - with_etag = False - + def __init__(self, verbose_name=None, with_etag=True, etag_field_name=None, **kwargs): + kwargs.setdefault('verbose_name', verbose_name) self.with_etag = with_etag self.etag_field_name = etag_field_name kwargs.setdefault('max_length', 255) @@ -108,15 +98,8 @@ class EbookField(models.FileField): else: kwargs['with_etag'] = self.with_etag - # Compatibility - verbose_name = kwargs.get('verbose_name') - if verbose_name: - del kwargs['verbose_name'] - if verbose_name != _("%s file") % self.ext: - args = [verbose_name] + args return name, path, args, kwargs - @classmethod def get_upload_to(cls, directory): directory = getattr(cls, 'directory', cls.ext) diff --git a/src/catalogue/migrations/0001_initial.py b/src/catalogue/migrations/0001_initial.py index e62b23358..448b8b90d 100644 --- a/src/catalogue/migrations/0001_initial.py +++ b/src/catalogue/migrations/0001_initial.py @@ -35,16 +35,16 @@ class Migration(migrations.Migration): ('extra_info', models.TextField(default='{}', verbose_name='Additional information')), ('gazeta_link', models.CharField(max_length=240, blank=True)), ('wiki_link', models.CharField(max_length=240, blank=True)), - ('cover', catalogue.fields.EbookField('cover', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, null=True, verbose_name='cover')), - ('cover_thumb', catalogue.fields.EbookField('cover_thumb', max_length=255, null=True, verbose_name='cover thumbnail', blank=True)), + ('cover', models.FileField(storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, null=True, verbose_name='cover')), + ('cover_thumb', models.FileField(max_length=255, null=True, verbose_name='cover thumbnail', blank=True)), ('_related_info', models.TextField(null=True, editable=False, blank=True)), - ('txt_file', catalogue.fields.EbookField('txt', default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='TXT file')), - ('fb2_file', catalogue.fields.EbookField('fb2', default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='FB2 file')), - ('pdf_file', catalogue.fields.EbookField('pdf', default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='PDF file')), - ('epub_file', catalogue.fields.EbookField('epub', default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='EPUB file')), - ('mobi_file', catalogue.fields.EbookField('mobi', default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='MOBI file')), - ('html_file', catalogue.fields.EbookField('html', default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='HTML file')), - ('xml_file', catalogue.fields.EbookField('xml', default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='XML file')), + ('txt_file', models.FileField(default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='TXT file')), + ('fb2_file', models.FileField(default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='FB2 file')), + ('pdf_file', models.FileField(default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='PDF file')), + ('epub_file', models.FileField(default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='EPUB file')), + ('mobi_file', models.FileField(default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='MOBI file')), + ('html_file', models.FileField(default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='HTML file')), + ('xml_file', models.FileField(default='', storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, verbose_name='XML file')), ('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='children', blank=True, to='catalogue.Book', null=True)), ], options={ diff --git a/src/catalogue/migrations/0020_book_cover_api_thumb.py b/src/catalogue/migrations/0020_book_cover_api_thumb.py index 0dba17502..4c9cd8ef4 100644 --- a/src/catalogue/migrations/0020_book_cover_api_thumb.py +++ b/src/catalogue/migrations/0020_book_cover_api_thumb.py @@ -15,6 +15,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='book', name='cover_api_thumb', - field=catalogue.fields.EbookField('cover_api_thumb', max_length=255, upload_to=catalogue.fields.UploadToPath('book/cover_api_thumb/%s.jpg'), null=True, verbose_name='cover thumbnail for API', blank=True), + field=models.FileField(max_length=255, upload_to=catalogue.fields.UploadToPath('book/cover_api_thumb/%s.jpg'), null=True, verbose_name='cover thumbnail for API', blank=True), ), ] diff --git a/src/catalogue/migrations/0021_auto_20171222_1404.py b/src/catalogue/migrations/0021_auto_20171222_1404.py index e4a8762e2..6e0331cb5 100644 --- a/src/catalogue/migrations/0021_auto_20171222_1404.py +++ b/src/catalogue/migrations/0021_auto_20171222_1404.py @@ -15,11 +15,11 @@ class Migration(migrations.Migration): migrations.AddField( model_name='book', name='simple_cover', - field=catalogue.fields.EbookField('simple_cover', max_length=255, upload_to=catalogue.fields.UploadToPath('book/cover_simple/%s.jpg'), null=True, verbose_name='cover for mobile app', blank=True), + field=models.FileField(max_length=255, upload_to=catalogue.fields.UploadToPath('book/cover_simple/%s.jpg'), null=True, verbose_name='cover for mobile app', blank=True), ), migrations.AlterField( model_name='book', name='cover_api_thumb', - field=catalogue.fields.EbookField('cover_api_thumb', max_length=255, upload_to=catalogue.fields.UploadToPath('book/cover_api_thumb/%s.jpg'), null=True, verbose_name='cover thumbnail for mobile app', blank=True), + field=models.FileField(max_length=255, upload_to=catalogue.fields.UploadToPath('book/cover_api_thumb/%s.jpg'), null=True, verbose_name='cover thumbnail for mobile app', blank=True), ), ] diff --git a/src/catalogue/migrations/0028_book_cover_ebookpoint.py b/src/catalogue/migrations/0028_book_cover_ebookpoint.py index b9ba1b064..3b96a7fdf 100644 --- a/src/catalogue/migrations/0028_book_cover_ebookpoint.py +++ b/src/catalogue/migrations/0028_book_cover_ebookpoint.py @@ -1,7 +1,7 @@ # Generated by Django 2.2.10 on 2020-04-03 09:40 import catalogue.fields -from django.db import migrations +from django.db import migrations, models class Migration(migrations.Migration): @@ -14,6 +14,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='book', name='cover_ebookpoint', - field=catalogue.fields.EbookField('cover_ebookpoint', blank=True, max_length=255, null=True, upload_to=catalogue.fields.UploadToPath('book/cover_ebookpoint/%s.jpg'), verbose_name='cover for Ebookpoint'), + field=models.FileField(blank=True, max_length=255, null=True, upload_to=catalogue.fields.UploadToPath('book/cover_ebookpoint/%s.jpg'), verbose_name='cover for Ebookpoint'), ), ] diff --git a/src/catalogue/migrations/0034_auto_20220310_1251.py b/src/catalogue/migrations/0034_auto_20220310_1251.py index 9360229a1..0fece61fd 100644 --- a/src/catalogue/migrations/0034_auto_20220310_1251.py +++ b/src/catalogue/migrations/0034_auto_20220310_1251.py @@ -14,7 +14,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='book', name='cover_clean', - field=catalogue.fields.EbookField('cover_clean', blank=True, max_length=255, null=True, upload_to=catalogue.fields.UploadToPath('book/cover_clean/%s.jpg'), verbose_name='clean cover'), + field=models.FileField(blank=True, max_length=255, null=True, upload_to=catalogue.fields.UploadToPath('book/cover_clean/%s.jpg'), verbose_name='clean cover'), ), migrations.AddField( model_name='book', -- 2.20.1