changeset 387:9b68e1090065

action InstallLanguage: install action improved
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 24 Jul 2009 19:48:31 +0200
parents 2987a4ef997a
children fb3f4a1fb50b 764834d3a461
files data/plugin/action/InstallLanguage.py
diffstat 1 files changed, 26 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/InstallLanguage.py	Fri Jul 24 12:32:19 2009 +0200
+++ b/data/plugin/action/InstallLanguage.py	Fri Jul 24 19:48:31 2009 +0200
@@ -11,13 +11,11 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-from MoinMoin import i18n
+from MoinMoin import i18n, packages
 from MoinMoin.i18n import strings
 i18n.strings = strings
 
 from MoinMoin.action import AttachFile
-
-from MoinMoin.Page import Page
 from MoinMoin.util.dataset import TupleDataset, Column
 from MoinMoin.widget.browser import DataBrowserWidget
 
@@ -31,8 +29,24 @@
     files = AttachFile._get_files(request, language_setup_page)
     wiki_languages = list(set([lang_file.split('_')[0] for lang_file in files]) - set(['00']))
     wiki_languages.sort()
-    lang_default = 'English'
-    lang = request.values.get('language') or lang_default
+
+    lang = request.values.get('language') or 'English'
+    target = request.values.get('target') or ''
+    msg = ''
+    # if target is given it tries to install the package.
+    if target:
+        dummy_pagename, dummy_target, targetpath = AttachFile._access_file(language_setup_page, request)
+        package = packages.ZipPackage(request, targetpath)
+        if package.isPackage():
+            if package.installPackage():
+                msg = package.msg
+                if not msg:
+                    msg = _("Attachment '%(filename)s' installed.") % {'filename': target}
+            else:
+                msg = _("Installation of '%(filename)s' failed.") % {'filename': target}
+        else:
+            msg = _('The file %s is not a MoinMoin package file.') % target
+
 
     data = TupleDataset()
     data.columns = [
@@ -43,13 +57,13 @@
     label_install = _("install")
     for pageset_name in i18n.strings.pagesets:
         attachment = "%s_%s.zip" % (lang, pageset_name)
+        # not_translated_system_pages are in english
         if attachment.endswith(not_translated_system_pages):
             attachment = 'English_not_translated_system_pages.zip'
         install_link = ''
+        querystr = {'action': 'InstallLanguage', 'target': attachment, 'language': lang}
         if AttachFile.exists(request, language_setup_page, attachment):
-            install_link = (fmt.url(1, AttachFile.getAttachUrl(language_setup_page, attachment, request, do='install')) + 
-                            fmt.text(label_install) +
-                            fmt.url(0))
+            install_link = request.page.link_to(request, label_install, querystr=querystr)
         data.addRow((pageset_name, install_link))
 
     table = DataBrowserWidget(request)
@@ -57,16 +71,16 @@
     page_table = ''.join(table.format(method='GET'))
 
     fmt = request.formatter
-    this_page = Page(request, pagename)
-    lang_links = [this_page.link_to_raw(request, _lang,
+    lang_links = [request.page.link_to_raw(request, _lang,
                                         querystr={'action': 'InstallLanguage',
                                                   'language': _lang,
                                                   'pageset': pageset_name, })
                   for _lang in wiki_languages]
 
     lang_selector = u''.join([fmt.paragraph(1), _("Choose:"), ' ', ' '.join(lang_links), fmt.paragraph(0)])
+
     title = _("Install language packs for '%s'") % (lang)
-
+    request.theme.add_msg(msg, "info")
     request.theme.send_title(title, page=request.page, pagename=pagename)
     request.write(request.formatter.startContent("content"))
     request.write(lang_selector)
@@ -74,3 +88,4 @@
     request.write(request.formatter.endContent())
     request.theme.send_footer(pagename)
     request.theme.send_closing_html()
+