changeset 527:09b97ed541e2

macro.ListPages: keyword for selecting link text from pagename or subpage added
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 16 May 2010 14:27:24 +0200
parents 56cbdae11f25
children a39542a85f10
files data/plugin/macro/ListPages.py
diffstat 1 files changed, 21 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/macro/ListPages.py	Sun May 16 13:26:17 2010 +0200
+++ b/data/plugin/macro/ListPages.py	Sun May 16 14:27:24 2010 +0200
@@ -15,11 +15,21 @@
 import re
 from MoinMoin import search, wikiutil
 
-def macro_ListPages(macro, search_term=u'.+', list_type=("number_list", "bullet_list")):
+def _subpage(pagename):
+    """
+    returns the last last segement of a pagename
+    @param pagename: the pagename
+    """
+    segments = pagename.split('/')
+    return segments[-1]
+
+def macro_ListPages(macro, search_term=u'.+', list_type=("number_list", "bullet_list"),
+                    link=("pagename", "subpage")):
     """
     lists pages
     @param search_term: regex for searching of page titles
     @param list_type: select type of list in between number_list and bullet_list
+    @param link: change the link from pagename to subpage for shorter links
     """
     _ = macro._
     case = 0
@@ -36,10 +46,16 @@
         filterfn = re.compile(ur"%s" % search_term, re.U).match
         pageobjs = rootpage.getPageList(include_underlay=False, exists=1, filter=filterfn, return_objects=True)
         f = macro.request.formatter
-        ret = [''.join([f.listitem(1),
-               f.url(1, href=page.url(macro.request, escape=0)),
-               page.page_name,
-               f.url(0)]) for page in pageobjs]
+        if link == "pagename":
+            ret = [''.join([f.listitem(1),
+                   f.url(1, href=page.url(macro.request, escape=0)),
+                   page.page_name,
+                   f.url(0)]) for page in pageobjs]
+        if link == "subpage":
+             ret = [''.join([f.listitem(1),
+                   f.url(1, href=page.url(macro.request, escape=0)),
+                   _subpage(page.page_name),
+                   f.url(0)]) for page in pageobjs]   
         ret.sort()
         if list_type == "number_list":
             ret = ''.join([f.number_list(1), ''.join(ret), f.number_list(0)])