Back to index

moin  1.9.0~rc2
Functions
MoinMoin.action.language_setup Namespace Reference

Functions

def execute

Function Documentation

def MoinMoin.action.language_setup.execute (   pagename,
  request 
)

Definition at line 22 of file language_setup.py.

00022 
00023 def execute(pagename, request):
00024     _ = request.getText
00025     if not request.user or not request.user.isSuperUser():
00026         msg = _('Only superuser is allowed to use this action.')
00027         request.theme.add_msg(msg, "error")
00028         request.page.send_page()
00029         return ''
00030     fmt = request.html_formatter
00031     language_setup_page = 'LanguageSetup'
00032     not_translated_system_pages = 'not_translated_system_pages.zip'
00033     files = AttachFile._get_files(request, language_setup_page)
00034     if not files:
00035         msg = _('No page packages found.')
00036         request.theme.add_msg(msg, "error")
00037         request.page.send_page()
00038         return ''
00039     wiki_languages = list(set([lang_file.split('_')[0] for lang_file in files]) - set(['00']))
00040     wiki_languages.sort()
00041 
00042     lang = request.values.get('language') or 'English'
00043     target = request.values.get('target') or ''
00044     msg = ''
00045     # if target is given it tries to install the package.
00046     if target:
00047         dummy_pagename, dummy_target, targetpath = AttachFile._access_file(language_setup_page, request)
00048         package = packages.ZipPackage(request, targetpath)
00049         if package.isPackage():
00050             if package.installPackage():
00051                 msg = _("Attachment '%(filename)s' installed.") % {'filename': target}
00052             else:
00053                 msg = _("Installation of '%(filename)s' failed.") % {'filename': target}
00054         else:
00055             msg = _('The file %s is not a MoinMoin package file.') % target
00056 
00057 
00058     data = TupleDataset()
00059     data.columns = [
00060            Column('page package', label=_('page package')),
00061            Column('action', label=_('install')),
00062         ]
00063 
00064     label_install = _("install")
00065     for pageset_name in i18n.strings.pagesets:
00066         attachment = "%s_%s.zip" % (lang, pageset_name)
00067         # not_translated_system_pages are in english
00068         if attachment.endswith(not_translated_system_pages):
00069             attachment = 'English_not_translated_system_pages.zip'
00070         install_link = ''
00071         querystr = {'action': 'language_setup', 'target': attachment, 'language': lang}
00072         if AttachFile.exists(request, language_setup_page, attachment):
00073             install_link = request.page.link_to(request, label_install, querystr=querystr)
00074         data.addRow((pageset_name, install_link))
00075 
00076     table = DataBrowserWidget(request)
00077     table.setData(data)
00078     page_table = ''.join(table.format(method='GET'))
00079 
00080     fmt = request.formatter
00081     lang_links = [request.page.link_to_raw(request, _lang,
00082                                         querystr={'action': 'language_setup',
00083                                                   'language': _lang,
00084                                                   'pageset': pageset_name, })
00085                   for _lang in wiki_languages]
00086 
00087     lang_selector = u''.join([fmt.paragraph(1), _("Choose:"), ' ', ' '.join(lang_links), fmt.paragraph(0)])
00088 
00089     title = _("Install language packs for '%s'") % (lang)
00090     request.theme.add_msg(msg, "info")
00091     request.theme.send_title(title, page=request.page, pagename=pagename)
00092     request.write(request.formatter.startContent("content"))
00093     request.write(lang_selector)
00094     request.write(page_table)
00095     request.write(request.formatter.endContent())
00096     request.theme.send_footer(pagename)
00097     request.theme.send_closing_html()
00098