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
=== modified file 'Mailman/Cgi/edithtml.py'
--- Mailman/Cgi/edithtml.py 2018-06-17 23:47:34 +0000
+++ Mailman/Cgi/edithtml.py 2018-07-08 22:09:07 +0000
@@ -138,6 +138,13 @@
138 Auth.loginpage(mlist, 'admin', msg=msg)138 Auth.loginpage(mlist, 'admin', msg=msg)
139 return139 return
140140
141 # See if the user want to see this page in other language
142 language = cgidata.getfirst('language', '')
143 if language not in mlist.GetAvailableLanguages():
144 language = mlist.preferred_language
145 i18n.set_language(language)
146 doc.set_language(language)
147
141 realname = mlist.real_name148 realname = mlist.real_name
142 if len(parts) > 1:149 if len(parts) > 1:
143 template_name = parts[1]150 template_name = parts[1]
@@ -169,42 +176,62 @@
169 return176 return
170177
171 try:178 try:
172 if cgidata.keys():179 if cgidata.keys() and not cgidata.has_key('langform'):
173 if csrf_checked:180 if csrf_checked:
174 ChangeHTML(mlist, cgidata, template_name, doc)181 ChangeHTML(mlist, cgidata, template_name, doc, lang=language)
175 else:182 else:
176 doc.addError(183 doc.addError(
177 _('The form lifetime has expired. (request forgery check)'))184 _('The form lifetime has expired. (request forgery check)'))
178 FormatHTML(mlist, doc, template_name, template_info)185 FormatHTML(mlist, doc, template_name, template_info, lang=language)
179 finally:186 finally:
180 doc.AddItem(mlist.GetMailmanFooter())187 doc.AddItem(mlist.GetMailmanFooter())
181 print doc.Format()188 print doc.Format()
182189
183190
184191
185192
186def FormatHTML(mlist, doc, template_name, template_info):193def FormatHTML(mlist, doc, template_name, template_info, lang=None):
194 if lang not in mlist.GetAvailableLanguages():
195 lang = mlist.preferred_language
196 lcset = Utils.GetCharSet(lang)
187 doc.AddItem(Header(1,'%s:' % mlist.real_name))197 doc.AddItem(Header(1,'%s:' % mlist.real_name))
188 doc.AddItem(Header(1, template_info))198 doc.AddItem(Header(1, template_info))
189 doc.AddItem('<hr>')199 doc.AddItem('<hr>')
190200
191 link = Link(mlist.GetScriptURL('admin'),201 link = Link(mlist.GetScriptURL('admin'),
192 _('View or edit the list configuration information.'))202 _('View or edit the list configuration information.'))
203 backlink = Link(mlist.GetScriptURL('edithtml'),
204 _('Edit the public HTML pages and text files'))
193205
194 doc.AddItem(FontSize("+1", link))206 doc.AddItem(FontSize("+1", link))
207 doc.AddItem(FontSize("+1", backlink))
195 doc.AddItem('<p>')208 doc.AddItem('<p>')
196 doc.AddItem('<hr>')209 doc.AddItem('<hr>')
210 if len(mlist.GetAvailableLanguages()) > 1:
211 langform = Form(mlist.GetScriptURL('edithtml') + '/' + template_name,
212 mlist=mlist, contexts=AUTH_CONTEXTS)
213 langform.AddItem(
214 mlist.FormatButton('editlang-button',
215 text = _("Edit this template for")))
216 langform.AddItem(mlist.GetLangSelectBox(lang))
217 langform.AddItem(Hidden('langform', 'True'))
218 doc.AddItem(langform)
219 doc.AddItem('<hr>')
197 form = Form(mlist.GetScriptURL('edithtml') + '/' + template_name,220 form = Form(mlist.GetScriptURL('edithtml') + '/' + template_name,
198 mlist=mlist, contexts=AUTH_CONTEXTS)221 mlist=mlist, contexts=AUTH_CONTEXTS)
199 text = Utils.maketext(template_name, raw=1, mlist=mlist)222 text = Utils.maketext(template_name, raw=1, lang=lang, mlist=mlist)
200 # MAS: Don't websafe twice. TextArea does it.223 # MAS: Don't websafe twice. TextArea does it.
201 form.AddItem(TextArea('html_code', text, rows=40, cols=75))224 form.AddItem(TextArea('html_code', text, rows=40, cols=75))
202 form.AddItem('<p>' + _('When you are done making changes...'))225 form.AddItem('<p>' + _('When you are done making changes...'))
226 if lang != mlist.preferred_language:
227 form.AddItem(Hidden('language', lang))
203 form.AddItem(SubmitButton('submit', _('Submit Changes')))228 form.AddItem(SubmitButton('submit', _('Submit Changes')))
204 doc.AddItem(form)229 doc.AddItem(form)
205230
206231
207232
208233
209def ChangeHTML(mlist, cgi_info, template_name, doc):234def ChangeHTML(mlist, cgi_info, template_name, doc, lang=None):
235 if lang not in mlist.GetAvailableLanguages():
236 lang = mlist.preferred_language
210 if not cgi_info.has_key('html_code'):237 if not cgi_info.has_key('html_code'):
211 doc.AddItem(Header(3,_("Can't have empty html page.")))238 doc.AddItem(Header(3,_("Can't have empty html page.")))
212 doc.AddItem(Header(3,_("HTML Unchanged.")))239 doc.AddItem(Header(3,_("HTML Unchanged.")))
@@ -225,7 +252,7 @@
225 doc.AddItem(Header(3,_("Page Unchanged.")))252 doc.AddItem(Header(3,_("Page Unchanged.")))
226 doc.AddItem('<hr>')253 doc.AddItem('<hr>')
227 return254 return
228 langdir = os.path.join(mlist.fullpath(), mlist.preferred_language)255 langdir = os.path.join(mlist.fullpath(), lang)
229 # Make sure the directory exists256 # Make sure the directory exists
230 omask = os.umask(0)257 omask = os.umask(0)
231 try:258 try:

Subscribers

People subscribed via source and target branches

to status/vote changes: