Merge lp:~futatuki/mailman/edithtml-lang-select into lp:mailman/2.1

Proposed by Yasuhito FUTATSUKI at POEM on 2018-07-08
Status: Merged
Merged at revision: 1789
Proposed branch: lp:~futatuki/mailman/edithtml-lang-select
Merge into: lp:mailman/2.1
Diff against target: 95 lines (+34/-7)
1 file modified
Mailman/Cgi/edithtml.py (+34/-7)
To merge this branch: bzr merge lp:~futatuki/mailman/edithtml-lang-select
Reviewer Review Type Date Requested Status
Mark Sapiro 2018-07-08 Approve on 2018-07-09
Review via email: mp+349101@code.launchpad.net

Commit message

Allow to edit templates other than lists preferred language

Description of the change

This enables to edit templates for available languages without changing preferred_language temporary.

* Add language selecter to template editing page (if the list has multiple available language)
* Add link from editing page to template selection page

To post a comment you must log in.
Mark Sapiro (msapiro) wrote :

Thank you very mush for your contribution.

It is much appreciated.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Mailman/Cgi/edithtml.py'
2--- Mailman/Cgi/edithtml.py 2018-06-17 23:47:34 +0000
3+++ Mailman/Cgi/edithtml.py 2018-07-08 22:09:07 +0000
4@@ -138,6 +138,13 @@
5 Auth.loginpage(mlist, 'admin', msg=msg)
6 return
7
8+ # See if the user want to see this page in other language
9+ language = cgidata.getfirst('language', '')
10+ if language not in mlist.GetAvailableLanguages():
11+ language = mlist.preferred_language
12+ i18n.set_language(language)
13+ doc.set_language(language)
14+
15 realname = mlist.real_name
16 if len(parts) > 1:
17 template_name = parts[1]
18@@ -169,42 +176,62 @@
19 return
20
21 try:
22- if cgidata.keys():
23+ if cgidata.keys() and not cgidata.has_key('langform'):
24 if csrf_checked:
25- ChangeHTML(mlist, cgidata, template_name, doc)
26+ ChangeHTML(mlist, cgidata, template_name, doc, lang=language)
27 else:
28 doc.addError(
29 _('The form lifetime has expired. (request forgery check)'))
30- FormatHTML(mlist, doc, template_name, template_info)
31+ FormatHTML(mlist, doc, template_name, template_info, lang=language)
32 finally:
33 doc.AddItem(mlist.GetMailmanFooter())
34 print doc.Format()
35
36
37
38
39-def FormatHTML(mlist, doc, template_name, template_info):
40+def FormatHTML(mlist, doc, template_name, template_info, lang=None):
41+ if lang not in mlist.GetAvailableLanguages():
42+ lang = mlist.preferred_language
43+ lcset = Utils.GetCharSet(lang)
44 doc.AddItem(Header(1,'%s:' % mlist.real_name))
45 doc.AddItem(Header(1, template_info))
46 doc.AddItem('<hr>')
47
48 link = Link(mlist.GetScriptURL('admin'),
49 _('View or edit the list configuration information.'))
50+ backlink = Link(mlist.GetScriptURL('edithtml'),
51+ _('Edit the public HTML pages and text files'))
52
53 doc.AddItem(FontSize("+1", link))
54+ doc.AddItem(FontSize("+1", backlink))
55 doc.AddItem('<p>')
56 doc.AddItem('<hr>')
57+ if len(mlist.GetAvailableLanguages()) > 1:
58+ langform = Form(mlist.GetScriptURL('edithtml') + '/' + template_name,
59+ mlist=mlist, contexts=AUTH_CONTEXTS)
60+ langform.AddItem(
61+ mlist.FormatButton('editlang-button',
62+ text = _("Edit this template for")))
63+ langform.AddItem(mlist.GetLangSelectBox(lang))
64+ langform.AddItem(Hidden('langform', 'True'))
65+ doc.AddItem(langform)
66+ doc.AddItem('<hr>')
67 form = Form(mlist.GetScriptURL('edithtml') + '/' + template_name,
68 mlist=mlist, contexts=AUTH_CONTEXTS)
69- text = Utils.maketext(template_name, raw=1, mlist=mlist)
70+ text = Utils.maketext(template_name, raw=1, lang=lang, mlist=mlist)
71 # MAS: Don't websafe twice. TextArea does it.
72 form.AddItem(TextArea('html_code', text, rows=40, cols=75))
73 form.AddItem('<p>' + _('When you are done making changes...'))
74+ if lang != mlist.preferred_language:
75+ form.AddItem(Hidden('language', lang))
76 form.AddItem(SubmitButton('submit', _('Submit Changes')))
77 doc.AddItem(form)
78
79
80
81
82-def ChangeHTML(mlist, cgi_info, template_name, doc):
83+def ChangeHTML(mlist, cgi_info, template_name, doc, lang=None):
84+ if lang not in mlist.GetAvailableLanguages():
85+ lang = mlist.preferred_language
86 if not cgi_info.has_key('html_code'):
87 doc.AddItem(Header(3,_("Can't have empty html page.")))
88 doc.AddItem(Header(3,_("HTML Unchanged.")))
89@@ -225,7 +252,7 @@
90 doc.AddItem(Header(3,_("Page Unchanged.")))
91 doc.AddItem('<hr>')
92 return
93- langdir = os.path.join(mlist.fullpath(), mlist.preferred_language)
94+ langdir = os.path.join(mlist.fullpath(), lang)
95 # Make sure the directory exists
96 omask = os.umask(0)
97 try:

Subscribers

People subscribed via source and target branches

to status/vote changes: