Tidying up all the covers craziness and storages. master
authorRadek Czajka <radekczajka@wolnelektury.pl>
Wed, 25 Nov 2026 21:58:52 +0000 (22:58 +0100)
committerRadek Czajka <radekczajka@wolnelektury.pl>
Wed, 25 Nov 2026 21:58:52 +0000 (22:58 +0100)
34 files changed:
requirements/requirements.txt
src/api/tests/res/responses/books-child.json
src/api/tests/res/responses/books-parent.json
src/api/tests/res/responses/books.json
src/api/tests/res/responses/books.xml
src/api/tests/res/responses/collection.json
src/api/tests/res/responses/filter-books.json
src/bookmarks/templates/bookmarks/quote_detail.html
src/catalogue/api/serializers.py
src/catalogue/fields.py
src/catalogue/fixtures/test-books.yaml
src/catalogue/migrations/0001_initial.py
src/catalogue/migrations/0014_auto_20170627_1442.py
src/catalogue/migrations/0038_auto_20220930_1050.py
src/catalogue/migrations/0046_alter_book_options_alter_bookmedia_options_and_more.py
src/catalogue/migrations/0049_book_html_nonotes_file_book_html_nonotes_file_etag_and_more.py
src/catalogue/migrations/0059_remove_book_cover_api_thumb_and_more.py [new file with mode: 0644]
src/catalogue/models/book.py
src/catalogue/models/bookmedia.py
src/catalogue/templates/catalogue/book_box.html
src/catalogue/templates/catalogue/book_detail.html
src/catalogue/templates/catalogue/book_mini_box.html
src/catalogue/templates/catalogue/book_text.html
src/catalogue/templates/catalogue/collection_box.html
src/catalogue/templates/catalogue/fragment_box.html
src/catalogue/templates/catalogue/preview_ad.html
src/catalogue/templates/catalogue/preview_ad_homepage.html
src/catalogue/utils.py
src/catalogue/views.py
src/references/templates/references/onepager.html
src/references/templates/references/popup.html
src/search/views.py
src/wolnelektury/settings/static.py
src/wolnelektury/views.py

index 92fb217..af6ca0a 100644 (file)
@@ -6,6 +6,7 @@ fnpdjango==0.8
 docutils==0.23
 django-debug-toolbar==8.0.0
 psycopg2-binary==2.9.13
 docutils==0.23
 django-debug-toolbar==8.0.0
 psycopg2-binary==2.9.13
+django-storages[s3]==1.14.6
 
 pymemcache==4.0.0
 
 
 pymemcache==4.0.0
 
index b3155e6..0b79949 100644 (file)
@@ -53,7 +53,7 @@
         "epoch": "Barok", 
         "href": "http://testserver/api/books/parent/",
         "genre": "Sonet", 
         "epoch": "Barok", 
         "href": "http://testserver/api/books/parent/",
         "genre": "Sonet", 
-        "simple_thumb": "http://testserver/media/cover_api_thumb/parent.jpg",
+        "simple_thumb": "http://testserver/media/cover/parent.jpg-139x193",
         "has_audio": true, 
         "cover_thumb": "http://testserver/media/cover/parent.jpg-139x193"
     }, 
         "has_audio": true, 
         "cover_thumb": "http://testserver/media/cover/parent.jpg-139x193"
     }, 
index 6b8bce9..4c15830 100644 (file)
@@ -68,7 +68,7 @@
     "language": "pol",
     "parent": null, 
     "cover_color": "#a6820a", 
     "language": "pol",
     "parent": null, 
     "cover_color": "#a6820a", 
-    "simple_cover": "http://testserver/media/simple_cover/parent.jpg",
+    "simple_cover": "http://testserver/media/cover/parent.jpg",
     "authors": [
         {
             "url": "http://testserver/katalog/autor/john-doe/",
     "authors": [
         {
             "url": "http://testserver/katalog/autor/john-doe/",
@@ -85,7 +85,7 @@
     "url": "http://testserver/katalog/lektura/parent/",
     "cover": "http://testserver/media/cover/parent.jpg",
     "pdf": "http://testserver/media/pdf/parent.pdf",
     "url": "http://testserver/katalog/lektura/parent/",
     "cover": "http://testserver/media/cover/parent.jpg",
     "pdf": "http://testserver/media/pdf/parent.pdf",
-    "simple_thumb": "http://testserver/media/cover_api_thumb/parent.jpg",
+    "simple_thumb": "http://testserver/media/cover/parent.jpg-139x193",
     "isbn_epub": null,
     "isbn_mobi": null,
     "isbn_pdf": null
     "isbn_epub": null,
     "isbn_mobi": null,
     "isbn_pdf": null
index 4b8d11e..3700ac8 100644 (file)
@@ -46,8 +46,8 @@
         "epoch": "Barok", 
         "href": "http://testserver/api/books/parent/",
         "genre": "Sonet", 
         "epoch": "Barok", 
         "href": "http://testserver/api/books/parent/",
         "genre": "Sonet", 
-        "simple_thumb": "http://testserver/media/cover_api_thumb/parent.jpg",
+        "simple_thumb": "http://testserver/media/cover/parent.jpg-139x193",
         "slug": "parent", 
         "slug": "parent", 
-        "cover_thumb": "cover_thumb/parent.jpg"
+        "cover_thumb": "cover/parent.jpg"
     }
 ]
     }
 ]
index 1eb4a97..3d47fe9 100644 (file)
@@ -1,2 +1,2 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
-<response><resource><kind></kind><full_sort_key>$child$2</full_sort_key><title>Child</title><url>http://testserver/katalog/lektura/child/</url><cover_color>#000000</cover_color><author></author><cover></cover><epoch></epoch><href>http://testserver/api/books/child/?format=xml</href><has_audio>False</has_audio><genre>Wiersz</genre><simple_thumb></simple_thumb><slug>child</slug><cover_thumb></cover_thumb><liked></liked></resource><resource><kind></kind><full_sort_key>$grandchild$3</full_sort_key><title>Grandchild</title><url>http://testserver/katalog/lektura/grandchild/</url><cover_color>#000000</cover_color><author></author><cover></cover><epoch></epoch><href>http://testserver/api/books/grandchild/?format=xml</href><has_audio>False</has_audio><genre>Sonet</genre><simple_thumb></simple_thumb><slug>grandchild</slug><cover_thumb></cover_thumb><liked></liked></resource><resource><kind>Liryka</kind><full_sort_key>john doe$parent$1</full_sort_key><title>Parent</title><url>http://testserver/katalog/lektura/parent/</url><cover_color>#a6820a</cover_color><author>John Doe</author><cover>cover/parent.jpg</cover><epoch>Barok</epoch><href>http://testserver/api/books/parent/?format=xml</href><has_audio>True</has_audio><genre>Sonet</genre><simple_thumb>http://testserver/media/cover_api_thumb/parent.jpg</simple_thumb><slug>parent</slug><cover_thumb>cover_thumb/parent.jpg</cover_thumb><liked></liked></resource></response>
+<response><resource><kind></kind><full_sort_key>$child$2</full_sort_key><title>Child</title><url>http://testserver/katalog/lektura/child/</url><cover_color>#000000</cover_color><author></author><cover></cover><epoch></epoch><href>http://testserver/api/books/child/?format=xml</href><has_audio>False</has_audio><genre>Wiersz</genre><simple_thumb></simple_thumb><slug>child</slug><cover_thumb></cover_thumb><liked></liked></resource><resource><kind></kind><full_sort_key>$grandchild$3</full_sort_key><title>Grandchild</title><url>http://testserver/katalog/lektura/grandchild/</url><cover_color>#000000</cover_color><author></author><cover></cover><epoch></epoch><href>http://testserver/api/books/grandchild/?format=xml</href><has_audio>False</has_audio><genre>Sonet</genre><simple_thumb></simple_thumb><slug>grandchild</slug><cover_thumb></cover_thumb><liked></liked></resource><resource><kind>Liryka</kind><full_sort_key>john doe$parent$1</full_sort_key><title>Parent</title><url>http://testserver/katalog/lektura/parent/</url><cover_color>#a6820a</cover_color><author>John Doe</author><cover>cover/parent.jpg</cover><epoch>Barok</epoch><href>http://testserver/api/books/parent/?format=xml</href><has_audio>True</has_audio><genre>Sonet</genre><simple_thumb>http://testserver/media/cover/parent.jpg</simple_thumb><slug>parent</slug><cover_thumb>cover/parent.jpg</cover_thumb><liked></liked></resource></response>
index 0e385dc..679a7ee 100644 (file)
@@ -15,7 +15,7 @@
             "epoch": "Barok", 
             "href": "http://testserver/api/books/parent/",
             "genre": "Sonet", 
             "epoch": "Barok", 
             "href": "http://testserver/api/books/parent/",
             "genre": "Sonet", 
