Attachment 'gallery2image-1.3.5-6.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - gallery2Image Actionmacro
4
5 PURPOSE::
6 This action macro is used to rotate, move to bak or to slide through the images from Gallery2
7
8 CALLING SEQUENCE::
9 called by Gallery2 POST Method
10
11 PROCEDURE::
12 see Gallery2
13
14 Please remove the version number from this file
15
16 RESTRICTIONS::
17 spaces in file names are not supported. I don't know how to escape them right. Probaly this does work in 1.3.5
18
19 MODIFICATION HISTORY::
20 Version 1.3.3.-1
21 @copyright: 2005 by Reimar Bauer (R.Bauer@fz-juelich.de)
22 @license: GNU GPL, see COPYING for details.
23 2005-06-24: 1.3.3.-2 feature reqeust of CraigJohnson added
24 os.path.join used to join platform independent pathes
25 os.unlink removed to get it more platform independend
26 2005-08-06: 1.3.5-3 RB VS mode added
27 by one step back or forward could be toggled through the selected slides
28 and the first and last one could be selected too
29 2005-08-07 1.3.5-4 RB bug fixed for cgi-bin call. formatting of tables adjusted
30 2005-08-13 1.3.5-5 RB code change from GET to POST
31 forms instead of link
32 toggle between webnail and image by click on image
33 alias (description) and exif_date added
34 this version needs Gallery2-1.3.5-7.py
35 2005-08-31 1.3.5-6 RB html code changed into a function :-)
36 some html bugs fixed too
37 instead of button text now images used (disabled buttons are grey color coded)
38 back link to callers page
39 whole page inserted into the common wiki page
40 code clean up.
41
42
43
44
45 """
46 Dependencies = []
47 import os,string,Image,StringIO
48 from MoinMoin import config, wikiutil
49 from MoinMoin.PageEditor import PageEditor
50 from MoinMoin import user, util
51 from MoinMoin.Page import Page
52 from MoinMoin.action import AttachFile
53 from MoinMoin.formatter.text_html import Formatter
54 from MoinMoin.parser import wiki
55
56 def html_show_image(request,pagename,url_wiki_page,full,alias,exif_date,target,idx):
57
58 n = len(target)
59 last_disabled = ''
60 last_status = ''
61 first_disabled = ''
62 first_status = ''
63 previous = idx - 1
64 next = idx + 1
65
66 if idx == n-1 :
67 last_disabled = 'disabled'
68 last_status = '_disabled'
69
70 if idx == 0 :
71 first_disabled = 'disabled'
72 first_status = '_disabled'
73
74
75 if previous < 0 :
76 previous = 0
77
78 if next > n - 1 :
79 next = n - 1
80
81 if n == 1 :
82 next = 0
83 # previous = 0
84 # first_disabled = 'disabled'
85 # first_status = '_disabled'
86 # last_disabled = 'disabled'
87 # last_status = '_disabled'
88
89 html = '''
90 <table border="1" align="center"">
91 <tr align="center" >
92 <td>
93 <table border="0";style="border-style:none;">
94 <tr align="center">
95
96 <form action="%(base_url)s/%(pagename)s" method="POST" enctype="multipart/form-data">
97 <th>
98 <input type="hidden" name="action" value="gallery2image">
99 <input type="hidden" name="do" value="VS">
100 <input type="hidden" name="full" value="%(first_full_list)s">
101 <input type="hidden" name="alias" value="%(first_alias_list)s">
102 <input type="hidden" name="exif_date" value="%(first_exif_date_list)s">
103 <input type="hidden" name="target" value="%(first_target_list)s">
104 <input type="image" value="submit" src="/wiki/modern/img/first%(first_status)s.png" title="first slide" %(first_disabled)s>
105 </th>
106 </form>
107 <form action="%(base_url)s/%(pagename)s" method="POST" enctype="multipart/form-data">
108 <th>
109 <input type="hidden" name="action" value="gallery2image">
110 <input type="hidden" name="do" value="VS">
111 <input type="hidden" name="full" value="%(previous_full_list)s">
112 <input type="hidden" name="alias" value="%(previous_alias_list)s">
113 <input type="hidden" name="exif_date" value="%(previous_exif_date_list)s">
114 <input type="hidden" name="target" value="%(previous_target_list)s">
115 <input type="image" value="submit" src="/wiki/modern/img/previous%(first_status)s.png" title="previous slide" %(first_disabled)s>
116 </th>
117 </form>
118 <form action="%(base_url)s/%(pagename)s" method="POST" enctype="multipart/form-data">
119 <th>
120 <input type="hidden" name="action" value="gallery2image">
121 <input type="hidden" name="do" value="VS">
122 <input type="hidden" name="full" value="%(next_full_list)s">
123 <input type="hidden" name="exif_date" value="%(next_exif_date_list)s">
124 <input type="hidden" name="alias" value="%(next_alias_list)s">
125 <input type="hidden" name="target" value="%(next_target_list)s">
126 <input type="image" value="submit" src="/wiki/modern/img/next%(last_status)s.png" title="next slide" %(last_disabled)s>
127 </th>
128 </form>
129 <form action="%(base_url)s/%(pagename)s" method="POST" enctype="multipart/form-data">
130 <th>
131 <input type="hidden" name="action" value="gallery2image">
132 <input type="hidden" name="do" value="VS">
133 <input type="hidden" name="full" value="%(last_full_list)s">
134 <input type="hidden" name="alias" value="%(last_alias_list)s">
135 <input type="hidden" name="exif_date" value="%(last_exif_date_list)s">
136 <input type="hidden" name="target" value="%(last_target_list)s">
137 <input type="image" value="submit" src="/wiki/modern/img/last%(last_status)s.png" title="last slide" %(last_disabled)s>
138 </th>
139 </form>
140 <form action="%(base_url)s/%(pagename)s" method="POST" enctype="multipart/form-data">
141 <th>
142 <input type="hidden" name="action" value="gallery2image">
143 <input type="hidden" name="do" value="BS">
144 <input type="hidden" name="full" value="%(this_full_list)s">
145 <input type="hidden" name="alias" value="%(this_alias_list)s">
146 <input type="hidden" name="exif_date" value="%(this_exif_date_list)s">
147 <input type="hidden" name="target" value="%(this_target_list)s">
148 <input type="image" value="submit" src="/wiki/modern/img/back.png" title="return to %(pagename)s">
149 </th>
150 </form>
151 </tr>
152 </table>
153 </td>
154 </tr>
155 <tr align="center">
156 <form action="%(base_url)s/%(pagename)s" method="POST" enctype="multipart/form-data">
157 <th>
158 <input type="hidden" name="action" value="gallery2image">
159 <input type="hidden" name="do" value="VS">
160 <input type="hidden" name="full" value="%(this_target_list)s">
161 <input type="hidden" name="alias" value="%(this_alias_list)s">
162 <input type="hidden" name="exif_date" value="%(this_exif_date_list)s">
163 <input type="hidden" name="target" value="%(this_full_list)s">
164 <input type="image" value="submit" src="%(this_image)s">
165 </th>
166 </form>
167 </tr>
168 <tr>
169 <td>
170 <p>
171 %(this_alias_text)s
172 </p>
173 </td>
174 </tr>
175 <tr>
176 <td>
177 <p>
178 %(this_exif_date_text)s
179 </p>
180 </td>
181 </tr>
182
183 </table>''' % {
184
185 "base_url" : request.getScriptname(),
186 "first_status" : first_status,
187 "last_status" : last_status,
188 "first_full_list" : full[0] + "," + string.join(full,','),
189 "first_alias_list" : alias[0] + '!,!' + string.join(alias,'!,!'),
190 "first_exif_date_list" : exif_date[0] + ',' + string.join(exif_date,','),
191 "first_target_list" : target[0] + "," + string.join(target,','),
192
193 "previous_full_list" : full[previous] + "," + string.join(full,','),
194 "previous_alias_list" : alias[previous] + '!,!' + string.join(alias,'!,!'),
195 "previous_exif_date_list" : exif_date[previous] + ',' + string.join(exif_date,','),
196 "previous_target_list" : target[previous] + "," + string.join(target,','),
197
198 "next_full_list" : full[next] + "," + string.join(full,','),
199 "next_alias_list" : alias[next] + '!,!' + string.join(alias,'!,!'),
200 "next_exif_date_list" : exif_date[next] + ',' + string.join(exif_date,','),
201 "next_target_list" : target[next] + "," + string.join(target,','),
202
203 "last_full_list" : full[n-1] + "," + string.join(full,','),
204 "last_alias_list" : alias[n-1] + '!,!' + string.join(alias,'!,!'),
205 "last_exif_date_list" : exif_date[n-1] + ',' + string.join(exif_date,','),
206 "last_target_list" : target[n-1] + "," + string.join(target,','),
207
208 "this_full_list" : full[idx] + "," + string.join(full,','),
209 "this_alias_list" : alias[idx] + '!,!' + string.join(alias,'!,!'),
210 "this_exif_date_list" : exif_date[idx] + ',' + string.join(exif_date,','),
211 "this_target_list" : target[idx] + "," + string.join(target,','),
212
213 "first_disabled" : first_disabled,
214 "last_disabled" : last_disabled,
215 "this_alias_text" : alias[idx],
216 "this_exif_date_text" : exif_date[idx],
217 "this_image" : AttachFile.getAttachUrl(pagename,target[idx],request),
218 "url_wiki_page" : url_wiki_page,
219 "pagename" : pagename
220 }
221
222
223 return html
224
225 def to_wikiname(request,text):
226
227 #taken from test_parser_wiki
228 page = Page(request, 'ThisPageDoesNotExistsAndWillNeverBeReally')
229 page.formatter = Formatter(request)
230 request.formatter = page.formatter
231 page.formatter.setPage(page)
232 page.hilite_re = None
233
234 out=StringIO.StringIO()
235 request.redirect(out)
236 wikiizer = wiki.Parser(text.strip(),request)
237 wikiizer.format(page.formatter)
238 result = out.getvalue()
239 request.redirect()
240 del out
241
242 return result.strip()
243
244
245 action_name = __name__.split('.')[-1]
246
247 def execute(pagename, request):
248 """ Main dispatcher for the 'Gallery' action.
249 """
250 _ = request.getText
251
252 request.formatter = Formatter(request)
253 attachment_path = AttachFile.getAttachDir(request,pagename)
254 if request.form['do'][0] == 'VS' :
255 web = {}
256 images = string.split(request.form['target'][0],',')
257 target = images[0]
258 images = (images[1:])
259
260 full_image = string.split(request.form['full'][0],',')
261 full_target = full_image[0]
262 full_image = (full_image[1:])
263
264 all_description = string.split(request.form['alias'][0],'!,!')
265 this_description = all_description[0]
266 all_description = (all_description[1:])
267
268 all_exif_date = string.split(request.form['exif_date'][0],',')
269 this_exif_date = all_exif_date[0]
270 all_exif_date = (all_exif_date[1:])
271
272 z = 0
273 for img in images :
274 if target == img :
275 idx = z
276
277 z += 1
278 n = len(images)
279
280 ######## url_wiki_page #############################################################
281 text = pagename
282 url = pagename
283 url_wiki_page = wikiutil.link_tag(request, url, text = text,
284 formatter = request.formatter)
285 ############################################################################
286
287 attachment_path = AttachFile.getAttachDir(request,pagename)
288
289 web['src'] = AttachFile.getAttachUrl(pagename,target,request)
290 web['title'] = target
291 #web['width']="1024"
292
293
294 image_link=request.formatter.image(**web)
295
296
297 request.http_headers()
298 request.setContentLanguage(request.lang)
299 wikiutil.send_title(request, pagename,
300 pagename=pagename)
301 request.write(request.formatter.startContent("content"))
302
303
304 html = html_show_image(request,pagename,url_wiki_page,full_image,all_description,all_exif_date,images,idx)
305 request.write(html)
306 request.write(request.formatter.endContent())
307 wikiutil.send_footer(request, pagename)
308 msg = None
309 #return
310
311 elif request.form['do'][0] == 'PS' :
312 images=string.split(request.form['target'][0],',')
313 attachment_path = AttachFile.getAttachDir(request,pagename)
314 target=request.form['target'][0]
315
316 msg= _('not finished by now') #+ target
317
318 elif request.form['do'][0] == 'BS' :
319
320 msg = "gone back" #None
321
322 elif request.user.may.delete(pagename):
323 # only users which are allowed to delete should use this tool
324
325 target=request.form['target'][0]
326 file, ext = os.path.splitext(target)
327
328 if ext == '.gif' or ext == '.png' :
329 img_type = 'PNG'
330 thumbfile = "thumbnail_%(file)s.png" % {"file" : file}
331 webnail = "webnail_%(file)s.png" % {"file" : file}
332 else:
333 img_type="JPEG"
334 thumbfile="thumbnail_%(file)s.jpg" % {"file" : file}
335 webnail="webnail_%(file)s.jpg" % {"file" : file}
336
337 thumb = os.path.join(attachment_path,thumbfile)
338 webf = os.path.join(attachment_path,webnail)
339 infile = os.path.join(attachment_path,target)
340
341 msg = None
342 if action_name in request.cfg.excluded_actions:
343 msg = _('File attachments are not allowed in this wiki!')
344
345 elif request.form['do'][0] == 'RM' :
346 if os.path.exists(infile + '.bak') :
347 os.unlink("%(file)s.bak" % {"file" : infile})
348 os.link(infile,"%(file)s.bak" % {"file" : infile})
349 os.unlink(infile)
350 os.unlink(webf)
351 os.unlink(thumb)
352
353 msg = _('%(target)s deleted, backup in place' % {
354 'target':target})
355
356 elif request.form['do'][0] == 'RL' :
357 im = Image.open(infile)
358 #os.unlink(infile)
359 im.rotate(90).save(infile,img_type)
360 nim = Image.open(infile)
361 nim.thumbnail((640,640), Image.ANTIALIAS)
362 #os.unlink(webf)
363 nim.save(webf, img_type)
364 nim.thumbnail((128, 128), Image.ANTIALIAS)
365 #os.unlink(thumb)
366 nim.save(thumb, img_type)
367 msg= _('%(target)s rotated to left 90 degrees' % {
368 'target':target})
369
370 elif request.form['do'][0] == 'RR' :
371 im = Image.open(infile)
372 #os.unlink(infile)
373 im.rotate(270).save(infile,img_type)
374
375
376 nim = Image.open(infile)
377
378 nim.thumbnail((640,640), Image.ANTIALIAS)
379 #os.unlink(webf)
380 nim.save(webf, img_type)
381 nim.thumbnail((128, 128), Image.ANTIALIAS)
382 #os.unlink(thumb)
383 nim.save(thumb, img_type)
384 msg= _('%(target)s rotated to right 90 degrees' % {
385 'target':target})
386
387
388
389
390 else:
391 msg = _('action not implemented: %s') % (request.form['do'][0],)
392 else:
393 msg = _('Your are not allowed to change images on this page: %s') % (pagename,)
394
395 if msg:
396 AttachFile.error_msg(pagename, request, msg)
397
398 return()
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.