From: Radek Czajka Date: Tue, 30 Jan 2024 16:36:41 +0000 (+0100) Subject: Support cover logo X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/51ea493dd4c46246c80ed3190b43ebfc0d75d67c?ds=sidebyside Support cover logo --- diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 8feffa88..68dab26a 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -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 diff --git a/src/cover/views.py b/src/cover/views.py index 39b12f91..5ea4a6c2 100644 --- a/src/cover/views.py +++ b/src/cover/views.py @@ -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) diff --git a/src/depot/publishers/woblink.py b/src/depot/publishers/woblink.py index 64eca06e..3e1c78c8 100644 --- a/src/depot/publishers/woblink.py +++ b/src/depot/publishers/woblink.py @@ -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 index 00000000..6b9f7e10 --- /dev/null +++ b/src/documents/migrations/0014_project_logo_project_logo_mono.py @@ -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" + ), + ), + ] diff --git a/src/documents/models/book.py b/src/documents/models/book.py index bede8d09..fa93eeb9 100644 --- a/src/documents/models/book.py +++ b/src/documents/models/book.py @@ -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) diff --git a/src/documents/models/project.py b/src/documents/models/project.py index cc78ba58..ed066f18 100644 --- a/src/documents/models/project.py +++ b/src/documents/models/project.py @@ -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'