Attachment 'gallery2image_test.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     RESTRICTIONS:
  17         spaces in file names are not supported. I don't know how to escape them right.	
  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-17 1.3.5-6 RB FIRST and LAST removed (thats only for testing at the moment)
  36         
  37                               
  38         next ist clean up                       
  39                        
  40 
  41 """
  42 Dependencies = []
  43 import os,string,Image,StringIO
  44 from MoinMoin import config, wikiutil
  45 from MoinMoin.PageEditor import PageEditor
  46 from MoinMoin import user, util
  47 from MoinMoin.Page import Page
  48 from MoinMoin.action import AttachFile
  49 from MoinMoin.formatter.text_html import Formatter
  50 from MoinMoin.parser import wiki
  51 
  52 def to_wikiname(request,text):
  53 
  54     #taken from test_parser_wiki
  55     page = Page(request, 'ThisPageDoesNotExistsAndWillNeverBeReally')
  56     page.formatter = Formatter(request)
  57     request.formatter = page.formatter
  58     page.formatter.setPage(page)
  59     page.hilite_re = None
  60     
  61     out=StringIO.StringIO()
  62     request.redirect(out)
  63     wikiizer = wiki.Parser(text.strip(),request)
  64     wikiizer.format(page.formatter)
  65     naw=out.getvalue()
  66     request.redirect()
  67     del out
  68     
  69     return naw.strip()
  70 
  71 
  72 action_name = __name__.split('.')[-1]
  73 
  74 def execute(pagename, request):
  75     """ Main dispatcher for the 'Gallery' action.
  76     """
  77     _ = request.getText
  78     
  79     request.formatter = Formatter(request)
  80     if request.form['do'][0] == 'VS':
  81         web = {}
  82         images = string.split(request.form['target'][0],',')
  83         target = images[0]
  84         images = (images[1:])
  85         
  86         full_image = string.split(request.form['full'][0],',')
  87         full_target = full_image[0]
  88         full_image = (full_image[1:])
  89         
  90         all_description = string.split(request.form['alias'][0],'!,!')
  91         this_description = all_description[0]
  92         all_description = (all_description[1:])
  93         
  94         all_exif_date = string.split(request.form['exif_date'][0],',')
  95         this_exif_date = all_exif_date[0]
  96         all_exif_date = (all_exif_date[1:])
  97         
  98         z = 0
  99         for img in images :
 100             if (target == img):
 101                previous = z - 1
 102                next = z + 1
 103       
 104             z += 1
 105         n = len(images)
 106        
 107         ######## url_wiki_page #############################################################
 108         text = pagename
 109         url = pagename
 110         url_wiki_page = wikiutil.link_tag(request, url, text = text,
 111                                           formatter = request.formatter)   
 112         ############################################################################			 
 113 
 114         attachment_path = AttachFile.getAttachDir(request,pagename)
 115 
 116         web['src'] = AttachFile.getAttachUrl(pagename,target,request)
 117         web['title'] = target
 118         image_link = request.formatter.image(**web)
 119        
 120         request.http_headers()
 121         request.write('<html>')
 122         request.write('<head>')
 123         request.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">')
 124         request.write('<meta name="robots" content="noindex,nofollow">')
 125         request.write("<H2>%s</H2>" % url_wiki_page)
 126         request.write('<TABLE BORDER="1" ALIGN="CENTER"><TR><TD>')
 127      
 128         if n > 1:
 129             request.write('<TABLE ALIGN="CENTER"><TR>')
 130             url = '<form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">' % {
 131                   'baseurl': request.getScriptname(),
 132                   'pagename': wikiutil.quoteWikinameURL(pagename)}
 133 
 134             url = url + '<input type="hidden" name="action" value="gallery2image">'
 135             url = url + '<input type="hidden" name="do" value="VS">'
 136             url = url + '<input type="hidden" name="full" value="'+full_image[previous]+","+string.join(full_image,',')+'">'
 137             url = url + '<input type="hidden" name="alias" value="'+all_description[previous]+'!,!'+string.join(all_description,'!,!')+'">'
 138             url = url + '<input type="hidden" name="exif_date" value="'+all_exif_date[previous]+','+string.join(all_exif_date,',')+'">'
 139             url = url + '<input type="hidden" name="target" value="'+images[previous]+","+string.join(images,',')+'">'
 140             if (previous >= 0):
 141                 url = url + '<input type="submit" value="PREVIOUS" >'
 142             else:
 143                 url = url + '<input type="submit" value="PREVIOUS" disabled>' 
 144             url = url + '</FORM>'
 145                
 146             request.write("<TD>%s</TD>" % url)
 147      
 148             url = '<form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">' % {
 149                   'baseurl': request.getScriptname(),
 150                   'pagename': wikiutil.quoteWikinameURL(pagename)}
 151             if next < n:
 152                 url = url + '<input type="hidden" name="action" value="gallery2image">'
 153                 url = url + '<input type="hidden" name="do" value="VS">'
 154                 url = url + '<input type="hidden" name="full" value="'+full_image[next]+","+string.join(full_image,',')+'">'
 155                 url = url + '<input type="hidden" name="exif_date" value="'+all_exif_date[next]+','+string.join(all_exif_date,',')+'">'
 156                 url = url + '<input type="hidden" name="alias" value="'+all_description[next]+'!,!'+string.join(all_description,'!,!')+'">'
 157                 url = url + '<input type="hidden" name="target" value="'+images[next]+","+string.join(images,',')+'">'
 158                 url = url + '<input type="submit" value="NEXT" >'
 159             else:
 160                 url = url + '<input type="submit" value="NEXT" disabled >'
 161             url = url + '</FORM>'
 162                 
 163             request.write("<TD>%s</TD>" % url)
 164                               
 165 
 166             request.write("</TR></TABLE>")
 167         
 168         url = '<form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data"><TT>' % {
 169               'baseurl': request.getScriptname(),
 170               'pagename': wikiutil.quoteWikinameURL(pagename)}
 171 
 172         url = url + '<input type="hidden" name="action" value="gallery2image">'
 173         url = url + '<input type="hidden" name="do" value="VS">'
 174         url = url + '<input type="hidden" name="full" value="'+target+","+string.join(images,',')+'">'
 175         url = url + '<input type="hidden" name="alias" value="'+this_description+'!,!'+string.join(all_description,'!,!')+'">'
 176         url = url + '<input type="hidden" name="exif_date" value="'+this_exif_date+','+string.join(all_exif_date,',')+'">'
 177         url = url + '<input type="hidden" name="target" value="'+full_target+","+string.join(full_image,',')+'">'
 178         url = url + '<input type="image" value="submit" src="'+AttachFile.getAttachUrl(pagename,target,request)+'">'
 179         url = url + '</FORM>'             
 180         
 181         
 182         request.write(url)
 183         
 184         request.write("</TD></TR>")
 185         request.write("<TR><TD>")
 186         
 187         request.write(to_wikiname(request,this_description))
 188       
 189         request.write("</TD></TR>")
 190         request.write("<TR><TD>")
 191         
 192         request.write(this_exif_date)
 193       
 194         request.write("</TD></TR>")
 195         request.write("<TR><TD>")
 196         request.write("back to %(url_wiki_page)s" % {
 197                       "url_wiki_page":url_wiki_page})  
 198       
 199         request.write("</TD></TR></TABLE>")	    
 200         request.write("</HTML>")
 201         
 202         return
 203         
 204     elif request.form['do'][0] == 'PS':
 205             images=string.split(request.form['target'][0],',')
 206             attachment_path = AttachFile.getAttachDir(request,pagename)
 207             target=request.form['target'][0]
 208 
 209             msg= _('not finished by now') #+ target
 210 
 211     elif request.user.may.delete(pagename):
 212        # only users which are allowed to delete should use this tool
 213 
 214         target=request.form['target'][0]
 215         file, ext = os.path.splitext(target)
 216 
 217         if ext == '.gif' or ext == '.png':
 218             img_type='PNG'
 219             thumbfile='thumbnail_'+file+".png"
 220             webnail='webnail_'+file+".png"
 221         else:
 222             img_type="JPEG"
 223             thumbfile='thumbnail_'+file+".jpg"
 224             webnail='webnail_'+file+".jpg"
 225 
 226 
 227         attachment_path = AttachFile.getAttachDir(request,pagename)
 228         thumb=os.path.join(attachment_path,thumbfile)
 229         webf=os.path.join(attachment_path,webnail)
 230         infile=os.path.join(attachment_path,target)
 231 
 232         msg = None
 233         if action_name in request.cfg.excluded_actions:
 234             msg = _('File attachments are not allowed in this wiki!')
 235 
 236         elif request.form['do'][0] == 'RM':
 237             if os.path.exists(infile+'.bak'):
 238                os.unlink(infile+'.bak')
 239             os.link(infile,infile+'.bak')
 240             os.unlink(infile)
 241             os.unlink(webf)
 242             os.unlink(thumb)
 243 
 244             msg= _('%(target)s deleted, backup in place' % {
 245                   'target':target})
 246 
 247         elif request.form['do'][0] == 'RL':
 248             im = Image.open(infile)
 249             #os.unlink(infile)
 250             im.rotate(90).save(infile,img_type)
 251             nim = Image.open(infile)
 252             nim.thumbnail((640,640), Image.ANTIALIAS)
 253             #os.unlink(webf)
 254             nim.save(webf, img_type)
 255             nim.thumbnail((128, 128), Image.ANTIALIAS)
 256             #os.unlink(thumb)
 257             nim.save(thumb, img_type)
 258             msg= _('%(target)s rotated to left 90 degrees' % {
 259                   'target':target})
 260 
 261         elif request.form['do'][0] == 'RR':
 262             im = Image.open(infile)
 263             #os.unlink(infile)
 264             im.rotate(270).save(infile,img_type)
 265 
 266 
 267             nim = Image.open(infile)
 268 
 269             nim.thumbnail((640,640), Image.ANTIALIAS)
 270             #os.unlink(webf)
 271             nim.save(webf, img_type)
 272             nim.thumbnail((128, 128), Image.ANTIALIAS)
 273             #os.unlink(thumb)
 274             nim.save(thumb, img_type)
 275             msg= _('%(target)s rotated to right 90 degrees' % {
 276                   'target':target})
 277 
 278         else:
 279             msg = _('action not implemented: %s') % (request.form['do'][0],)
 280     else:
 281         msg = _('Your are not allowed to change images on this page: %s') % (pagename,)
 282 
 283     if msg:
 284         AttachFile.error_msg(pagename, request, msg)
 285 
 286     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.
  • [get | view] (2006-08-06 08:57:54, 41.8 KB) [[attachment:EXIF.py]]
  • [get | view] (2005-03-24 20:14:37, 10.6 KB) [[attachment:Gallery2-1.3.3-1.py]]
  • [get | view] (2005-03-26 08:39:13, 11.6 KB) [[attachment:Gallery2-1.3.3-2.py]]
  • [get | view] (2005-03-26 12:41:49, 13.1 KB) [[attachment:Gallery2-1.3.3-3.py]]
  • [get | view] (2005-03-27 20:23:01, 19.0 KB) [[attachment:Gallery2-1.3.3-4.py]]
  • [get | view] (2005-08-03 19:30:10, 23.2 KB) [[attachment:Gallery2-1.3.3-5.py]]
  • [get | view] (2005-08-18 07:58:38, 31.9 KB) [[attachment:Gallery2-1.3.5-10.py]]
  • [get | view] (2005-09-02 19:55:13, 34.1 KB) [[attachment:Gallery2-1.3.5-11.py]]
  • [get | view] (2005-11-13 18:09:11, 35.4 KB) [[attachment:Gallery2-1.3.5-12.py]]
  • [get | view] (2005-11-18 20:13:04, 46.2 KB) [[attachment:Gallery2-1.3.5-13.py]]
  • [get | view] (2005-12-03 15:33:06, 46.6 KB) [[attachment:Gallery2-1.3.5-14.py]]
  • [get | view] (2006-01-01 09:20:19, 43.3 KB) [[attachment:Gallery2-1.3.5-15.py]]
  • [get | view] (2005-08-07 15:46:28, 26.9 KB) [[attachment:Gallery2-1.3.5-6.py]]
  • [get | view] (2005-08-13 15:13:59, 28.7 KB) [[attachment:Gallery2-1.3.5-7.py]]
  • [get | view] (2005-08-14 13:02:00, 27.5 KB) [[attachment:Gallery2-1.3.5-8.py]]
  • [get | view] (2005-08-14 14:38:32, 28.7 KB) [[attachment:Gallery2-1.3.5-9.py]]
  • [get | view] (2006-08-06 08:45:47, 41.8 KB) [[attachment:Gallery2-1.5.4-16.py]]
  • [get | view] (2006-08-22 20:29:39, 42.0 KB) [[attachment:Gallery2-1.5.4-18.py]]
  • [get | view] (2006-08-06 08:57:36, 514.8 KB) [[attachment:example.swf]]
  • [get | view] (2005-08-17 18:10:27, 11.3 KB) [[attachment:gallery2image_test.py]]
  • [get | view] (2005-08-10 16:49:16, 1.3 KB) [[attachment:patchpullfromdir.diff]]
  • [get | view] (2006-08-17 16:32:50, 41.9 KB) [[attachment:text_x_gallery2-1.6.0-17.py]]
  • [get | view] (2006-08-22 20:23:06, 42.1 KB) [[attachment:text_x_gallery2-1.6.0-18.py]]
  • [get | view] (2008-02-06 10:08:05, 42.2 KB) [[attachment:text_x_gallery2-1.6.0-19.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.