Attachment 'ListPagePacks.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - ListPagePacks Macro
   4     This macro shows in which pagepack a page is and if the page is translated
   5 
   6     @copyright: 2010 MoinMoin:ReimarBauer
   7 
   8     @license: GNU GPL, see COPYING for details.
   9 """
  10 
  11 from MoinMoin import i18n
  12 from MoinMoin import wikiutil
  13 from MoinMoin.action import AttachFile
  14 from MoinMoin.packages import ZipPackage, unpackLine
  15 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
  16 from MoinMoin.i18n import strings
  17 i18n.strings = strings
  18 from MoinMoin.Page import Page
  19 from MoinMoin.util.dataset import TupleDataset, Column
  20 from MoinMoin.widget.browser import DataBrowserWidget
  21 
  22 
  23 def macro_ListPagePacks(macro):
  24     """
  25     lists all pages of LanguageSetup dependent for your language you get if help is wanted 
  26     """
  27     request = macro.request
  28     lang = request.lang or 'en'
  29     wiki_languages = sorted(i18n.wikiLanguages().keys())
  30     if lang not in wiki_languages:
  31         lang = 'en'
  32 
  33     lang_package_prefix =  i18n.wikiLanguages()[lang]['x-language-in-english']
  34     language_setup_page = 'LanguageSetup'
  35     all_pages = getattr(strings, 'all_pages')
  36 
  37     pagesets = list(strings.pagesets)
  38     pagesets.remove('all_pages')
  39     pagesets.remove('all_system_pages')
  40     pagesets = ['all_pages', 'all_system_pages'] + pagesets
  41 
  42     data = TupleDataset()
  43     data.columns = []
  44     data.columns.extend([Column("pagename", label="pagename")])
  45     for pagename in all_pages:
  46         row = []
  47         for ps in pagesets:
  48             help_us = ""
  49             footnote = ""
  50             lps = "%s_%s.zip" % (lang_package_prefix, ps)
  51             if pagename in getattr(strings, ps):
  52                 if ps == 'all_pages' and not (lang == "en" or pagename in getattr(strings, "not_translated_system_pages")):
  53                     footnote = "[[http://master19.moinmo.in/CheckTranslation/FrontPage?action=CheckTranslation&pageset=%(pageset)s&language=%(lang)s|help translating]]" % {"pageset": ps,
  54                                                                                                                                                                             "lang": lang}
  55                     if AttachFile.exists(request, language_setup_page, lps):
  56                         packagefile = AttachFile.getFilename(request, language_setup_page, lps)
  57                         package = ZipPackage(request, packagefile)
  58                         scriptfile = package.getScript().split('\n')
  59                         tranlated_pages_for_this_set = [unpackLine(line)[2].strip() for line in 
  60                                                         scriptfile if line.startswith('ReplaceUnderlay')]
  61                         test_name = i18n.getText(pagename, request, lang).strip()
  62                         
  63                         if not test_name in tranlated_pages_for_this_set:
  64                             help_us = """not in your language "%s" translated <<FootNote(%s)>>""" % (lang_package_prefix, footnote)
  65                     else:
  66                         help_us = """not in your language "%s" translated <<FootNote(%s)>>""" % (lang_package_prefix)
  67                 row.append(wikiutil.renderText(request, WikiParser, '(./) ' + help_us))
  68             else:
  69                 row.append('')
  70         page = Page(request, pagename)
  71         link = page.link_to(request)
  72         data.addRow([link] + row)
  73 
  74     for key in pagesets:
  75         key = key.replace('_pages', '').replace('_', ' ')
  76         data.columns.extend([Column(key, label=key)])
  77         
  78     table = DataBrowserWidget(request)
  79     table.setData(data)
  80         
  81     html = ''.join(table.format(method='GET'))
  82     return html
  83  

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-02-20 23:17:08, 3.6 KB) [[attachment:ListPagePacks.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.