changeset 362:ff2e57ddeb68

arnica_slides: compatibility for 1.9 changes added
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 21 Feb 2009 23:47:30 +0100
parents 2098e0920de5
children 2bf44dde5191
files data/plugin/action/arnica_slides.py
diffstat 1 files changed, 44 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/arnica_slides.py	Wed Feb 18 00:33:04 2009 +0100
+++ b/data/plugin/action/arnica_slides.py	Sat Feb 21 23:47:30 2009 +0100
@@ -9,7 +9,7 @@
     @copyright: 2008 by MoinMoin:ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
-import os
+import os, re
 
 from MoinMoin import log
 logging = log.getLogger(__name__)
@@ -27,7 +27,19 @@
 
 action_name = __name__.split('.')[-1]
 
-
+def ensureversion(request, version):
+    """ Ensures that the version of MoinMoin is greater or equal than
+    version. 
+     
+    @param version: required version of MoinMoin (e.g. "1.3.4")
+    """
+    from MoinMoin.version import release
+    version_int = [int(x) for x in version.split(".")]
+    # use a regex here to get only the numbers of the release string (e.g. ignore betaX)
+    release = re.compile('\d+').findall(release)[0:3]
+    release = [int(x) for x in release]
+    return version_int >= release
+            
 def image_rotate(file_name, angle, img_type):
     """ rotates the image
     @param file_name: the name of the attachment
@@ -336,13 +348,19 @@
         request = self.request
         if not request.user.may.read(pagename):
             return _("You are not allowed to view this page!"), "error"
+        if not ensureversion(request, '1.9.0'):
+            target = request.form.get('target', [''])[0]
+            images = request.form.get('images', [''])[0]
+            original_images = request.form.get('original_images', [''])[0]
+            all_description = request.form.get('alias', [''])[0]
+            all_exif_date = request.form.get('exif_date', [''])[0]
+        else:
+            target = request.values.get('target', '')
+            images = request.values.get('images', '')
+            original_images = request.values.get('original_images', '')
+            all_description = request.values.get('alias', '')
+            all_exif_date = request.values.get('exif_date', '')
 
-        target = request.form.get('target', [''])[0]
-        images = request.form.get('images', [''])[0]
-        original_images = request.form.get('original_images', [''])[0]
-
-        all_description = request.form.get('alias', [''])[0]
-        all_exif_date = request.form.get('exif_date', [''])[0]
 
         if not (target and images and all_description and all_exif_date):
             return _("Missing required parameters!"), "error"
@@ -370,8 +388,9 @@
         web['src'] = cache.url(request, target)
         web['title'] = target
 
-        mimetype = "text/html"
-        request.emit_http_headers(["Content-Type: %s; charset=%s" % (mimetype, config.charset)])
+        if not ensureversion(request, '1.9.0'):
+            mimetype = "text/html"
+            request.emit_http_headers(["Content-Type: %s; charset=%s" % (mimetype, config.charset)])
 
         request.theme.send_title(pagename,
                                  pagename=pagename,
@@ -389,10 +408,16 @@
     def render(self):
         """ executes the commands of the form data """
         _ = self.request.getText
+
         request = self.request
-        pagename = request.form.get('pagename', [self.pagename])[0]
-        command = request.form.get('do', ['none'])[0]
-        target = request.form.get('target', [''])[0]
+        if not ensureversion(request, '1.9.0'):
+            pagename = request.form.get('pagename', [self.pagename])[0]
+            command = request.form.get('do', ['none'])[0]
+            target = request.form.get('target', [''])[0]
+        else:
+            pagename = request.values.get('pagename', self.pagename)
+            command = request.values.get('do', 'none')
+            target = request.values.get('target', '')
 
         # View Slides
         if command == 'slide_show':
@@ -401,8 +426,12 @@
         # only users which are allowed to delete should use this tool
         elif request.user.may.delete(pagename):
             # only POST continues
-            if request.request_method != 'POST':
-                return _('Missing parameters or GET method used'), "error"
+            if not ensureversion(request, '1.9.0'):
+                if request.request_method != 'POST':
+                    return _('Missing parameters or GET method used'), "error"
+            else:
+                if request.method != 'POST':
+                    return _('Missing parameters or GET method used'), "error"
 
             filename, ext = os.path.splitext(target)
             img_type = "JPEG"