summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2012-09-24 20:47:06 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2012-09-24 20:47:06 +0200
commit7aa6f36e6df3fed026e7a802c79bd945bce9a8c4 (patch)
tree43aaee7790ebb2d4a6d12d55362821448d754f7d
parent9c915bab172a4d5a2d9aed056c9261cd7b0cbd60 (diff)
Show a placeholder image when no thumbnail could be fetched or generated.
-rw-r--r--db.py2
-rwxr-xr-xfbin.py2
-rw-r--r--static/no-thumbnail.pngbin0 -> 1546 bytes
-rw-r--r--templates/images.tmpl9
4 files changed, 11 insertions, 2 deletions
diff --git a/db.py b/db.py
index eaf5f13..8cadb6b 100644
--- a/db.py
+++ b/db.py
@@ -67,7 +67,7 @@ class File(Base):
return self.get_mime_type().startswith('image')
def image_html(self):
- return u'<a href="{root}f/{hash}{ext}" title="{filename}"><img src="{root}t/{hash}" alt="{filename}" /></a>'.format(
+ return u'<a href="{root}f/{hash}{ext}" title="{filename}"><img src="{root}t/{hash}" alt="{filename}" onerror="thumb_onerror(this)" /></a>'.format(
root = settings.virtual_root, hash = self.hash, filename = self.filename, ext = os.path.splitext(self.filename)[1])
Base.metadata.create_all()
diff --git a/fbin.py b/fbin.py
index 726a87c..2bda843 100755
--- a/fbin.py
+++ b/fbin.py
@@ -429,7 +429,7 @@ class Application(object):
def static(self, environ, start_response, path):
filename = path[1]
- if not filename in ('style.css',):
+ if not filename in ('style.css', 'no-thumbnail.png'):
start_response('404 Not Found', [])
return []
diff --git a/static/no-thumbnail.png b/static/no-thumbnail.png
new file mode 100644
index 0000000..4af3517
--- /dev/null
+++ b/static/no-thumbnail.png
Binary files differ
diff --git a/templates/images.tmpl b/templates/images.tmpl
index 4cd3752..1dcfc46 100644
--- a/templates/images.tmpl
+++ b/templates/images.tmpl
@@ -1,6 +1,15 @@
#def title: images
#def header: images
#extends templates.base
+#def head
+<script type="text/javascript">
+ function thumb_onerror(img) {
+ var no_thumb = '${root}s/no-thumbnail.png';
+ if(img.src != no_thumb)
+ img.src = no_thumb;
+ }
+</script>
+#end def
#def content
<p>You have $len($files) uploaded images totaling $total_size.</p>
<ul class="image-list">