annotate MoinMoin/action/language_setup.py @ 6025:05a6897ee496

"userdir" caching scope: use it for userid lookup caches, reduce code duplication For same reasons (see previous changesets), we need to use the "userdir" scope for the name2id / openid2id lookup caches, too.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 12 Feb 2014 12:07:22 +0100
parents e50b087c4572
children
rev   line source
4903
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
2 """
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
3 MoinMoin - language_setup
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
4
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
5 The superuser gets a table of language packages listed dependent on the selected language
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
6 for installation.
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
7
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
8 @copyright: 2009 MoinMoin:ReimarBauer,
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
9 MoinMoin:ThomasWaldmnann
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
10
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
11 @license: GNU GPL, see COPYING for details.
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
12 """
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
13
5679
e50b087c4572 merge moin/1.7
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5375
diff changeset
14 from MoinMoin import i18n, packages, wikiutil
4903
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
15 from MoinMoin.i18n import strings
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
16 i18n.strings = strings
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
17
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
18 from MoinMoin.action import AttachFile
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
19 from MoinMoin.util.dataset import TupleDataset, Column
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
20 from MoinMoin.widget.browser import DataBrowserWidget
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
21
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
22 def execute(pagename, request):
4918
9953cf1cec5b action language_setup: error messages added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4904
diff changeset
23 _ = request.getText
4903
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
24 if not request.user or not request.user.isSuperUser():
4918
9953cf1cec5b action language_setup: error messages added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4904
diff changeset
25 msg = _('Only superuser is allowed to use this action.')
9953cf1cec5b action language_setup: error messages added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4904
diff changeset
26 request.theme.add_msg(msg, "error")
9953cf1cec5b action language_setup: error messages added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4904
diff changeset
27 request.page.send_page()
4903
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
28 return ''
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
29 fmt = request.html_formatter
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
30 language_setup_page = 'LanguageSetup'
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
31 not_translated_system_pages = 'not_translated_system_pages.zip'
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
32 files = AttachFile._get_files(request, language_setup_page)
4918
9953cf1cec5b action language_setup: error messages added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4904
diff changeset
33 if not files:
9953cf1cec5b action language_setup: error messages added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4904
diff changeset
34 msg = _('No page packages found.')
9953cf1cec5b action language_setup: error messages added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4904
diff changeset
35 request.theme.add_msg(msg, "error")
9953cf1cec5b action language_setup: error messages added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4904
diff changeset
36 request.page.send_page()
9953cf1cec5b action language_setup: error messages added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4904
diff changeset
37 return ''
5375
97a4b92d2055 language packs: use -- (not _) as separator between language and pageset name, fixes problems with languages that have an underscore
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5244
diff changeset
38 wiki_languages = list(set([lang_file.split('--')[0] for lang_file in files]) - set(['00_needs_fixing.zip']))
4903
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
39 wiki_languages.sort()
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
40
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
41 lang = request.values.get('language') or 'English'
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
42 target = request.values.get('target') or ''
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
43 msg = ''
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
44 # if target is given it tries to install the package.
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
45 if target:
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
46 dummy_pagename, dummy_target, targetpath = AttachFile._access_file(language_setup_page, request)
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
47 package = packages.ZipPackage(request, targetpath)
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
48 if package.isPackage():
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
49 if package.installPackage():
5244
9730c2936db7 language_setup, packages: new method ReplaceUnderlayAttachment introduced.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4918
diff changeset
50 msg = _("Attachment '%(filename)s' installed.") % {'filename': target}
4903
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
51 else:
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
52 msg = _("Installation of '%(filename)s' failed.") % {'filename': target}
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
53 else:
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
54 msg = _('The file %s is not a MoinMoin package file.') % target
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
55
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
56
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
57 data = TupleDataset()
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
58 data.columns = [
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
59 Column('page package', label=_('page package')),
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
60 Column('action', label=_('install')),
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
61 ]
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
62
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
63 label_install = _("install")
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
64 for pageset_name in i18n.strings.pagesets:
5375
97a4b92d2055 language packs: use -- (not _) as separator between language and pageset name, fixes problems with languages that have an underscore
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5244
diff changeset
65 attachment = "%s--%s.zip" % (lang, pageset_name)
4903
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
66 # not_translated_system_pages are in english
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
67 if attachment.endswith(not_translated_system_pages):
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
68 attachment = 'English_not_translated_system_pages.zip'
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
69 install_link = ''
4904
c88234489140 action language_setup: fixed action name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4903
diff changeset
70 querystr = {'action': 'language_setup', 'target': attachment, 'language': lang}
4903
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
71 if AttachFile.exists(request, language_setup_page, attachment):
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
72 install_link = request.page.link_to(request, label_install, querystr=querystr)
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
73 data.addRow((pageset_name, install_link))
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
74
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
75 table = DataBrowserWidget(request)
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
76 table.setData(data)
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
77 page_table = ''.join(table.format(method='GET'))
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
78
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
79 fmt = request.formatter
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
80 lang_links = [request.page.link_to_raw(request, _lang,
4904
c88234489140 action language_setup: fixed action name
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 4903
diff changeset
81 querystr={'action': 'language_setup',
4903
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
82 'language': _lang,
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
83 'pageset': pageset_name, })
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
84 for _lang in wiki_languages]
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
85
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
86 lang_selector = u''.join([fmt.paragraph(1), _("Choose:"), ' ', ' '.join(lang_links), fmt.paragraph(0)])
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
87
5679
e50b087c4572 merge moin/1.7
Eugene Syromyatnikov <evgsyr@gmail.com>
parents: 5375
diff changeset
88 title = _("Install language packs for '%s'") % wikiutil.escape(lang)
4903
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
89 request.theme.add_msg(msg, "info")
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
90 request.theme.send_title(title, page=request.page, pagename=pagename)
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
91 request.write(request.formatter.startContent("content"))
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
92 request.write(lang_selector)
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
93 request.write(page_table)
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
94 request.write(request.formatter.endContent())
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
95 request.theme.send_footer(pagename)
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
96 request.theme.send_closing_html()
4eea6a2856dd action language_setup: The superuser gets a table of language packages listed dependent on the selected language for installation.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
97