comparison data/plugin/macro/Image.py @ 299:1c25a98e3d9d

reverted changeset 269:1e3e876e38fb for Image and partly for text_x_arnica
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Wed, 26 Nov 2008 23:07:44 +0100
parents 03071c3569d8
children 91e4b1f42614
comparison
equal deleted inserted replaced
298:b08869e17e8b 299:1c25a98e3d9d
46 46
47 def __init__(self, request, 47 def __init__(self, request,
48 item_name, # PageName/AttachName for now, later this is just the item name 48 item_name, # PageName/AttachName for now, later this is just the item name
49 headline=None, 49 headline=None,
50 caption=None, 50 caption=None,
51 raw=None,
52 ): 51 ):
53 self.request = request 52 self.request = request
54 self.pagename, self.attachname = item_name.rsplit('/', 1) 53 self.pagename, self.attachname = item_name.rsplit('/', 1)
55 self.raw = raw
56 54
57 # cached property values: 55 # cached property values:
58 self.__filename = None 56 self.__filename = None
59 self.__content_type = None 57 self.__content_type = None
60 self.__cache_key = None 58 self.__cache_key = None
61 self.__image = None 59 self.__image = None
62 self.__exif = None 60 self.__exif = None
63 self.__ctime = None 61 self.__ctime = None
64 self.__headline = headline 62 self.__headline = headline
65 self.__caption = caption 63 self.__caption = caption
66 self.__description = self.attachname
67
68 def _get_description(self):
69 if self.raw is None:
70 self.__description = self.attachname
71 return self.__description
72 else:
73 quotes = self.raw.split('\n')
74 quotes = [quote.strip() for quote in quotes]
75 quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
76 image_alias = self.attachname
77 for line in quotes:
78 if line.startswith('[[') and line.endswith(']]'):
79 img, alias = line[2:-2].split('|', 1)
80 if img.strip() == self.attachname:
81 self.__description = alias.strip()
82 break
83 return self.__description
84 description = property(_get_description)
85 64
86 def _get_filename(self): 65 def _get_filename(self):
87 if self.__filename is None: 66 if self.__filename is None:
88 self.__filename = AttachFile.getFilename(self.request, self.pagename, self.attachname) 67 self.__filename = AttachFile.getFilename(self.request, self.pagename, self.attachname)
89 return self.__filename 68 return self.__filename
263 the original image. Thus, by not giving width or height, you'll get the original image, 242 the original image. Thus, by not giving width or height, you'll get the original image,
264 and if you specify width or height you will get an image of that width or that height. 243 and if you specify width or height you will get an image of that width or that height.
265 244
266 <<Image(PageName/attachname,width=100,alt="sample image")>> 245 <<Image(PageName/attachname,width=100,alt="sample image")>>
267 """ 246 """
268 arnica_parser = wikiutil.importWikiPlugin(macro.request.cfg, "parser", "text_x_arnica", function="Parser")
269 if '/' not in itemname: 247 if '/' not in itemname:
270 itemname = macro.formatter.page.page_name + '/' + itemname 248 itemname = macro.formatter.page.page_name + '/' + itemname
271 raw = " * [[%s | %s]]\n" % (itemname.split('/')[1], (alt or (itemname.split('/')[1]))) 249 img = Image(macro.request, itemname, caption=alt)
272 img = Image(macro.request, itemname, caption=alt, raw=raw) 250 return macro.formatter.image(src=img.url((width, height)), alt=img.caption)
273 try: 251
274 exif_date = time.strftime("%Y-%m-%d %H:%M:%S", macro.request.user.getTime(img.exif["DateTimeOriginal"]))
275 except KeyError:
276 exif_date = '--'
277 # ToDo use alt attribute in arnica for one image instead of Slide Show title
278 ap = arnica_parser(raw, macro.request, image=img)
279 ap.arnica_image[img.attachname] = (img.url(), img.url(size=(width, height)), exif_date, img.description, "0")
280 return ap.render(macro.formatter)