diff data/plugin/macro/Image.py @ 267:de2f265a9ac5

Image: add headline/caption support, read from iptc data if not given
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 14 Sep 2008 00:46:38 +0200
parents 3e4eaae2f7df
children 1e3e876e38fb
line wrap: on
line diff
--- a/data/plugin/macro/Image.py	Sun Sep 14 00:15:21 2008 +0200
+++ b/data/plugin/macro/Image.py	Sun Sep 14 00:46:38 2008 +0200
@@ -1,6 +1,6 @@
 # -*- coding: iso-8859-1 -*-
 """
-    MoinMoin - MoinImage image rendering support class and a test macro using it.
+    MoinMoin - Image rendering support class and a simple macro using it.
 
     Features:
     * rendering (and caching) of thumbnails/webnails/originals
@@ -46,11 +46,11 @@
 
     def __init__(self, request,
                  item_name, # PageName/AttachName for now, later this is just the item name
-                 description=u'', # we just store this, but we do not use it in Image
+                 headline=None,
+                 caption=None,
         ):
         self.request = request
         self.pagename, self.attachname = item_name.rsplit('/', 1)
-        self.description = description
 
         # cached property values:
         self.__filename = None
@@ -59,6 +59,8 @@
         self.__image = None
         self.__exif = None
         self.__ctime = None
+        self.__headline = headline
+        self.__caption = caption
 
     def _get_filename(self):
         if self.__filename is None:
@@ -139,6 +141,18 @@
     exif = property(lambda self: self._get_exif_data()[0]) # dict of preprocessed EXIF data (string -> value)
     iptc = property(lambda self: self._get_exif_data()[1]) # dict of preprocessed IPTC data (string -> value)
 
+    def _get_headline(self):
+        if self.__headline is None:
+            self.__headline = self.iptc.get('headline', u'')
+        return self.__headline
+    headline = property(_get_headline)
+
+    def _get_caption(self):
+        if self.__caption is None:
+            self.__caption = self.iptc.get('caption', u'')
+        return self.__caption
+    caption = property(_get_caption)
+
     def _get_ctime(self):
         """ return creation time of image (either from EXIF or file date) as UNIX timestamp """
         if self.__ctime is None:
@@ -232,6 +246,6 @@
     """
     if '/' not in itemname:
         itemname = macro.formatter.page.page_name + '/' + itemname
-    img = Image(macro.request, itemname, alt)
-    return macro.formatter.image(src=img.url((width, height)), alt=img.description)
+    img = Image(macro.request, itemname, caption=alt)
+    return macro.formatter.image(src=img.url((width, height)), alt=img.caption)