changeset 23:26d9d5f67365

arnica_slides: some more refactoring
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 23 May 2008 10:30:14 +0200
parents 914915a1c47a
children 9d46f04d556a
files data/plugin/action/arnica_slides.py
diffstat 1 files changed, 86 insertions(+), 99 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/arnica_slides.py	Fri May 23 10:29:36 2008 +0200
+++ b/data/plugin/action/arnica_slides.py	Fri May 23 10:30:14 2008 +0200
@@ -24,78 +24,14 @@
 
 action_name = __name__.split('.')[-1]
 
-def getAttachUrl(pagename, filename):
-    url = "/%(pagename)s?action=arnica_slides&do=view&target=%(filename)s" % {'pagename': pagename,
-                                                                              'filename': filename}
-    return wikiutil.escape(url)
-
-class arnica_slides(ActionBase):
-    """ arnica_slides page action
-
-    Note: the action name is the class name
+def html_js(request, counter):
+    """ javscript for the slides 
+    @param request: request object
+    @param this_image:  url of image to start
+    @param counter: index position of this_image
     """
-    def __init__(self, request, pagename):
-        ActionBase.__init__(self, pagename, request)
-        self.request = request
-        self.pagename = pagename
-        self.page = Page(request, pagename)
-        self.method = 'POST'
-        self.enctype = 'multipart/form-data'
-
-    def is_excluded(self):
-        """ Return True if action is excluded """
-        return self.actionname in self.cfg.actions_excluded
-
-    def is_allowed(self):
-        """ Return True if read access is allowed """
-        may = self.request.user.may
-        return may.read(self.pagename)
 
-    def get_path_url(self, request, pagename, attachment_path):
-        """ Returns attachment path and it's url 
-        @param request: request object
-        @pagename: pagename of attachments
-        @attachment_path: path to attachment
-        """
-        url = AttachFile.getAttachUrl(pagename, '', request)
-        # xxx fix this at the right place!
-        url = url.replace('//', '/')
-        return attachment_path, url
-
-    def option_list(self, this_image, pagename, text, request, image_for_webnail):
-        """ generates the pulldown option list
-        @param this_image: selected image  on top
-        @param pagename: pagename of attachments
-        @param text: array of filenames
-        @param request: request object
-        """
-        txt = ''
-
-        for filename in text:
-            if not image_for_webnail:
-                url = getAttachUrl(pagename, filename)
-            else:
-                url = AttachFile.getAttachUrl(pagename, filename, request)
-
-            if url == this_image:
-                txt += '<option selected value="%(name)s">%(alias)s' % {
-                    "name": this_image,
-                    "alias": filename.replace('tmp.', '')}
-            else:
-                txt += '<option value="%(name)s">%(alias)s' % {
-                    "name": this_image,
-                    "alias": filename.replace('tmp.', '')}
-
-        return txt
-
-    def html_js(self, request, counter):
-        """ javscript for the slides 
-        @param request: request object
-        @param this_image:  url of image to start
-        @param counter: index position of this_image
-        """
-
-        html = '''
+    html = '''
 <SCRIPT LANGUAGE="JavaScript">
 <!-- Original:  Ricocheting (ricocheting@hotmail.com) -->
 <!-- Web Site:  http://www.ricocheting.com -->
@@ -218,33 +154,32 @@
   'htdocs': request.cfg.url_prefix_static,
   'counter': counter}
 
-        return html
+    return html
 
-    def html_slideform(self, request, pagename, alias, exif_date, target, idx, image_for_webnail):
-        """ html code for the slideform
-        @param request: request object
-        @param pagename: pagename where the attachments are located
-        @param url_wiki_page: 
-        @param alias: text alias for filename
-        @param exif_date:  date information 
-        @param target: all images 
-        @param idx:  index position of the image
-        @param image_for_webnail:  identifier for AttchFile or arnica_slides
-        """
-        if not image_for_webnail:
-            static_url = getAttachUrl(pagename, "")
-        else:
-            attachment_path = AttachFile.getAttachDir(request, pagename)
-            static_path, static_url = self.get_path_url(request, pagename, attachment_path)
+def html_slideform(request, pagename, alias, exif_date, target, idx, image_for_webnail):
+    """ html code for the slideform
+    @param request: request object
+    @param pagename: pagename where the attachments are located
+    @param url_wiki_page: 
+    @param alias: text alias for filename
+    @param exif_date:  date information 
+    @param target: all images 
+    @param idx:  index position of the image
+    @param image_for_webnail:  identifier for AttchFile or arnica_slides
+    """
+    if not image_for_webnail:
+        static_url = getAttachUrl(pagename, "")
+    else:
+        static_url = AttachFile.getAttachUrl(pagename, "", request)
 
-        option_webnail = self.option_list(static_url + target[idx], pagename, target, request, image_for_webnail)
-
-        inner_table_style = ' style="border-style:none; margin:10px;"'
+    option_webnail = option_list(static_url + target[idx], pagename, target, request, image_for_webnail)
 
-        this_webnail_list = ''
-        for name in target:
-            this_webnail_list += static_url + name + ','
-            html = '''
+    inner_table_style = ' style="border-style:none; margin:10px;"'
+
+    this_webnail_list = ''
+    for name in target:
+        this_webnail_list += static_url + name + ','
+        html = '''
 <form name=slideform method="POST">
    <input type="hidden" name="flag" value="webnail">
    <input type="hidden" name="webnail_list" value='%(this_webnail_list)s'>
@@ -311,7 +246,61 @@
 "tablestyle": inner_table_style,
 "option_webnails": option_webnail,
 }
-        return html
+    return html
+    
+def option_list(this_image, pagename, text, request, image_for_webnail):
+    """ generates the pulldown option list
+    @param this_image: selected image  on top
+    @param pagename: pagename of attachments
+    @param text: array of filenames
+    @param request: request object
+    """
+    txt = ''
+
+    for filename in text:
+        if not image_for_webnail:
+            url = getAttachUrl(pagename, filename)
+        else:
+            url = AttachFile.getAttachUrl(pagename, filename, request)
+
+        if url == this_image:
+            txt += '<option selected value="%(name)s">%(alias)s' % {
+                    "name": this_image,
+                    "alias": filename.replace('tmp.', '')}
+        else:
+            txt += '<option value="%(name)s">%(alias)s' % {
+                    "name": this_image,
+                    "alias": filename.replace('tmp.', '')}
+
+    return txt
+
+def getAttachUrl(pagename, filename):
+    """ Get URL that points to cache of `filename` on page `pagename`. """
+    url = "/%(pagename)s?action=arnica_slides&do=view&target=%(filename)s" % {'pagename': pagename,
+                                                                              'filename': filename}
+    return wikiutil.escape(url)
+
+class arnica_slides(ActionBase):
+    """ arnica_slides page action
+
+    Note: the action name is the class name
+    """
+    def __init__(self, request, pagename):
+        ActionBase.__init__(self, pagename, request)
+        self.request = request
+        self.pagename = pagename
+        self.page = Page(request, pagename)
+        self.method = 'POST'
+        self.enctype = 'multipart/form-data'
+
+    def is_excluded(self):
+        """ Return True if action is excluded """
+        return self.actionname in self.cfg.actions_excluded
+
+    def is_allowed(self):
+        """ Return True if read access is allowed """
+        may = self.request.user.may
+        return may.read(self.pagename)
 
     def do_action(self):
         """ Do the action and either return error msg or None, if there was no error. """
@@ -404,10 +393,10 @@
             request.theme.send_title(pagename,
                                  pagename=pagename,
                                  body_onload="arnica_preload();",
-                                 html_head=self.html_js(request, idx))
+                                 html_head=html_js(request, idx))
 
             request.write(request.formatter.startContent("content"))
-            html = self.html_slideform(request, pagename, all_description, all_exif_date, images, idx, image_for_webnail)
+            html = html_slideform(request, pagename, all_description, all_exif_date, images, idx, image_for_webnail)
             request.write(html)
             request.write(request.formatter.endContent())
             request.write(request.theme.send_footer(pagename))
@@ -452,8 +441,6 @@
         elif request.user.may.delete(pagename):
         # only users which are allowed to delete should use this tool
         # ToDo besides lots of refactoring, logig when what is needed has to be rechecked
-        # e.g. we need to rotate only the master image and delete the cache files
-        # because they will be recreated if they are missing 
 
             target = request.form.get('target', [''])[0]
             filename, ext = os.path.splitext(target)