From 289e09f5588e3afdec2256c4f1e450f7fd9d742d Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Mon, 5 May 2025 16:25:51 +0200 Subject: [PATCH] Placeholdery, vol 1 --- .../static/galerie/neznamy_placeholder.svg | 38 +++++++++++++ galerie/static/galerie/video_placeholder.svg | 54 +++++++++++++++++++ galerie/typy.py | 35 +++++++++--- 3 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 galerie/static/galerie/neznamy_placeholder.svg create mode 100644 galerie/static/galerie/video_placeholder.svg diff --git a/galerie/static/galerie/neznamy_placeholder.svg b/galerie/static/galerie/neznamy_placeholder.svg new file mode 100644 index 00000000..d4482304 --- /dev/null +++ b/galerie/static/galerie/neznamy_placeholder.svg @@ -0,0 +1,38 @@ + + + + + + + + + + + + + diff --git a/galerie/static/galerie/video_placeholder.svg b/galerie/static/galerie/video_placeholder.svg new file mode 100644 index 00000000..a06ed632 --- /dev/null +++ b/galerie/static/galerie/video_placeholder.svg @@ -0,0 +1,54 @@ + + + + + + + + + + + + diff --git a/galerie/typy.py b/galerie/typy.py index ae71a5f8..936750e4 100644 --- a/galerie/typy.py +++ b/galerie/typy.py @@ -12,8 +12,12 @@ import logging logger = logging.getLogger(__name__) +from django.contrib.staticfiles.finders import find +# FIXME: static fily na lokálním webu?? +find = lambda x: '/static/'+x from django.utils.safestring import mark_safe, SafeString from django.utils.html import format_html, format_html_join +from django.urls import reverse from imagekit import ImageSpec from imagekit.cachefiles import ImageCacheFile @@ -68,6 +72,9 @@ class ObrazekMalySpec(ImageSpec): format = 'JPEG' options = {'quality': 95} +def _fmt_attrs(attrs): + return format_html_join(' ', r'{}="{}"', ((mark_safe(k), v) for k, v in attrs.items())) + class Obrazek(ZobrazitelnyBazmek): """Obrázek pro zobrazení @@ -80,34 +87,46 @@ class Obrazek(ZobrazitelnyBazmek): # Jak se takový cachefile používá je potřeba vyčíst ze zdrojáků? file = ImageCacheFile(ObrazekStredniSpec(source=self.soubor)) file.generate() - attrs = format_html_join(' ', r'{}="{}"', ((mark_safe(k), v) for k, v in kwargs.items())) + attrs = _fmt_attrs(kwargs) html = format_html(r'', file.url, attrs) return html def zmenseny_nahled(self, **kwargs): file = ImageCacheFile(ObrazekMalySpec(source=self.soubor)) file.generate() - attrs = format_html_join(' ', r'{}="{}"', ((mark_safe(k), v) for k, v in kwargs.items())) + attrs = _fmt_attrs(kwargs) html = format_html(r'', file.url, attrs) return html class Video(ZobrazitelnyBazmek): + def __init__(self, *a, **kwa): + super().__init__(*a, **kwa) + self.placeholder = find('galerie/video_placeholder.svg') + def zobrazit(self, **kwargs): - attrs = format_html_join(' ', r'{}="{}"', ((mark_safe(k), v) for k, v in kwargs.items())) + attrs = _fmt_attrs(kwargs) # Atributy specifické pro video musíme vesměs vyřešit tady… (šlo by to {% if %}-ovat podle typu, ale to je spíš haluz. html = format_html(r'