Commit e077b0d4 authored by Thomas Lecavelier's avatar Thomas Lecavelier Committed by Laurent Bachelier

Introduce Media class in Gallery plugin. Media encapsulates a standard file,...

Introduce Media class in Gallery plugin. Media encapsulates a standard file, it permits to have a generic template but a specific behavior for differents kind of Media. ie: an SVG image is an image, but since it's vectorial there's fucking no reason to try to thumbnail it.
parent a6b17ed5
......@@ -22,6 +22,7 @@ import os
from PIL import Image
from paste.httpheaders import CACHE_CONTROL, CONTENT_DISPOSITION
from mako.filters import html_escape
from paste.url import URL
from ass2m.plugin import Plugin
from ass2m.routes import View
......@@ -76,6 +77,33 @@ class DownloadThumbnailAction(ViewAction):
CONTENT_DISPOSITION.apply(self.ctx.res.headers, inline=True,
filename="%s_thumb_%s.%s" % (os.path.splitext(f.get_name())[0], size, thumbext))
class Media:
__file = None
def __init__(self, f):
self.__file = f
def get_name(self):
return self.__file.get_name()
def get_pretty_name(self):
return self.__file.get_pretty_name()
def get_mimetype(self):
return self.__file.get_mimetype()
def get_url(self):
return URL(self.get_name())
def get_thumb_url(self):
if self.get_mimetype() == 'image/svg+xml':
return self.get_url()
return self.get_url().setvars(view='thumbnail', thumb_size=200)
def get_extra_classes(self):
if self.get_mimetype() == 'image/svg+xml':
return ' svg'
return ''
class MediaListAction(ViewAction):
......@@ -94,7 +122,7 @@ class MediaListAction(ViewAction):
filename = f.get_name()
mimetype = f.get_mimetype()
if self.IS_MEDIA and mimetype is not None and mimetype.startswith('image'):
if filename in ('README', 'README.html', 'HEADER', 'HEADER.html'):
with open(f.get_realpath(), 'r') as fp:
......@@ -111,7 +139,6 @@ class MediaListAction(ViewAction):
self.ctx.res.body = self.ctx.render('list.html')
class GalleryPlugin(Plugin):
def init(self):
......@@ -207,6 +207,11 @@ img {
border: 0;
img.svg {
width: 200px;
height: 200px;
p.message {
margin-left: auto;
margin-right: auto;
......@@ -11,9 +11,9 @@
<ul class="gallery">
% for thumb in thumbs:
<li class="hmedia">
<a rel="enclosure original" type="${thumb.get_mimetype() | h}" href="${URL(thumb.get_name()) | n,U,h}" title="${thumb.get_name() | h}">
<a rel="enclosure original" type="${thumb.get_mimetype() | h}" href="${thumb.get_url() | n,U,h}" title="${thumb.get_name() | h}">
<span class="frame"><img class="thumbnail photo" src="${URL(thumb.get_name()).setvars(view='thumbnail', thumb_size=200) | n,U,h}" /></span>
<span class="frame"><img class="thumbnail photo${thumb.get_extra_classes()}" src="${thumb.get_thumb_url() | n,U,h}" /></span>
<span class="fn">${thumb.get_pretty_name() | h}</span>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment