Placeholdery, vol 1

This commit is contained in:
Pavel "LEdoian" Turinsky 2025-05-05 16:25:51 +02:00
parent 5d67227bfe
commit 289e09f558
3 changed files with 119 additions and 8 deletions

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="768"
height="576"
viewBox="0 0 768 576"
version="1.1"
id="svg1"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs1" />
<g
id="layer1">
<path
style="fill:#6f2509;stroke:#6f2509;stroke-width:24.4876;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;paint-order:markers fill stroke;fill-opacity:1"
id="path1"
d="m 171.56486,156.34958 277.81099,481.18278 -555.62201,-2e-5 z"
transform="translate(212.43515,-108.94158)" />
<g
id="g4"
style="fill:#ff0000"
transform="matrix(0.63613865,0,0,0.62847938,383.26722,188.1938)">
<circle
style="fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:32.6502;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;paint-order:markers fill stroke"
id="path2"
cx="0"
cy="430.19247"
r="64.870293" />
<path
style="fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:24.4876;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;paint-order:markers fill stroke"
id="path3"
d="m -93.037653,283.56151 -174.608127,-302.430127 349.216236,-10e-6 z"
transform="matrix(0.69829007,0,0,1.0128734,64.967275,29.408685)" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="768"
height="576"
viewBox="0 0 768 576"
version="1.1"
id="svg1"
inkscape:version="1.4.1 (93de688d07, 2025-03-30)"
sodipodi:docname="video_placeholder.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#eee4ec"
bordercolor="#000000"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="false"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="px"
inkscape:zoom="1"
inkscape:cx="375"
inkscape:cy="297"
inkscape:window-width="1920"
inkscape:window-height="1164"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="layer1" />
<defs
id="defs1" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<g
id="path1"
inkscape:transform-center-x="-73.186406"
style="opacity:1;fill:#ff0000;fill-opacity:0.77159059"
transform="translate(107.81361,192)">
<path
style="baseline-shift:baseline;display:inline;overflow:visible;vector-effect:none;fill:#f5b34f;fill-opacity:1;stroke-linecap:round;stroke-linejoin:round;paint-order:markers fill stroke;enable-background:accumulate;stop-color:#000000;stop-opacity:1"
d="m 54.501953,-169.58203 c -5.851459,1.03154 -10.117969,6.11495 -10.119141,12.05664 v 507.05078 c 8.82e-4,9.42554 10.204294,15.31604 18.367188,10.60352 L 501.86719,106.60352 c 8.16111,-4.71353 8.16111,-16.493503 0,-21.207036 L 62.75,-168.12891 c -2.493096,-1.43876 -5.413362,-1.95325 -8.248047,-1.45312 z"
id="path3"
inkscape:label="path3"
sodipodi:nodetypes="cccccccc" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -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'<img src="{}" {} />', 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'<img src="{}" {} />', 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'<video src="{}" preload="metadata" controls {} />', self.soubor.url, attrs)
return html
return
def zmenseny_nahled(self, **kwargs):
return r'FIXME: Takhle se jednou zobrazí videjko…'
attrs = _fmt_attrs(kwargs)
return format_html(r'<img src="{}" {} />', self.placeholder, attrs)
class DummyBazmek(ZobrazitelnyBazmek):
# FIXME: hezčí blokovější elementy!
def __init__(self, *a, **kwa):
super().__init__(*a, **kwa)
self.placeholder = find('galerie/neznamy_placeholder.svg')
def zobrazit(self, **kwargs):
return r'Tohle zobrazit neumím :-('
attrs = _fmt_attrs(kwargs)
# Stavíme HTML ad-hoc, co se může rozbít :'-)
obrazek = format_html(r'<img src="{}"/>', self.placeholder, attrs)
popisek = format_html(r'<p style="text-align: center; font-size: 1.1em;">Prosím oprav typ aktuálního obrázku v <a href="{}">adminu</a>!</p>', reverse('admin:galerie_obrazek_change', args=(self.db_objekt.id,)))
return format_html(r'<div {}>{}{}</div>', attrs, obrazek, popisek)
def zmenseny_nahled(self, **kwargs):
return r'Tohle zobrazit neumím :-('
attrs = _fmt_attrs(kwargs)
return format_html(r'<img src="{}" {} />', self.placeholder, attrs)
def tipniTyp(soubor) -> DbObrazek.Typ:
from PIL import Image, UnidentifiedImageError