Support cover logo
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 30 Jan 2024 16:36:41 +0000 (17:36 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 30 Jan 2024 16:36:41 +0000 (17:36 +0100)
requirements/requirements.txt
src/cover/views.py
src/depot/publishers/woblink.py
src/documents/migrations/0014_project_logo_project_logo_mono.py [new file with mode: 0644]
src/documents/models/book.py
src/documents/models/project.py

index 8feffa8..68dab26 100644 (file)
@@ -10,7 +10,7 @@ python-slugify==8.0.1
 python-docx==0.8.11
 Wikidata==0.7
 
-librarian==23.12
+librarian==24.1
 
 ## Django
 Django==4.1.9
index 39b12f9..5ea4a6c 100644 (file)
@@ -65,7 +65,11 @@ def preview(request, book, chunk=None, rev=None):
 
     cover_class = request.GET.get('cover_class', 'default')
 
-    cover = make_cover(info, cover_class=cover_class, width=width, height=height)
+    kwargs = {}
+    if chunk.book.project is not None:
+        if chunk.book.project.logo_mono or chunk.book.project.logo:
+            kwargs['cover_logo'] = (chunk.book.project.logo_mono or chunk.book.project.logo).path
+    cover = make_cover(info, cover_class=cover_class, width=width, height=height, **kwargs)
     response = HttpResponse(content_type=cover.mime_type())
     img = cover.final_image()
     img.save(response, cover.format)
index 64eca06..3e1c78c 100644 (file)
@@ -187,6 +187,7 @@ class Woblink(BasePublisher):
                 (self.ROLE_TRANSLATOR, meta.translators, False)
         ]:
             for person_literal in items:
+                if person_literal is None: continue
                 if person_literal.lang != 'pl':
                     if errors is not None:
                         if obligatory:
diff --git a/src/documents/migrations/0014_project_logo_project_logo_mono.py b/src/documents/migrations/0014_project_logo_project_logo_mono.py
new file mode 100644 (file)
index 0000000..6b9f7e1
--- /dev/null
@@ -0,0 +1,25 @@
+# Generated by Django 4.1.9 on 2024-01-30 16:22
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("documents", "0013_alter_chunkchange_publishable_and_more"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="project",
+            name="logo",
+            field=models.FileField(blank=True, upload_to="projects"),
+        ),
+        migrations.AddField(
+            model_name="project",
+            name="logo_mono",
+            field=models.FileField(
+                blank=True, help_text="white on transparent", upload_to="logo_mono"
+            ),
+        ),
+    ]
index bede8d0..fa93eeb 100644 (file)
@@ -23,6 +23,7 @@ from io import BytesIO
 import os
 import shutil
 import re
+from urllib.parse import urljoin
 
 
 class Book(models.Model):
@@ -399,7 +400,11 @@ class Book(models.Model):
         try:
             xml = self.materialize(publishable=True).encode('utf-8')
             info = BookInfo.from_bytes(xml)
-            cover = make_cover(info, width=width, height=height)
+            kwargs = {}
+            if chunk.book.project is not None:
+                if chunk.book.project.logo_mono or chunk.book.project.logo:
+                    kwargs['cover_logo'] = (chunk.book.project.logo_mono or chunk.book.project.logo).path
+            cover = make_cover(info, width=width, height=height, **kwargs)
             out = BytesIO()
             ext = cover.ext()
             cover.save(out)
@@ -464,6 +469,17 @@ class Book(models.Model):
         if not fake:
             book_xml = self.materialize(changes=changes)
             data = {"book_xml": book_xml, "days": days, "hidden": hidden}
+            if self.project is not None:
+                if self.project.logo:
+                    data['logo'] = urljoin(
+                        'https://' + Site.objects.get_current().domain,
+                        self.project.logo.url,
+                    )
+                if self.project.logo_mono:
+                    data['logo_mono'] = urljoin(
+                        'https://' + Site.objects.get_current().domain,
+                        self.project.logo.url,
+                    )
             if host:
                 data['gallery_url'] = host + self.gallery_url()
             apiclient.api_call(user, "books/", data, beta=beta)
index cc78ba5..ed066f1 100644 (file)
@@ -10,6 +10,8 @@ class Project(models.Model):
 
     name = models.CharField(_('name'), max_length=255, unique=True)
     notes = models.TextField(_('notes'), blank=True, null=True)
+    logo = models.FileField(upload_to='projects', blank=True)
+    logo_mono = models.FileField(upload_to='logo_mono', help_text='white on transparent', blank=True)
 
     class Meta:
         app_label = 'documents'