-            "simple_thumb": "http://testserver/media/cover_api_thumb/parent.jpg",
+            "simple_thumb": "http://testserver/media/cover/parent.jpg-139x193",
             "has_audio": true, 
             "cover_thumb": "http://testserver/media/cover/parent.jpg-139x193"
         }
             "has_audio": true, 
             "cover_thumb": "http://testserver/media/cover/parent.jpg-139x193"
         }
index 49f3dea..3e4c72b 100644 (file)
@@ -49,8 +49,8 @@
         "href": "http://testserver/api/books/parent/",
         "key": "book$parent", 
         "genre": "Sonet", 
         "href": "http://testserver/api/books/parent/",
         "key": "book$parent", 
         "genre": "Sonet", 
-        "simple_thumb": "http://testserver/media/cover_api_thumb/parent.jpg",
+        "simple_thumb": "http://testserver/media/cover/parent.jpg-139x193",
         "slug": "parent", 
         "slug": "parent", 
-        "cover_thumb": "cover_thumb/parent.jpg"
+        "cover_thumb": "cover/parent.jpg"
     }
 ]
     }
 ]
index 46181dd..c72e37f 100644 (file)
@@ -16,7 +16,7 @@
         <aside class="l-aside">
           <figure class="only-l">
             <a href="{{ book.get_absolute_url }}">
         <aside class="l-aside">
           <figure class="only-l">
             <a href="{{ book.get_absolute_url }}">
-              <img src="{% if book.cover_clean %}{{ book.cover_clean.url }}{% endif %}" alt="{{ book.pretty_title }}" width="240">
+              <img src="{% if book.cover %}{{ book.cover.url }}{% endif %}" alt="{{ book.pretty_title }}" width="240">
             </a>
           </figure>
           </ul>
             </a>
           </figure>
           </ul>
@@ -49,7 +49,7 @@
               <div class="lay-row lay-l-block lay-spread">
                 <figure class="only-s book-cover-small">
                   <a href="{{ book.get_absolute_url }}">
               <div class="lay-row lay-l-block lay-spread">
                 <figure class="only-s book-cover-small">
                   <a href="{{ book.get_absolute_url }}">
-                    <img src="{% if book.cover_clean %}{{ book.cover_clean.url }}{% endif %}" alt="{{ book.pretty_title }}">
+                    <img src="{% if book.cover %}{{ book.cover.url }}{% endif %}" alt="{{ book.pretty_title }}">
                   </a>
                 </figure>
               </div>
                   </a>
                 </figure>
               </div>
index 9fa05f5..ee34532 100644 (file)
@@ -145,6 +145,8 @@ class BookSerializer2(serializers.ModelSerializer):
     mobi = EmbargoURLField(source='mobi_url')
     pdf = EmbargoURLField(source='pdf_url')
 
     mobi = EmbargoURLField(source='mobi_url')
     pdf = EmbargoURLField(source='pdf_url')
 
+    cover_thumb = ThumbnailField('139x193', source='cover')
+
     authors = AuthorItemSerializer(many=True)
     translators = AuthorItemSerializer(many=True)
     epochs = EpochItemSerializer(many=True)
     authors = AuthorItemSerializer(many=True)
     translators = AuthorItemSerializer(many=True)
     epochs = EpochItemSerializer(many=True)
@@ -217,9 +219,9 @@ class BookSerializer(LegacyMixin, serializers.ModelSerializer):
     genre = serializers.CharField(source='genre_unicode')
     liked = BookLiked()
 
     genre = serializers.CharField(source='genre_unicode')
     liked = BookLiked()
 
-    simple_thumb = serializers.FileField(source='cover_api_thumb')
     href = AbsoluteURLField(view_name='catalogue_api_book', view_args=['slug'])
     url = AbsoluteURLField()
     href = AbsoluteURLField(view_name='catalogue_api_book', view_args=['slug'])
     url = AbsoluteURLField()
+    simple_thumb = ThumbnailField('139x193', source='cover')
     cover_thumb = ThumbnailField('139x193', source='cover')
 
     class Meta:
     cover_thumb = ThumbnailField('139x193', source='cover')
 
     class Meta:
@@ -235,7 +237,7 @@ class BookSerializer(LegacyMixin, serializers.ModelSerializer):
 
 class BookListSerializer(BookSerializer):
     cover = serializers.CharField()
 
 class BookListSerializer(BookSerializer):
     cover = serializers.CharField()
-    cover_thumb = serializers.CharField()
+    cover_thumb = serializers.CharField(source='cover')
 
     Meta = BookSerializer.Meta
 
 
     Meta = BookSerializer.Meta
 
@@ -290,8 +292,9 @@ class BookDetailSerializer(LegacyMixin, serializers.ModelSerializer):
     mobi = EmbargoURLField(source='mobi_url')
     pdf = EmbargoURLField(source='pdf_url')
     media = MediaSerializer(many=True)
     mobi = EmbargoURLField(source='mobi_url')
     pdf = EmbargoURLField(source='pdf_url')
     media = MediaSerializer(many=True)
+    simple_cover = serializers.FileField(source='cover')
     cover_thumb = ThumbnailField('139x193', source='cover')
     cover_thumb = ThumbnailField('139x193', source='cover')
-    simple_thumb = serializers.FileField(source='cover_api_thumb')
+    simple_thumb = ThumbnailField('139x193', source='cover')
 
     class Meta:
         model = Book
 
     class Meta:
         model = Book
index ee64ee4..64782ec 100644 (file)
@@ -428,47 +428,3 @@ class CoverField(EbookField):
 
     def set_file_permissions(self, fieldfile):
         pass
 
     def set_file_permissions(self, fieldfile):
         pass
