Back to index

moin  1.9.0~rc2
language_setup.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - language_setup
00004 
00005     The superuser gets a table of language packages listed dependent on the selected language
00006     for installation.
00007 
00008     @copyright: 2009 MoinMoin:ReimarBauer,
00009                      MoinMoin:ThomasWaldmnann
00010 
00011     @license: GNU GPL, see COPYING for details.
00012 """
00013 
00014 from MoinMoin import i18n, packages
00015 from MoinMoin.i18n import strings
00016 i18n.strings = strings
00017 
00018 from MoinMoin.action import AttachFile
00019 from MoinMoin.util.dataset import TupleDataset, Column
00020 from MoinMoin.widget.browser import DataBrowserWidget
00021 
00022 def execute(pagename, request):
00023     _ = request.getText
00024     if not request.user or not request.user.isSuperUser():
00025         msg = _('Only superuser is allowed to use this action.')
00026         request.theme.add_msg(msg, "error")
00027         request.page.send_page()
00028         return ''
00029     fmt = request.html_formatter
00030     language_setup_page = 'LanguageSetup'
00031     not_translated_system_pages = 'not_translated_system_pages.zip'
00032     files = AttachFile._get_files(request, language_setup_page)
00033     if not files:
00034         msg = _('No page packages found.')
00035         request.theme.add_msg(msg, "error")
00036         request.page.send_page()
00037         return ''
00038     wiki_languages = list(set([lang_file.split('_')[0] for lang_file in files]) - set(['00']))
00039     wiki_languages.sort()
00040 
00041     lang = request.values.get('language') or 'English'
00042     target = request.values.get('target') or ''
00043     msg = ''
00044     # if target is given it tries to install the package.
00045     if target:
00046         dummy_pagename, dummy_target, targetpath = AttachFile._access_file(language_setup_page, request)
00047         package = packages.ZipPackage(request, targetpath)
00048         if package.isPackage():
00049             if package.installPackage():
00050                 msg = _("Attachment '%(filename)s' installed.") % {'filename': target}
00051             else:
00052                 msg = _("Installation of '%(filename)s' failed.") % {'filename': target}
00053         else:
00054             msg = _('The file %s is not a MoinMoin package file.') % target
00055 
00056 
00057     data = TupleDataset()
00058     data.columns = [
00059            Column('page package', label=_('page package')),
00060            Column('action', label=_('install')),
00061         ]
00062 
00063     label_install = _("install")
00064     for pageset_name in i18n.strings.pagesets:
00065         attachment = "%s_%s.zip" % (lang, pageset_name)
00066         # not_translated_system_pages are in english
00067         if attachment.endswith(not_translated_system_pages):
00068             attachment = 'English_not_translated_system_pages.zip'
00069         install_link = ''
00070         querystr = {'action': 'language_setup', 'target': attachment, 'language': lang}
00071         if AttachFile.exists(request, language_setup_page, attachment):
00072             install_link = request.page.link_to(request, label_install, querystr=querystr)
00073         data.addRow((pageset_name, install_link))
00074 
00075     table = DataBrowserWidget(request)
00076     table.setData(data)
00077     page_table = ''.join(table.format(method='GET'))
00078 
00079     fmt = request.formatter
00080     lang_links = [request.page.link_to_raw(request, _lang,
00081                                         querystr={'action': 'language_setup',
00082                                                   'language': _lang,
00083                                                   'pageset': pageset_name, })
00084                   for _lang in wiki_languages]
00085 
00086     lang_selector = u''.join([fmt.paragraph(1), _("Choose:"), ' ', ' '.join(lang_links), fmt.paragraph(0)])
00087 
00088     title = _("Install language packs for '%s'") % (lang)
00089     request.theme.add_msg(msg, "info")
00090     request.theme.send_title(title, page=request.page, pagename=pagename)
00091     request.write(request.formatter.startContent("content"))
00092     request.write(lang_selector)
00093     request.write(page_table)
00094     request.write(request.formatter.endContent())
00095     request.theme.send_footer(pagename)
00096     request.theme.send_closing_html()
00097