From 8885fd14f5f040eb3aa69f1d705856f99a1fa572 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 31 Jan 2024 08:44:46 +0100 Subject: [PATCH] Missing logos. --- requirements/requirements.txt | 2 +- src/annoy/static/annoy/banner.js | 4 +- src/catalogue/fields.py | 64 +++++++++++++------ src/catalogue/forms.py | 4 ++ src/catalogue/models/book.py | 17 +++-- .../templates/catalogue/book_info.html | 7 ++ .../templates/catalogue/book_text.html | 6 ++ src/catalogue/views.py | 1 + .../migrations/0045_alter_payuorder_pos_id.py | 18 ++++++ src/club/payu/models.py | 2 +- ...er_ip_alter_funding_notify_key_and_more.py | 28 ++++++++ src/funding/models.py | 4 +- src/references/templates/references/map.html | 2 +- src/references/views.py | 2 +- .../static/2022/styles/components/_media.scss | 1 + .../static/2022/styles/layout/_annoy.scss | 2 + .../static/2022/styles/layout/_module.scss | 1 + 17 files changed, 134 insertions(+), 31 deletions(-) create mode 100644 src/club/migrations/0045_alter_payuorder_pos_id.py create mode 100644 src/funding/migrations/0011_alter_funding_customer_ip_alter_funding_notify_key_and_more.py diff --git a/requirements/requirements.txt b/requirements/requirements.txt index acae07666..0fa614370 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -39,7 +39,7 @@ mutagen==1.45.1 sorl-thumbnail==12.8.0 # home-brewed & dependencies -librarian==23.10 +librarian==24.1 # celery tasks celery[redis]==5.2.7 diff --git a/src/annoy/static/annoy/banner.js b/src/annoy/static/annoy/banner.js index 74a7292e6..791741a15 100644 --- a/src/annoy/static/annoy/banner.js +++ b/src/annoy/static/annoy/banner.js @@ -11,14 +11,14 @@ e.preventDefault(); $target.slideDown('fast'); $on.hide(); - if (Modernizr.localstorage) localStorage.removeItem(tag); + localStorage.removeItem(tag); _paq.push(['trackEvent', 'banner', 'banner-unhide', $target.attr('id')]); }); $off.click(function() { $target.slideUp('fast'); $on.show(); - if (Modernizr.localstorage) localStorage[tag] = true; + localStorage[tag] = true; _paq.push(['trackEvent', 'banner', 'banner-hide', $target.attr('id')]); }); diff --git a/src/catalogue/fields.py b/src/catalogue/fields.py index 646ab1515..087fe0d88 100644 --- a/src/catalogue/fields.py +++ b/src/catalogue/fields.py @@ -1,15 +1,19 @@ # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # +import io import os import pkg_resources import random +import time +from urllib.request import urlopen from django.apps import apps from django.conf import settings from django.core.files import File from django.db import models from django.db.models.fields.files import FieldFile from django.utils.deconstruct import deconstructible +from librarian.cover import make_cover from catalogue.constants import LANGUAGES_3TO2 from catalogue.utils import absolute_url, remove_zip, truncate_html_words, gallery_path, gallery_url from waiter.utils import clear_cache @@ -31,6 +35,25 @@ class UploadToPath(object): return isinstance(other, type(self)) and other.path == self.path +def get_make_cover(book): + extra = book.get_extra_info_json() + cover_logo = extra.get('logo_mono', extra.get('logo')) + if cover_logo: + while True: + try: + cover_logo = io.BytesIO(urlopen(cover_logo, timeout=3).read()) + except: + time.sleep(2) + else: + break + + def mc(*args, **kwargs): + if cover_logo: + kwargs['cover_logo'] = cover_logo + return make_cover(*args, **kwargs) + return mc + + class EbookFieldFile(FieldFile): """Represents contents of an ebook file field.""" @@ -172,7 +195,7 @@ class EbookField(models.FileField): return found @staticmethod - def transform(wldoc): + def transform(wldoc, book): """Transforms an librarian.WLDocument into an librarian.OutputFile. """ raise NotImplemented() @@ -185,6 +208,7 @@ class EbookField(models.FileField): book = fieldfile.instance out = self.transform( book.wldocument2() if self.librarian2_api else book.wldocument(), + book, ) with open(out.get_filename(), 'rb') as f: fieldfile.save(None, File(f), save=False) @@ -207,7 +231,7 @@ class TxtField(EbookField): for_parents = False @staticmethod - def transform(wldoc): + def transform(wldoc, book): return wldoc.as_text() @@ -217,7 +241,7 @@ class Fb2Field(EbookField): ZIP = 'wolnelektury_pl_fb2' @staticmethod - def transform(wldoc): + def transform(wldoc, book): return wldoc.as_fb2() @@ -226,9 +250,10 @@ class PdfField(EbookField): ZIP = 'wolnelektury_pl_pdf' @staticmethod - def transform(wldoc): + def transform(wldoc, book): return wldoc.as_pdf( - morefloats=settings.LIBRARIAN_PDF_MOREFLOATS, cover=True, + morefloats=settings.LIBRARIAN_PDF_MOREFLOATS, + cover=get_make_cover(book), base_url=absolute_url(gallery_url(wldoc.book_info.url.slug)), customizations=['notoc']) def build(self, fieldfile): @@ -242,12 +267,13 @@ class EpubField(EbookField): ZIP = 'wolnelektury_pl_epub' @staticmethod - def transform(wldoc): + def transform(wldoc, book): from librarian.builders import EpubBuilder MediaInsertSet = apps.get_model('annoy', 'MediaInsertSet') return EpubBuilder( base_url='file://' + os.path.abspath(gallery_path(wldoc.meta.url.slug)) + '/', - fundraising=MediaInsertSet.get_texts_for('epub') + fundraising=MediaInsertSet.get_texts_for('epub'), + cover=get_make_cover(book), ).build(wldoc) @@ -257,12 +283,13 @@ class MobiField(EbookField): ZIP = 'wolnelektury_pl_mobi' @staticmethod - def transform(wldoc): + def transform(wldoc, book): from librarian.builders import MobiBuilder MediaInsertSet = apps.get_model('annoy', 'MediaInsertSet') return MobiBuilder( base_url='file://' + os.path.abspath(gallery_path(wldoc.meta.url.slug)) + '/', - fundraising=MediaInsertSet.get_texts_for('mobi') + fundraising=MediaInsertSet.get_texts_for('mobi'), + cover=get_make_cover(book), ).build(wldoc) @@ -359,7 +386,7 @@ class HtmlField(EbookField): return False @staticmethod - def transform(wldoc): + def transform(wldoc, book): # ugly, but we can't use wldoc.book_info here from librarian import DCNS url_elem = wldoc.edoc.getroot().find('.//' + DCNS('identifier.url')) @@ -378,8 +405,8 @@ class CoverField(EbookField): directory = 'cover' @staticmethod - def transform(wldoc): - return wldoc.as_cover() + def transform(wldoc, book): + return get_make_cover(book)(wldoc.book_info, width=360).output_file() def set_file_permissions(self, fieldfile): pass @@ -389,16 +416,15 @@ class CoverCleanField(CoverField): directory = 'cover_clean' @staticmethod - def transform(wldoc): - from librarian.covers.marquise import MarquiseCover - return MarquiseCover(wldoc.book_info, width=360).output_file() + 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): + def transform(wldoc, book): from librarian.cover import WLCover return WLCover(wldoc.book_info, height=193).output_file() @@ -407,7 +433,7 @@ class CoverApiThumbField(CoverField): directory = 'cover_api_thumb' @staticmethod - def transform(wldoc): + def transform(wldoc, book): from librarian.cover import WLNoBoxCover return WLNoBoxCover(wldoc.book_info, height=500).output_file() @@ -416,7 +442,7 @@ class SimpleCoverField(CoverField): directory = 'cover_simple' @staticmethod - def transform(wldoc): + def transform(wldoc, book): from librarian.cover import WLNoBoxCover return WLNoBoxCover(wldoc.book_info, height=1000).output_file() @@ -425,6 +451,6 @@ class CoverEbookpointField(CoverField): directory = 'cover_ebookpoint' @staticmethod - def transform(wldoc): + def transform(wldoc, book): from librarian.cover import EbookpointCover return EbookpointCover(wldoc.book_info).output_file() diff --git a/src/catalogue/forms.py b/src/catalogue/forms.py index 100f79496..055800edc 100644 --- a/src/catalogue/forms.py +++ b/src/catalogue/forms.py @@ -17,6 +17,8 @@ class BookImportForm(forms.Form): gallery_url = forms.CharField(required=False) days = forms.IntegerField(required=False) hidden = forms.BooleanField(required=False) + logo = forms.CharField(required=False) + logo_mono = forms.CharField(required=False) def clean(self): from django.core.files.base import ContentFile @@ -34,6 +36,8 @@ class BookImportForm(forms.Form): remote_gallery_url=self.cleaned_data['gallery_url'], days=self.cleaned_data['days'], findable=not self.cleaned_data['hidden'], + logo=self.cleaned_data['logo'], + logo_mono=self.cleaned_data['logo_mono'], **kwargs) diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index 411476aa0..b14269f8d 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -594,7 +594,7 @@ class Book(models.Model): @classmethod def from_text_and_meta(cls, raw_file, book_info, overwrite=False, dont_build=None, search_index=True, - remote_gallery_url=None, days=0, findable=True): + remote_gallery_url=None, days=0, findable=True, logo=None, logo_mono=None): from catalogue import tasks if dont_build is None: @@ -641,7 +641,12 @@ class Book(models.Model): book.common_slug = book_info.variant_of.slug else: book.common_slug = book.slug - book.extra_info = json.dumps(book_info.to_dict()) + extra = book_info.to_dict() + if logo: + extra['logo'] = logo + if logo_mono: + extra['logo_mono'] = logo_mono + book.extra_info = json.dumps(extra) book.load_abstract() book.load_toc() book.save() @@ -729,8 +734,12 @@ class Book(models.Model): else: entity, entity_created = Entity.objects.get_or_create(uri=uri) if entity_created: - entity.populate() - entity.save() + try: + entity.populate() + except: + pass + else: + entity.save() ref, ref_created = entity.reference_set.get_or_create(book=self) refs[uri] = ref if not ref_created: diff --git a/src/catalogue/templates/catalogue/book_info.html b/src/catalogue/templates/catalogue/book_info.html index 3da38b2a7..424d75980 100644 --- a/src/catalogue/templates/catalogue/book_info.html +++ b/src/catalogue/templates/catalogue/book_info.html @@ -1,5 +1,6 @@ {% load i18n %} {% load catalogue_tags %} +{% load thumbnail %} {% with extra_info=book.get_extra_info_json %}