-
-
-class CoverCleanField(CoverField):
-    directory = 'cover_clean'
-
-    @staticmethod
-    def transform(wldoc, book):
-        return get_make_cover(book)(wldoc.book_info, width=360).output_file()
-
-
-class CoverThumbField(CoverField):
-    directory = 'cover_thumb'
-
-    @staticmethod
-    def transform(wldoc, book):
-        from librarian.cover import WLCover
-        return WLCover(wldoc.book_info, height=193).output_file()
-
-
-class CoverApiThumbField(CoverField):
-    directory = 'cover_api_thumb'
-
-    @staticmethod
-    def transform(wldoc, book):
-        from librarian.cover import WLNoBoxCover
-        return WLNoBoxCover(wldoc.book_info, height=500).output_file()
-
-
-class SimpleCoverField(CoverField):
-    directory = 'cover_simple'
-
-    @staticmethod
-    def transform(wldoc, book):
-        from librarian.cover import WLNoBoxCover
-        return WLNoBoxCover(wldoc.book_info, height=1000).output_file()
-
-
-class CoverEbookpointField(CoverField):
-    directory = 'cover_ebookpoint'
-
-    @staticmethod
-    def transform(wldoc, book):
-        from librarian.cover import EbookpointCover
-        return EbookpointCover(wldoc.book_info).output_file()
index d580aa6..a2ecdb2 100644 (file)
@@ -11,9 +11,6 @@
     mobi_file: mobi/parent.mobi
     pdf_file: pdf/parent.pdf
     cover: cover/parent.jpg
     mobi_file: mobi/parent.mobi
     pdf_file: pdf/parent.pdf
     cover: cover/parent.jpg
-    cover_api_thumb: cover_api_thumb/parent.jpg
-    simple_cover: simple_cover/parent.jpg
-    cover_thumb: cover_thumb/parent.jpg
     recommended: true
     created_at: "1970-01-03 0:0Z"
     changed_at: "1970-01-03 0:0Z"
     recommended: true
     created_at: "1970-01-03 0:0Z"
     changed_at: "1970-01-03 0:0Z"
index 7a2d427..ac8048c 100644 (file)
@@ -3,7 +3,6 @@
 #
 from django.db import models, migrations
 import django.db.models.deletion
 #
 from django.db import models, migrations
 import django.db.models.deletion
-import fnpdjango.storage
 import catalogue.fields
 import catalogue.models.bookmedia
 from django.conf import settings
 import catalogue.fields
 import catalogue.models.bookmedia
 from django.conf import settings
@@ -35,16 +34,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)),
                 ('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', models.FileField(storage=fnpdjango.storage.BofhFileSystemStorage(), max_length=255, blank=True, null=True, verbose_name='cover')),
