changeset 229:6cc67d4f27cb

arnica_slides: refactored call of send_page
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 02 Sep 2008 09:21:28 +0200
parents 4507998dcfbc
children 7b71406a5baf
files data/plugin/action/arnica_slides.py
diffstat 1 files changed, 18 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/arnica_slides.py	Mon Sep 01 20:53:33 2008 +0200
+++ b/data/plugin/action/arnica_slides.py	Tue Sep 02 09:21:28 2008 +0200
@@ -328,10 +328,7 @@
         _ = self.request.getText
         request = self.request
         if not request.user.may.read(pagename):
-            msg = _("You are not allowed to view this page!")
-            request.theme.add_msg(msg, "error")
-            Page(request, pagename).send_page()
-            return
+            return _("You are not allowed to view this page!"), "error"
 
         target = request.form.get('target', [''])[0]
         images = request.form.get('images', [''])[0]
@@ -341,10 +338,7 @@
         all_exif_date = request.form.get('exif_date', [''])[0]
 
         if not (target and images and all_description and all_exif_date):
-            msg = _("Missing required parameters!")
-            request.theme.add_msg(msg, "error")
-            Page(request, pagename).send_page()
-            return
+            return _("Missing required parameters!"), "error"
 
         images = unpackLine(images)
         images = images[1:]
@@ -362,10 +356,7 @@
         try:
             idx = images.index(target)
         except ValueError:
-            msg = _("Attachment '%(filename)s' does not exist!") % {'filename': target}
-            request.theme.add_msg(msg, "error")
-            Page(request, pagename).send_page()
-            return
+            return _("Attachment '%(filename)s' does not exist!") % {'filename': target}, "error"
 
         web = {}
 
@@ -386,6 +377,7 @@
         request.write(request.formatter.endContent())
         request.write(request.theme.send_footer(pagename))
         request.theme.send_closing_html()
+        return None, None
 
     def render(self):
         """ executes the commands of the form data """
@@ -400,16 +392,13 @@
 
         # View Slides
         if command == 'slide_show':
-            self.slide_show(pagename)
+            return self.slide_show(pagename)
 
         # 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':
-                msg = _('Missing parameters or GET method used')
-                request.theme.add_msg(msg, "error")
-                self.page.send_page()
-                return
+                return _('Missing parameters or GET method used'), "error"
 
             filename, ext = os.path.splitext(target)
             img_type = "JPEG"
@@ -435,34 +424,34 @@
                 except:
                     pass
                 AttachFile.move_file(request, pagename, pagename, target, bakfile)
-                msg = _('%(target)s deleted, backup in place') % {'target': target}
+                return None, None
 
             elif command == 'rotate_left':
                 image_rotate(infile, 90, img_type)
-                msg = _('%(target)s rotated left 90 degrees') % {'target': target}
+                return _('%(target)s rotated left 90 degrees') % {'target': target}, "info"
 
             elif command == 'rotate_right':
                 image_rotate(infile, 270, img_type)
-                msg = _('%(target)s rotated right 90 degrees') % {'target': target}
+                return _('%(target)s rotated right 90 degrees') % {'target': target}, "info"
 
             else:
                 # fallback
-                msg = _('action not implemented: %s') % (command, )
+                return _('action not implemented: %s') % (command, ), "info"
         else:
-            msg = _('Your are not allowed to change attachments on this page: %s') % (pagename, )
+            return _('Your are not allowed to change attachments on this page: %s') % (pagename, ), "error"
 
-        if msg:
-            request.theme.add_msg(msg, "info")
-            self.page.send_page()
 
 def execute(pagename, request):
     """ Main dispatcher for the arnica_slides action. """
     _ = request.getText
+    msg = None
     if not Image:
         msg = _('The action %(action)s needs Python Imaging Library (PIL) installed') % {'action': action_name}
-        request.theme.add_msg(msg, "error")
+        state = "error"
+    if not msg:
+        msg, state = arnica_slides(request, pagename).render()
+    if msg:
+        request.theme.add_msg(msg, state)
         Page(request, pagename).send_page()
-        return
+    return
 
-    return arnica_slides(request, pagename).render()
-