@@ -39,6 +40,12 @@

{{ extra_info.description }}

{% endif %} + {% if extra_info.logo %} + {% thumbnail extra_info.logo '300x200' as th %} + + {% endthumbnail %} + {% endif %} + {% if extra_info.editor or extra_info.technical_editor %}

{% if is_picture %} diff --git a/src/catalogue/templates/catalogue/book_text.html b/src/catalogue/templates/catalogue/book_text.html index d9474b5a8..041a07a28 100644 --- a/src/catalogue/templates/catalogue/book_text.html +++ b/src/catalogue/templates/catalogue/book_text.html @@ -61,6 +61,12 @@ + {% if extra_info.logo_mono %} + {% thumbnail extra_info.logo_mono '200x200' as th %} + + {% endthumbnail %} + {% endif %} + {% trans "Numeracja" %} - + diff --git a/src/references/views.py b/src/references/views.py index 3c12c8f46..7e0e3574b 100644 --- a/src/references/views.py +++ b/src/references/views.py @@ -8,7 +8,7 @@ from . import models def pin_map(request): return render(request, 'references/map.html', { - 'title': 'Wakacje', + 'title': 'Mapa Wolnych Lektur', 'entities': models.Entity.objects.exclude(lat=None).exclude(lon=None), 'funding_no_show_current': True, }) diff --git a/src/wolnelektury/static/2022/styles/components/_media.scss b/src/wolnelektury/static/2022/styles/components/_media.scss index ebeb7aad2..c4af4ebd1 100644 --- a/src/wolnelektury/static/2022/styles/components/_media.scss +++ b/src/wolnelektury/static/2022/styles/components/_media.scss @@ -52,6 +52,7 @@ border-radius: 0 0 5px 5px; margin: 0 auto; display: flex; + gap: 10px; align-items: center; justify-content: space-between; position: relative; diff --git a/src/wolnelektury/static/2022/styles/layout/_annoy.scss b/src/wolnelektury/static/2022/styles/layout/_annoy.scss index 432ee4d0c..f0f06360a 100644 --- a/src/wolnelektury/static/2022/styles/layout/_annoy.scss +++ b/src/wolnelektury/static/2022/styles/layout/_annoy.scss @@ -14,6 +14,7 @@ background: linear-gradient(180deg, rgba(0,0,0,1) 90%, rgba(0,0, 0,.5) 100%); .annoy-banner-inner { + max-height: 100vh; overflow-y: auto; padding: 0 0 30px 0; display: flex; @@ -55,6 +56,7 @@ .annoy-banner-inner { padding: 0; margin: 10vh 10vw 20vh 10vw; + max-height: 70vh; flex-direction: row; overflow-y: unset; diff --git a/src/wolnelektury/static/2022/styles/layout/_module.scss b/src/wolnelektury/static/2022/styles/layout/_module.scss index 6aabadaea..3111fd3f1 100644 --- a/src/wolnelektury/static/2022/styles/layout/_module.scss +++ b/src/wolnelektury/static/2022/styles/layout/_module.scss @@ -4,6 +4,7 @@ /*!*/ +@import "annoy"; @import "navigation"; @import "header"; @import "main"; -- 2.20.1