+                ('cover', models.FileField(storage=catalogue.models.book.get_storage, 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)),
                 ('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', 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')),
+                ('txt_file', models.FileField(default='', storage=catalogue.models.book.get_storage, max_length=255, blank=True, verbose_name='TXT file')),
+                ('fb2_file', models.FileField(default='', storage=catalogue.models.book.get_storage, max_length=255, blank=True, verbose_name='FB2 file')),
+                ('pdf_file', models.FileField(default='', storage=catalogue.models.book.get_storage, max_length=255, blank=True, verbose_name='PDF file')),
+                ('epub_file', models.FileField(default='', storage=catalogue.models.book.get_storage, max_length=255, blank=True, verbose_name='EPUB file')),
+                ('mobi_file', models.FileField(default='', storage=catalogue.models.book.get_storage, max_length=255, blank=True, verbose_name='MOBI file')),
+                ('html_file', models.FileField(default='', storage=catalogue.models.book.get_storage, max_length=255, blank=True, verbose_name='HTML file')),
+                ('xml_file', models.FileField(default='', storage=catalogue.models.book.get_storage, 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={
                 ('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='children', blank=True, to='catalogue.Book', null=True)),
             ],
             options={
index e386c3c..75d35c3 100644 (file)
@@ -2,7 +2,6 @@
 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
 #
 from django.db import migrations, models
 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
 #
 from django.db import migrations, models
-import fnpdjango.storage
 import catalogue.models.bookmedia
 
 
 import catalogue.models.bookmedia
 
 
@@ -16,6 +15,6 @@ class Migration(migrations.Migration):
         migrations.AlterField(
             model_name='bookmedia',
             name='file',
         migrations.AlterField(
             model_name='bookmedia',
             name='file',
-            field=models.FileField(storage=fnpdjango.storage.BofhFileSystemStorage(), upload_to=catalogue.models.bookmedia._file_upload_to, max_length=600, verbose_name='file'),
+            field=models.FileField(storage=catalogue.models.bookmedia.get_storage, upload_to=catalogue.models.bookmedia._file_upload_to, max_length=600, verbose_name='file'),
         ),
     ]
         ),
     ]
index 47e904a..6036880 100644 (file)
@@ -1,8 +1,8 @@
 # Generated by Django 2.2.28 on 2022-09-30 08:50
 
 import catalogue.fields
 # Generated by Django 2.2.28 on 2022-09-30 08:50
 
 import catalogue.fields
+import catalogue.models.book
 from django.db import migrations
 from django.db import migrations
-import fnpdjango.storage
 
 
 class Migration(migrations.Migration):
 
 
 class Migration(migrations.Migration):
@@ -15,66 +15,66 @@ class Migration(migrations.Migration):
         migrations.AlterField(
             model_name='book',
             name='cover',
         migrations.AlterField(
             model_name='book',
             name='cover',
-            field=catalogue.fields.CoverField('cover', etag_field_name='cover_etag', storage=fnpdjango.storage.BofhFileSystemStorage()),
+            field=catalogue.fields.CoverField('cover', etag_field_name='cover_etag', storage=catalogue.models.book.get_storage),
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_api_thumb',
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_api_thumb',
-            field=catalogue.fields.CoverApiThumbField('cover thumbnail for mobile app', etag_field_name='cover_api_thumb_etag'),
+            field=catalogue.fields.CoverField('cover thumbnail for mobile app', etag_field_name='cover_api_thumb_etag'),
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_clean',
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_clean',
-            field=catalogue.fields.CoverCleanField('clean cover', etag_field_name='cover_clean_etag'),
+            field=catalogue.fields.CoverField('clean cover', etag_field_name='cover_clean_etag'),
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_ebookpoint',
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_ebookpoint',
-            field=catalogue.fields.CoverEbookpointField('cover for Ebookpoint', etag_field_name='cover_ebookpoint_etag'),
+            field=catalogue.fields.CoverField('cover for Ebookpoint', etag_field_name='cover_ebookpoint_etag'),
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_thumb',
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_thumb',
-            field=catalogue.fields.CoverThumbField('cover thumbnail', etag_field_name='cover_thumb_etag'),
+            field=catalogue.fields.CoverField('cover thumbnail', etag_field_name='cover_thumb_etag'),
         ),
         migrations.AlterField(
             model_name='book',
             name='epub_file',
         ),
         migrations.AlterField(
             model_name='book',
             name='epub_file',
-            field=catalogue.fields.EpubField(etag_field_name='epub_file_etag', storage=fnpdjango.storage.BofhFileSystemStorage()),
+            field=catalogue.fields.EpubField(etag_field_name='epub_file_etag', storage=catalogue.models.book.get_storage),
         ),
         migrations.AlterField(
             model_name='book',
             name='fb2_file',
         ),
         migrations.AlterField(
             model_name='book',
             name='fb2_file',
-            field=catalogue.fields.Fb2Field(etag_field_name='fb2_file_etag', storage=fnpdjango.storage.BofhFileSystemStorage()),
+            field=catalogue.fields.Fb2Field(etag_field_name='fb2_file_etag', storage=catalogue.models.book.get_storage),
         ),
         migrations.AlterField(
             model_name='book',
             name='html_file',
         ),
         migrations.AlterField(
             model_name='book',
             name='html_file',
-            field=catalogue.fields.HtmlField(etag_field_name='html_file_etag', storage=fnpdjango.storage.BofhFileSystemStorage()),
+            field=catalogue.fields.HtmlField(etag_field_name='html_file_etag', storage=catalogue.models.book.get_storage),
         ),
         migrations.AlterField(
             model_name='book',
             name='mobi_file',
         ),
         migrations.AlterField(
             model_name='book',
             name='mobi_file',
-            field=catalogue.fields.MobiField(etag_field_name='mobi_file_etag', storage=fnpdjango.storage.BofhFileSystemStorage()),
+            field=catalogue.fields.MobiField(etag_field_name='mobi_file_etag', storage=catalogue.models.book.get_storage),
         ),
         migrations.AlterField(
             model_name='book',
             name='pdf_file',
         ),
         migrations.AlterField(
             model_name='book',
             name='pdf_file',
-            field=catalogue.fields.PdfField(etag_field_name='pdf_file_etag', storage=fnpdjango.storage.BofhFileSystemStorage()),
+            field=catalogue.fields.PdfField(etag_field_name='pdf_file_etag', storage=catalogue.models.book.get_storage),
         ),
         migrations.AlterField(
             model_name='book',
             name='simple_cover',
         ),
         migrations.AlterField(
             model_name='book',
             name='simple_cover',
-            field=catalogue.fields.SimpleCoverField('cover for mobile app', etag_field_name='simple_cover_etag'),
+            field=catalogue.fields.CoverField('cover for mobile app', etag_field_name='simple_cover_etag'),
         ),
         migrations.AlterField(
             model_name='book',
             name='txt_file',
         ),
         migrations.AlterField(
             model_name='book',
             name='txt_file',
-            field=catalogue.fields.TxtField(etag_field_name='txt_file_etag', storage=fnpdjango.storage.BofhFileSystemStorage()),
+            field=catalogue.fields.TxtField(etag_field_name='txt_file_etag', storage=catalogue.models.book.get_storage),
         ),
         migrations.AlterField(
             model_name='book',
             name='xml_file',
         ),
         migrations.AlterField(
             model_name='book',
             name='xml_file',
-            field=catalogue.fields.XmlField(storage=fnpdjango.storage.BofhFileSystemStorage(), with_etag=False),
+            field=catalogue.fields.XmlField(storage=catalogue.models.book.get_storage, with_etag=False),
         ),
     ]
         ),
     ]
index 68e9a00..8d33eab 100644 (file)
@@ -1,10 +1,10 @@
 # Generated by Django 4.0.8 on 2023-08-28 14:36
 
 import catalogue.fields
 # Generated by Django 4.0.8 on 2023-08-28 14:36
 
 import catalogue.fields
+import catalogue.models.book
 import catalogue.models.bookmedia
 from django.db import migrations, models
 import django.db.models.deletion
 import catalogue.models.bookmedia
 from django.db import migrations, models
 import django.db.models.deletion
-import fnpdjango.storage
 
 
 class Migration(migrations.Migration):
 
 
 class Migration(migrations.Migration):
@@ -62,27 +62,27 @@ class Migration(migrations.Migration):
         migrations.AlterField(
             model_name='book',
             name='cover',
         migrations.AlterField(
             model_name='book',
             name='cover',
-            field=catalogue.fields.CoverField(etag_field_name='cover_etag', storage=fnpdjango.storage.BofhFileSystemStorage(), verbose_name='okładka'),
+            field=catalogue.fields.CoverField(etag_field_name='cover_etag', storage=catalogue.models.book.get_storage, verbose_name='okładka'),
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_api_thumb',
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_api_thumb',
-            field=catalogue.fields.CoverApiThumbField(etag_field_name='cover_api_thumb_etag', verbose_name='mniaturka okładki dla aplikacji'),
+            field=catalogue.fields.CoverField(etag_field_name='cover_api_thumb_etag', verbose_name='mniaturka okładki dla aplikacji'),
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_clean',
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_clean',
-            field=catalogue.fields.CoverCleanField(etag_field_name='cover_clean_etag', verbose_name='czysta okładka'),
+            field=catalogue.fields.CoverField(etag_field_name='cover_clean_etag', verbose_name='czysta okładka'),
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_ebookpoint',
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_ebookpoint',
-            field=catalogue.fields.CoverEbookpointField(etag_field_name='cover_ebookpoint_etag', verbose_name='okładka dla Ebookpoint'),
+            field=catalogue.fields.CoverField(etag_field_name='cover_ebookpoint_etag', verbose_name='okładka dla Ebookpoint'),
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_thumb',
         ),
         migrations.AlterField(
             model_name='book',
             name='cover_thumb',
-            field=catalogue.fields.CoverThumbField(etag_field_name='cover_thumb_etag', verbose_name='miniatura okładki'),
+            field=catalogue.fields.CoverField(etag_field_name='cover_thumb_etag', verbose_name='miniatura okładki'),
         ),
         migrations.AlterField(
             model_name='book',
         ),
         migrations.AlterField(
             model_name='book',
@@ -137,7 +137,7 @@ class Migration(migrations.Migration):
         migrations.AlterField(
             model_name='book',
             name='simple_cover',
         migrations.AlterField(
             model_name='book',
             name='simple_cover',
-            field=catalogue.fields.SimpleCoverField(etag_field_name='simple_cover_etag', verbose_name='okładka dla aplikacji'),
+            field=catalogue.fields.CoverField(etag_field_name='simple_cover_etag', verbose_name='okładka dla aplikacji'),
         ),
         migrations.AlterField(
             model_name='book',
         ),
         migrations.AlterField(
             model_name='book',
@@ -167,7 +167,7 @@ class Migration(migrations.Migration):
         migrations.AlterField(
             model_name='bookmedia',
             name='file',
         migrations.AlterField(
             model_name='bookmedia',
             name='file',
-            field=models.FileField(max_length=600, storage=fnpdjango.storage.BofhFileSystemStorage(), upload_to=catalogue.models.bookmedia._file_upload_to, verbose_name='plik'),
+            field=models.FileField(max_length=600, storage=catalogue.models.bookmedia.get_storage, upload_to=catalogue.models.bookmedia._file_upload_to, verbose_name='plik'),
         ),
         migrations.AlterField(
             model_name='bookmedia',
         ),
         migrations.AlterField(
             model_name='bookmedia',
index bd297d4..63bcfd1 100644 (file)
@@ -1,8 +1,8 @@
 # Generated by Django 4.0.8 on 2025-02-26 14:46
 
 import catalogue.fields
 # Generated by Django 4.0.8 on 2025-02-26 14:46
 
 import catalogue.fields
+import catalogue.models.book
 from django.db import migrations, models
 from django.db import migrations, models
-import fnpdjango.storage
 
 
 class Migration(migrations.Migration):
 
 
 class Migration(migrations.Migration):
@@ -15,7 +15,7 @@ class Migration(migrations.Migration):
         migrations.AddField(
             model_name='book',
             name='html_nonotes_file',
         migrations.AddField(
             model_name='book',
             name='html_nonotes_file',
-            field=catalogue.fields.HtmlNonotesField(etag_field_name='html_nonotes_file_etag', storage=fnpdjango.storage.BofhFileSystemStorage()),
+            field=catalogue.fields.HtmlNonotesField(etag_field_name='html_nonotes_file_etag', storage=catalogue.models.book.get_storage),
         ),
         migrations.AddField(
             model_name='book',
         ),
         migrations.AddField(
             model_name='book',
diff --git a/src/catalogue/migrations/0059_remove_book_cover_api_thumb_and_more.py b/src/catalogue/migrations/0059_remove_book_cover_api_thumb_and_more.py
new file mode 100644 (file)
index 0000000..1399623
--- /dev/null
@@ -0,0 +1,53 @@
+# Generated by Django 5.2.19 on 2026-11-24 13:18
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('catalogue', '0058_alter_book_can_sell_mp3'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='book',
+            name='cover_api_thumb',
+        ),
+        migrations.RemoveField(
+            model_name='book',
+            name='cover_api_thumb_etag',
+        ),
+        migrations.RemoveField(
+            model_name='book',
+            name='cover_clean',
+        ),
+        migrations.RemoveField(
+            model_name='book',
+            name='cover_clean_etag',
+        ),
+        migrations.RemoveField(
+            model_name='book',
+            name='cover_ebookpoint',
+        ),
+        migrations.RemoveField(
+            model_name='book',
+            name='cover_ebookpoint_etag',
+        ),
+        migrations.RemoveField(
+            model_name='book',
+            name='cover_thumb',
+        ),
+        migrations.RemoveField(
+            model_name='book',
+            name='cover_thumb_etag',
+        ),
+        migrations.RemoveField(
+            model_name='book',
+            name='simple_cover',
+        ),
+        migrations.RemoveField(
+            model_name='book',
+            name='simple_cover_etag',
+        ),
+    ]
index d09a09a..cfb3263 100644 (file)
@@ -16,10 +16,10 @@ from django.conf import settings
 from django.db import connection, models, transaction
 import django.dispatch
 from django.contrib.contenttypes.fields import GenericRelation
 from django.db import connection, models, transaction
 import django.dispatch
 from django.contrib.contenttypes.fields import GenericRelation
+from django.core.files.storage import storages
 from django.template.loader import render_to_string
 from django.urls import reverse
 from django.utils.translation import gettext_lazy as _, get_language
 from django.template.loader import render_to_string
 from django.urls import reverse
 from django.utils.translation import gettext_lazy as _, get_language
-from fnpdjango.storage import BofhFileSystemStorage
 from lxml import html
 from librarian.cover import WLCover
 from librarian.html import transform_abstrakt
 from lxml import html
 from librarian.cover import WLCover
 from librarian.html import transform_abstrakt
@@ -33,7 +33,9 @@ from catalogue.models.tag import prefetched_relations
 from catalogue import app_settings
 from wolnelektury.utils import makedirs, cached_render, clear_cached_renders
 
 from catalogue import app_settings
 from wolnelektury.utils import makedirs, cached_render, clear_cached_renders
 
-bofh_storage = BofhFileSystemStorage()
+
+def get_storage():
+    return storages['book']
 
 
 class Book(models.Model):
 
 
 class Book(models.Model):
@@ -67,24 +69,15 @@ class Book(models.Model):
     isbn_mp3 = models.CharField('ISBN audiobooka', max_length=32, blank=True)
 
     # files generated during publication
     isbn_mp3 = models.CharField('ISBN audiobooka', max_length=32, blank=True)
 
     # files generated during publication
-    xml_file = fields.XmlField(storage=bofh_storage, with_etag=False)
-    html_file = fields.HtmlField(storage=bofh_storage)
-    html_nonotes_file = fields.HtmlNonotesField(storage=bofh_storage)
-    fb2_file = fields.Fb2Field(storage=bofh_storage)
-    txt_file = fields.TxtField(storage=bofh_storage)
-    epub_file = fields.EpubField(storage=bofh_storage)
-    mobi_file = fields.MobiField(storage=bofh_storage)
-    pdf_file = fields.PdfField(storage=bofh_storage)
-
-    cover = fields.CoverField('okładka', storage=bofh_storage)
-    # Cleaner version of cover for thumbs
-    cover_clean = fields.CoverCleanField('czysta okładka')
-    cover_thumb = fields.CoverThumbField('miniatura okładki')
-    cover_api_thumb = fields.CoverApiThumbField(
-        'mniaturka okładki dla aplikacji')
-    simple_cover = fields.SimpleCoverField('okładka dla aplikacji')
-    cover_ebookpoint = fields.CoverEbookpointField(
-        'okładka dla Ebookpoint')
+    xml_file = fields.XmlField(storage=get_storage, with_etag=False)
+    html_file = fields.HtmlField(storage=get_storage)
+    html_nonotes_file = fields.HtmlNonotesField(storage=get_storage)
+    fb2_file = fields.Fb2Field(storage=get_storage)
+    txt_file = fields.TxtField(storage=get_storage)
+    epub_file = fields.EpubField(storage=get_storage)
+    mobi_file = fields.MobiField(storage=get_storage)
+    pdf_file = fields.PdfField(storage=get_storage)
+    cover = fields.CoverField('okładka', storage=get_storage)
 
     ebook_formats = constants.EBOOK_FORMATS
     formats = ebook_formats + ['html', 'xml', 'html_nonotes']
 
     ebook_formats = constants.EBOOK_FORMATS
     formats = ebook_formats + ['html', 'xml', 'html_nonotes']
@@ -639,7 +632,7 @@ class Book(models.Model):
             for filename in os.listdir(gallery_path):
                 file_path = os.path.join(gallery_path, filename)
                 os.unlink(file_path)
             for filename in os.listdir(gallery_path):
                 file_path = os.path.join(gallery_path, filename)
                 os.unlink(file_path)
-        ilustr_elements = list(self.wldocument().edoc.findall('//ilustr'))
+        ilustr_elements = list(self.wldocument().edoc.findall('.//ilustr'))
         if ilustr_elements:
             makedirs(gallery_path)
             for ilustr in ilustr_elements:
         if ilustr_elements:
             makedirs(gallery_path)
             for ilustr in ilustr_elements:
@@ -661,7 +654,7 @@ class Book(models.Model):
         if self.html_file:
             parser = html.HTMLParser(encoding='utf-8')
             tree = html.parse(self.html_file.path, parser=parser)
         if self.html_file:
             parser = html.HTMLParser(encoding='utf-8')
             tree = html.parse(self.html_file.path, parser=parser)
-            toc = tree.find('//div[@id="toc"]/ol')
+            toc = tree.find('.//div[@id="toc"]/ol')
             if toc is None or not len(toc):
                 return
             html_link = reverse('book_text', args=[self.slug])
             if toc is None or not len(toc):
                 return
             html_link = reverse('book_text', args=[self.slug])
@@ -792,11 +785,6 @@ class Book(models.Model):
         # Build cover.
         if 'cover' not in dont_build:
             book.cover.build_delay()
         # Build cover.
         if 'cover' not in dont_build:
             book.cover.build_delay()
-            book.cover_clean.build_delay()
-            book.cover_thumb.build_delay()
-            book.cover_api_thumb.build_delay()
-            book.simple_cover.build_delay()
-            book.cover_ebookpoint.build_delay()
 
         # Build HTML and ebooks.
         book.html_file.build_delay()
 
         # Build HTML and ebooks.
         book.html_file.build_delay()
@@ -1002,11 +990,6 @@ class Book(models.Model):
         if not self.cover_info(inherit=False):
             if 'cover' not in app_settings.DONT_BUILD:
                 self.cover.build_delay()
         if not self.cover_info(inherit=False):
             if 'cover' not in app_settings.DONT_BUILD:
                 self.cover.build_delay()
-                self.cover_clean.build_delay()
-                self.cover_thumb.build_delay()
-                self.cover_api_thumb.build_delay()
-                self.simple_cover.build_delay()
-                self.cover_ebookpoint.build_delay()
             for format_ in constants.EBOOK_FORMATS_WITH_COVERS:
                 if format_ not in app_settings.DONT_BUILD:
                     getattr(self, '%s_file' % format_).build_delay()
             for format_ in constants.EBOOK_FORMATS_WITH_COVERS:
                 if format_ not in app_settings.DONT_BUILD:
                     getattr(self, '%s_file' % format_).build_delay()
index a5df657..c1b0c5f 100644 (file)
@@ -4,11 +4,11 @@
 from collections import OrderedDict
 import json
 from collections import namedtuple
 from collections import OrderedDict
 import json
 from collections import namedtuple
+from django.core.files.storage import storages
 from django.db import models
 from slugify import slugify
 import mutagen
 from mutagen import id3
 from django.db import models
 from slugify import slugify
 import mutagen
 from mutagen import id3
-from fnpdjango.storage import BofhFileSystemStorage
 
 
 def _file_upload_to(i, _n):
 
 
 def _file_upload_to(i, _n):
@@ -21,6 +21,10 @@ def _file_upload_to(i, _n):
     return f'book/{ext}/{name}.{ext}'
 
 
     return f'book/{ext}/{name}.{ext}'
 
 
+def get_storage():
+    return storages['bookmedia']
+
+
 class BookMedia(models.Model):
     """Represents media attached to a book."""
     FileFormat = namedtuple("FileFormat", "name ext")
 class BookMedia(models.Model):
     """Represents media attached to a book."""
     FileFormat = namedtuple("FileFormat", "name ext")
@@ -37,7 +41,7 @@ class BookMedia(models.Model):
     name = models.CharField('nazwa', max_length=512)
     part_name = models.CharField('nazwa części', default='', blank=True, max_length=512)
     index = models.IntegerField('indeks', default=0)
     name = models.CharField('nazwa', max_length=512)
     part_name = models.CharField('nazwa części', default='', blank=True, max_length=512)
     index = models.IntegerField('indeks', default=0)
-    file = models.FileField('plik', max_length=600, upload_to=_file_upload_to, storage=BofhFileSystemStorage())
+    file = models.FileField('plik', max_length=600, upload_to=_file_upload_to, storage=get_storage)
     duration = models.FloatField(null=True, blank=True)
     uploaded_at = models.DateTimeField('data utworzenia', auto_now_add=True, editable=False, db_index=True)
     project_description = models.CharField(max_length=2048, blank=True)
     duration = models.FloatField(null=True, blank=True)
     uploaded_at = models.DateTimeField('data utworzenia', auto_now_add=True, editable=False, db_index=True)
     project_description = models.CharField(max_length=2048, blank=True)
index b82d926..462c231 100644 (file)
@@ -13,8 +13,8 @@
           {% endthumbnail %}
         {% endif %}
       {% else %}
           {% endthumbnail %}
         {% endif %}
       {% else %}
-        {% if book.cover_clean %}
-          <img src="{{ book.cover_clean.url }}" alt="{{ book.title }}">
+        {% if book.cover %}
+          <img src="{{ book.cover.url }}" alt="{{ book.title }}">
         {% endif %}
       {% endif %}
     </a>
         {% endif %}
       {% endif %}
     </a>
index 27748a6..d6444d0 100644 (file)
@@ -38,7 +38,7 @@
               {% if accessible and first_text %}
                 <a href="{% url 'book_text' first_text.slug %}">
               {% endif %}
               {% if accessible and first_text %}
                 <a href="{% url 'book_text' first_text.slug %}">
               {% endif %}
-              <img src="{% if book.cover_clean %}{{ book.cover_clean.url }}{% endif %}" alt="{{ book.pretty_title }}" width="240">
+              <img src="{% if book.cover %}{{ book.cover.url }}{% endif %}" alt="{{ book.pretty_title }}" width="240">
               {% if accessible and first_text %}
                 </a>
               {% endif %}
               {% if accessible and first_text %}
                 </a>
               {% endif %}
                       {% if accessible and first_text %}
                         <a href="{% url 'book_text' first_text.slug %}">
                       {% endif %}
                       {% if accessible and first_text %}
                         <a href="{% url 'book_text' first_text.slug %}">
                       {% endif %}
-                      <img src="{% if book.cover_clean %}{{ book.cover_clean.url }}{% endif %}" alt="{{ book.pretty_title }}">
+                      <img src="{% if book.cover %}{{ book.cover.url }}{% endif %}" alt="{{ book.pretty_title }}">
                       {% if accessible and first_text %}
                         </a>
                       {% endif %}
                       {% if accessible and first_text %}
                         </a>
                       {% endif %}
                 <article class="l-books__item">
                   <figure class="l-books__item__img">
                     <a href="{{ rel.get_absolute_url }}">
                 <article class="l-books__item">
                   <figure class="l-books__item__img">
                     <a href="{{ rel.get_absolute_url }}">
-                      <img src="{% if rel.cover_clean %}{{ rel.cover_clean.url }}{% endif %}" alt="{{ rel.pretty_title }}">
+                      <img src="{% if rel.cover %}{{ rel.cover.url }}{% endif %}" alt="{{ rel.pretty_title }}">
                     </a>
                   </figure>
                   <h3>
                     </a>
                   </figure>
                   <h3>
               <article class="l-books__item">
                 <figure class="l-books__item__img">
                   <a href="{{ rel.get_absolute_url }}">
               <article class="l-books__item">
                 <figure class="l-books__item__img">
                   <a href="{{ rel.get_absolute_url }}">
-                    <img src="{% if rel.cover_clean %}{{ rel.cover_clean.url }}{% endif %}" alt="{{ rel.pretty_title }}">
+                    <img src="{% if rel.cover %}{{ rel.cover.url }}{% endif %}" alt="{{ rel.pretty_title }}">
                   </a>
                 </figure>
                 <h3>
                   </a>
                 </figure>
                 <h3>
index c9e324b..9fece0d 100644 (file)
@@ -6,8 +6,8 @@
         {% if not no_link %}
           <a href="{{ book.get_absolute_url }}">
         {% endif %}
         {% if not no_link %}
           <a href="{{ book.get_absolute_url }}">
         {% endif %}
-          {% if book.cover_clean %}
-            <img src="{% thumbnail book.cover_clean '139x193' as th %}{{ th.url }}{% endthumbnail %}" alt="{{ author }} – {{ book.title }}" class="cover" />
+          {% if book.cover %}
+            <img src="{% thumbnail book.cover '139x193' as th %}{{ th.url }}{% endthumbnail %}" alt="{{ author }} – {{ book.title }}" class="cover" />
           {% endif %}
           {% if book.is_foreign %}
             <span class="language" title="{{ book.language_name }}">{{ book.language_code }}</span>
           {% endif %}
           {% if book.is_foreign %}
             <span class="language" title="{{ book.language_name }}">{{ book.language_code }}</span>
index ad0089a..a8479d5 100644 (file)
@@ -29,7 +29,7 @@
   <li>
     <a href="{{ book.get_absolute_url }}" id="menu-book" data-box="book-short">
       <span class="label">{% trans "Kliknij, by pobrać" %}:</span>
   <li>
     <a href="{{ book.get_absolute_url }}" id="menu-book" data-box="book-short">
       <span class="label">{% trans "Kliknij, by pobrać" %}:</span>
-      <img src="{% if book.cover_clean %}{% thumbnail book.cover_clean '240x332' as thumb %}{{ thumb.url }}{% empty %}{{ book.cover_clean.url }}{% endthumbnail %}{% endif %}"
+      <img src="{% if book.cover %}{% thumbnail book.cover '240x332' as thumb %}{{ thumb.url }}{% empty %}{{ book.cover.url }}{% endthumbnail %}{% endif %}"
            width="120" height="166"
            alt="{{ book.pretty_title }}"
            title="{{ book.pretty_title }}">
            width="120" height="166"
            alt="{{ book.pretty_title }}"
            title="{{ book.pretty_title }}">
   </div>
 
   <header class="l-text_header">
   </div>
 
   <header class="l-text_header">
-    <img class="l-text_header_cover" src="{% if book.cover_clean %}{{ book.cover_clean.url }}{% endif %}" alt="{{ book.pretty_title }}">
+    <img class="l-text_header_cover" src="{% if book.cover %}{{ book.cover.url }}{% endif %}" alt="{{ book.pretty_title }}">
 
     <div class="l-text_header__content">
       <p class="l-text_header_author">{% for author in book.authors %}<a href="{{ author.get_absolute_url }}">{{ author.name }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}
 
     <div class="l-text_header__content">
       <p class="l-text_header_author">{% for author in book.authors %}<a href="{{ author.get_absolute_url }}">{{ author.name }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}
index 495fe23..f52fbfa 100644 (file)
@@ -2,7 +2,7 @@
   <a href="{{ collection.get_absolute_url }}">
     <div class="c-collectionbox-covers">
       {% for c in collection.example3 %}
   <a href="{{ collection.get_absolute_url }}">
     <div class="c-collectionbox-covers">
       {% for c in collection.example3 %}
-        <img src="{{ c.cover_clean.url }}">
+        <img src="{{ c.cover.url }}">
       {% endfor %}
     </div>
     {{ collection.title }}
       {% endfor %}
     </div>
     {{ collection.title }}
index 49023c6..3ceaa50 100644 (file)
@@ -2,8 +2,8 @@
 <article class="l-books__item">
   <figure class="l-books__item__img">
     <a href="{{ fragment.get_absolute_url }}">
 <article class="l-books__item">
   <figure class="l-books__item__img">
     <a href="{{ fragment.get_absolute_url }}">
-      {% if fragment.book.cover_clean %}
-        <img src="{{ fragment.book.cover_clean.url }}" alt="{{ fragment.book.title }}">
+      {% if fragment.book.cover %}
+        <img src="{{ fragment.book.cover.url }}" alt="{{ fragment.book.title }}">
       {% endif %}
     </a>
     <div class="l-books__item__actions">
       {% endif %}
     </a>
     <div class="l-books__item__actions">
index 5cfbb12..0e657a2 100644 (file)
@@ -16,9 +16,9 @@
   </div>
   <div class="l-navigation__menu__book__info">
     <h3>
   </div>
   <div class="l-navigation__menu__book__info">
     <h3>
-      {% if book.cover_clean %}
+      {% if book.cover %}
         <a href="{{ book.get_absolute_url }}" tabindex="-1">
         <a href="{{ book.get_absolute_url }}" tabindex="-1">
-          <img src="{{ book.cover_clean.url }}" alt="{{ book.pretty_title }}">
+          <img src="{{ book.cover.url }}" alt="{{ book.pretty_title }}">
         </a>
       {% endif %}
       <a href="{{ book.get_absolute_url }}" tabindex="-1">
         </a>
       {% endif %}
       <a href="{{ book.get_absolute_url }}" tabindex="-1">
index 7755a89..1daec39 100644 (file)
@@ -4,10 +4,10 @@
     <h3>{% trans "Prapremiera" %}</h3>
     <div class="p-homepage-prapremiera__box">
       <div class="p-homepage-prapremiera__box__item">
     <h3>{% trans "Prapremiera" %}</h3>
     <div class="p-homepage-prapremiera__box">
       <div class="p-homepage-prapremiera__box__item">
-        {% if book.cover_clean %}
+        {% if book.cover %}
         <figure>
           <a href="{{ book.get_absolute_url }}">
         <figure>
           <a href="{{ book.get_absolute_url }}">
-            <img src="{{ book.cover_clean.url }}" alt="{{ book.pretty_title }}">
+            <img src="{{ book.cover.url }}" alt="{{ book.pretty_title }}">
           </a>
         </figure>
         {% endif %}
           </a>
         </figure>
         {% endif %}
index 267d6be..e6e567b 100644 (file)
@@ -334,3 +334,20 @@ def set_file_permissions(self, fieldfile):
     if fieldfile.instance.preview:
         fieldfile.set_readable(False)
 
     if fieldfile.instance.preview:
         fieldfile.set_readable(False)
 
+
+CHUNK_SIZE = 1024 * 1024  # 1 MB
+
+def iter_file(field_file, chunk_size=CHUNK_SIZE):
+    storage = field_file.storage
+    if hasattr(storage, "bucket"):
+        # If through S3Storage, chunk directly from
+        # boto interface to avoid loading the whole thing.
+        key = storage._normalize_name(field_file.name)
+        body = storage.bucket.Object(key).get()["Body"]
+        try:
+            yield from body.iter_chunks(chunk_size)
+        finally:
+            body.close()
+    else:
+        with field_file.open("rb") as f:
+            yield from f.chunks(chunk_size)
index b8f42b1..45c2485 100644 (file)
@@ -523,7 +523,7 @@ def stream_zip(request, media_format=None, slug=None):
     def iterate_audiobooks(book, names):
         for bm in book.media.filter(type=media_format).order_by('index'):
             yield (
     def iterate_audiobooks(book, names):
         for bm in book.media.filter(type=media_format).order_by('index'):
             yield (
-                bm.file.path,
+                bm.file,
                 bm.get_extra_info_json().get('license'),
                 names + (slugify(bm.part_name),) if bm.part_name else names
             )
                 bm.get_extra_info_json().get('license'),
                 names + (slugify(bm.part_name),) if bm.part_name else names
             )
@@ -535,17 +535,17 @@ def stream_zip(request, media_format=None, slug=None):
     audiobook_list = list(iterate_audiobooks(book, ()))
     
     licenses = set()
     audiobook_list = list(iterate_audiobooks(book, ()))
     
     licenses = set()
-    for i, (file_path, lic, names) in enumerate(audiobook_list):
+    for i, (bmfile, lic, names) in enumerate(audiobook_list):
         index = i + 1
         part_name = '_'.join(names)
         if part_name:
             part_name = '_' + part_name
         index = i + 1
         part_name = '_'.join(names)
         if part_name:
             part_name = '_' + part_name
-        ext = file_path.rsplit('.', 1)[-1]
+        ext = bmfile.name.rsplit('.', 1)[-1]
         if len(audiobook_list) > 1:
             zip_name = f'{book.slug}_{index:03d}{part_name}'[:240] + '.' + ext
         else:
             zip_name = book.slug[:240] + '.' + ext
         if len(audiobook_list) > 1:
             zip_name = f'{book.slug}_{index:03d}{part_name}'[:240] + '.' + ext
         else:
             zip_name = book.slug[:240] + '.' + ext
-        zs.add_path(file_path, zip_name)
+        zs.add(iter_file(bmfile), zip_name)
 
         lic_name = constants.LICENSES.get(lic, {}).get('locative')
         if lic_name:
 
         lic_name = constants.LICENSES.get(lic, {}).get('locative')
         if lic_name:
index 607f5e0..d3145f7 100644 (file)
     {% for ref in entity.reference_set.all|slice:":3" %}
     <div class="fragment">
       <div class="cover">
     {% for ref in entity.reference_set.all|slice:":3" %}
     <div class="fragment">
       <div class="cover">
-        <img src="{{ ref.book.cover_clean.url }}" alt="Okładka: {{ ref.book.pretty_title }}">
+        <img src="{{ ref.book.cover.url }}" alt="Okładka: {{ ref.book.pretty_title }}">
       </div>
       <div class="frag-text">
         <div class="book"><b>
       </div>
       <div class="frag-text">
         <div class="book"><b>
index 6ee12ce..7cd0051 100644 (file)
@@ -18,7 +18,7 @@
   <div class="c-search-result-fragment">
     <div class="l-popup-book-header">
       <div>
   <div class="c-search-result-fragment">
     <div class="l-popup-book-header">
       <div>
-        {% thumbnail ref.book.cover_clean '150x150' as th %}
+        {% thumbnail ref.book.cover '150x150' as th %}
         <a href="{{ ref.book.get_absolute_url }}" target="_blank">
           <img src="{{ th.url }}" alt="{{ ref.book.pretty_title }}" title="{{ ref.book.pretty_title }}">
         {% endthumbnail %}
         <a href="{{ ref.book.get_absolute_url }}" target="_blank">
           <img src="{{ th.url }}" alt="{{ ref.book.pretty_title }}" title="{{ ref.book.pretty_title }}">
         {% endthumbnail %}
index 6a9e1ea..1c26acc 100644 (file)
@@ -91,7 +91,7 @@ def get_hints(prefix, user=None, limit=10):
                     'label': b.title,
                     'author': author_str,
                     'url': b.get_absolute_url(),
                     'label': b.title,
                     'author': author_str,
                     'url': b.get_absolute_url(),
-                    'img': get_thumbnail(b.cover_clean, '72x72').url if b.cover_clean else '',
+                    'img': get_thumbnail(b.cover, '72x72').url if b.cover else '',
                     'slug': b.slug,
                 }
             )
                     'slug': b.slug,
                 }
             )
index 505d139..2ee5e2a 100644 (file)
@@ -1,13 +1,13 @@
 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
 #
 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
 #
-from os import path
+import os
 from .paths import VAR_DIR
 
 # Absolute path to the directory that holds media.
 # Example: "/home/media/media.lawrence.com/"
 from .paths import VAR_DIR
 
 # Absolute path to the directory that holds media.
 # Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = path.join(VAR_DIR, 'media/')
-STATIC_ROOT = path.join(VAR_DIR, 'static/')
+MEDIA_ROOT = os.path.join(VAR_DIR, 'media/')
+STATIC_ROOT = os.path.join(VAR_DIR, 'static/')
 
 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
 # trailing slash if there is a path component (optional in other cases).
 
 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
 # trailing slash if there is a path component (optional in other cases).
@@ -144,16 +144,57 @@ PIPELINE = {
     'CSSMIN_ARGUMENTS': '--stdin --style=compressed --no-source-map',
 }
 
     'CSSMIN_ARGUMENTS': '--stdin --style=compressed --no-source-map',
 }
 
+
 STORAGES = {
     'default': {
         'BACKEND': 'django.core.files.storage.FileSystemStorage'
     },
 STORAGES = {
     'default': {
         'BACKEND': 'django.core.files.storage.FileSystemStorage'
     },
+    'book': {
+        'BACKEND': 'django.core.files.storage.FileSystemStorage',
+        'OPTIONS': {
+            'allow_overwrite': True,
+        },
+    },
+    'bookmedia': {
+        'BACKEND': 'django.core.files.storage.FileSystemStorage',
+        'OPTIONS': {
+            'allow_overwrite': True,
+        },
+    },
     'staticfiles': {
         'BACKEND': 'fnpdjango.pipeline_storage.GzipPipelineManifestStorage'
     },
 }
 
 
     'staticfiles': {
         'BACKEND': 'fnpdjango.pipeline_storage.GzipPipelineManifestStorage'
     },
 }
 
 
+# Switch bookmedia to s3 if set.
+WL_BOOKMEDIA_STORAGE_MODE = os.environ.get(
+    "WL_BOOKMEDIA_STORAGE_MODE", "local") # or s3
+
+if WL_BOOKMEDIA_STORAGE_MODE == "s3":
+    AWS_S3_REGION_NAME = os.environ.get("WL_S3_REGION", "waw")
+    AWS_S3_ENDPOINT_URL = os.environ.get(
+        "WL_S3_ENDPOINT", f"https://s3.{AWS_S3_REGION_NAME}.io.cloud.ovh.net"
+    )
+    WL_S3_BUCKET = os.environ.get("WL_S3_BUCKET")
+    STORAGES['bookmedia'] = {
+        "BACKEND": "storages.backends.s3.S3Storage",
+        "OPTIONS": {
+            "bucket_name": WL_S3_BUCKET,
+            "access_key": os.environ.get("WL_S3_ACCESS_KEY"),
+            "secret_key": os.environ.get("WL_S3_SECRET_KEY"),
+            "custom_domain": os.environ.get(
+                "WL_S3_CUSTOM_DOMAIN",
+                f"{WL_S3_BUCKET}.s3.{AWS_S3_REGION_NAME}.io.cloud.ovh.net"
+            ),
+            "default_acl": "public-read",
+            "querystring_auth": False,
+            "file_overwrite": True,
+        }
+    }
+
+
+
 STATICFILES_FINDERS = [
     'django.contrib.staticfiles.finders.FileSystemFinder',
     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
 STATICFILES_FINDERS = [
     'django.contrib.staticfiles.finders.FileSystemFinder',
     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
index 611ee3c..345453d 100644 (file)
@@ -31,7 +31,7 @@ def main_page(request):
         request.EXPERIMENTS['layout'].override(True)
 
     ctx = {}
         request.EXPERIMENTS['layout'].override(True)
 
     ctx = {}
-    ctx['last_published'] = Book.objects.exclude(cover_clean='').filter(findable=True, parent=None).order_by('-created_at')[:10]
+    ctx['last_published'] = Book.objects.exclude(cover='').filter(findable=True, parent=None).order_by('-created_at')[:10]
     ctx['recommended_collection'] = Collection.objects.filter(listed=True, role='recommend').order_by('?').first()
     ctx['ambassadors'] = club.models.Ambassador.objects.all().order_by('?')
     ctx['widget'] = settings.WIDGETS.get(request.GET.get('w'))
     ctx['recommended_collection'] = Collection.objects.filter(listed=True, role='recommend').order_by('?').first()
     ctx['ambassadors'] = club.models.Ambassador.objects.all().order_by('?')
     ctx['widget'] = settings.WIDGETS.get(request.GET.get('w'))