Attachment 'gallery2image-1.3.3-1.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - gallery2Image Actionmacro
4
5 PURPOSE:
6 This action macro is used to rotate 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 MODIFICATION HISTORY:
17 Version 1.3.3.-1
18 @copyright: 2005 by Reimar Bauer (R.Bauer@fz-juelich.de)
19 @license: GNU GPL, see COPYING for details.
20
21 """
22
23 import os,string,Image
24 from MoinMoin import config, wikiutil
25 from MoinMoin.PageEditor import PageEditor
26 from MoinMoin import user, util
27 from MoinMoin.Page import Page
28 from MoinMoin.action import AttachFile
29
30
31 action_name = __name__.split('.')[-1]
32
33 def execute(pagename, request):
34 """ Main dispatcher for the 'Gallery' action.
35 """
36 _ = request.getText
37
38 if(request.form['do'][0] == 'PS'):
39 images=string.split(request.form['target'][0],',')
40 attachment_path = AttachFile.getAttachDir(request,pagename)
41 # for img in images:
42 # infile=attachment_path+'/'+img
43 # im = Image.open(infile)
44 # src=im.tostring()
45
46 msg= _('not finished by now')
47
48 elif request.user.may.delete(pagename):
49 # only users which are allowed to delete should use this tool
50
51 target=request.form['target'][0]
52 file, ext = os.path.splitext(target)
53
54 if (ext == '.gif') or (ext == '.png'):
55 img_type='PNG'
56 thumbfile='thumbnail_'+file+".png"
57 webnail='webnail_'+file+".png"
58 else:
59 img_type="JPEG"
60 thumbfile='thumbnail_'+file+".jpg"
61 webnail='webnail_'+file+".jpg"
62
63
64 attachment_path = AttachFile.getAttachDir(request,pagename)
65 thumb=attachment_path+'/'+thumbfile
66 webf=attachment_path+'/'+webnail
67 infile=attachment_path+'/'+target
68 msg = None
69 if action_name in request.cfg.excluded_actions:
70 msg = _('File attachments are not allowed in this wiki!')
71
72 elif (request.form['do'][0] == 'RM'):
73 os.link(infile,infile+'.bak')
74 os.unlink(infile)
75 os.unlink(webf)
76 os.unlink(thumb)
77
78 msg= _('%(target)s deleted, backup in place' % {
79 'target':target})
80
81 elif (request.form['do'][0] == 'RL'):
82 im = Image.open(infile)
83 os.unlink(infile)
84 im.rotate(90).save(infile,img_type)
85 nim = Image.open(infile)
86 nim.thumbnail((640,640), Image.ANTIALIAS)
87 os.unlink(webf)
88 nim.save(webf, img_type)
89 nim.thumbnail((128, 128), Image.ANTIALIAS)
90 os.unlink(thumb)
91 nim.save(thumb, img_type)
92 msg= _('%(target)s rotated to left 90 degrees' % {
93 'target':target})
94
95 elif (request.form['do'][0] == 'RR'):
96 im = Image.open(infile)
97 os.unlink(infile)
98 im.rotate(270).save(infile,img_type)
99
100
101 nim = Image.open(infile)
102
103 nim.thumbnail((640,640), Image.ANTIALIAS)
104 os.unlink(webf)
105 nim.save(webf, img_type)
106 nim.thumbnail((128, 128), Image.ANTIALIAS)
107 os.unlink(thumb)
108 nim.save(thumb, img_type)
109 msg= _('%(target)s rotated to right 90 degrees' % {
110 'target':target})
111
112 else:
113 msg = _('action not implemented: %s') % (request.form['do'][0],)
114 else:
115 msg = _('Your are not allowed to change images on this page: %s') % (pagename,)
116
117 if msg:
118 AttachFile.error_msg(pagename, request, msg)
119
120 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.