changeset 242:db18e0d98dd0

text_x_arnica: bug fix for wrong order of only_items=True
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Wed, 03 Sep 2008 09:40:13 +0200
parents d082511f6a3b
children 94c4f97265eb
files data/plugin/parser/text_x_arnica.py
diffstat 1 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Tue Sep 02 11:39:49 2008 +0200
+++ b/data/plugin/parser/text_x_arnica.py	Wed Sep 03 09:40:13 2008 +0200
@@ -339,8 +339,12 @@
         """
 
         for attfile in files:
-            # only files not thumb_key or webnails
-            self.description.append(image_alias.get(attfile, attfile))
+            if image_alias.get(attfile):
+                # use alias
+                self.description.append(image_alias.get(attfile)[0])
+            else:
+                # use filename
+                self.description.append(attfile)
             self.high_resolution_image.append(attfile)
             fname, ext = os.path.splitext(attfile)
             key = cache.key(self.request, itemname=self.pagename, attachname=attfile)
@@ -367,16 +371,18 @@
         return wikiutil.renderText(self.request, WikiParser, text)
 
     def get_image_alias(self):
-        """  gets the quotes from the item list and returns a dictionary of image and alias"""        
+        """  gets the quotes from the item list and returns a dictionary of image and alias """
         # ToDo keep the order of the given quotes
         quotes = self.raw.split('\n')
         quotes = [quote.strip() for quote in quotes]
         quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
         image_alias = {}
+        counter = 0
         for line in quotes:
             if line.startswith('[[') and line.endswith(']]'):
                 img, alias = line[2:-2].split('|', 1)
-                image_alias[img.strip()] = self.formatter.text(alias.strip())
+                image_alias[img.strip()] = (self.formatter.text(alias.strip()), counter)
+                counter += 1
         return image_alias
 
     def select_files(self, formatter):
@@ -390,11 +396,16 @@
         image_dict = {}
         image_alias = self.get_image_alias()
         if self.only_items:
+            # get the same order of files and aliastext as on the page written
             files = image_alias.keys()
+            alias_text = image_alias.values()
+            index = [alias_text[idx][1] for idx in range(len(files))]
+            alias_text = [alias_text[idx][0] for idx in index]
+            files = [files[idx] for idx in index]
+
             all_files = [fn for fn in files if wikiutil.isPicture(fn) and
                          AttachFile.exists(self.request, self.pagename, fn)]
             if self.sort_by_alias:
-                alias_text = image_alias.values()
                 # ToDo use a longer var
                 i = 0
                 for attfile in all_files: