annotate MoinMoin/action/userprefs.py @ 2967:a310264ad186

Added a few add_msg calls (by Federico Lorenzi).
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Mon, 24 Dec 2007 00:16:48 +0100
parents 2142eea37033
children a1322262398a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
511
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
2 """
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
3 MoinMoin - UserPreferences action
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
4
511
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
5 This is a simple plugin, that adds a "UserPreferences" action.
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
6
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1784
diff changeset
7 @copyright: 2006 Radomir Dopieralski
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
8 2007 MoinMoin:JohannesBerg
511
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
9 @license: GNU GPL, see COPYING for details.
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
10 """
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
11
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
12 from MoinMoin import wikiutil
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
13 from MoinMoin.Page import Page
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
14 from MoinMoin.widget import html
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
15
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
16 def _handle_submission(request):
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
17 """ Handle GET and POST requests of preferences forms.
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
18
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
19 Return error msg or None.
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
20 """
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
21 _ = request.getText
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
22 sub = request.form.get('handler', [None])[0]
2306
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
23
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
24 if sub in request.cfg.disabled_userprefs:
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
25 return None
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
26
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
27 try:
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
28 cls = wikiutil.importPlugin(request.cfg, 'userprefs', sub, 'Settings')
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
29 except wikiutil.PluginMissingError:
2306
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
30 # we never show this plugin to click on so no need to
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
31 # give a message here
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
32 return None
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
33
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
34 obj = cls(request)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
35 if not obj.allowed():
2306
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
36 return None
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
37 return obj.handle_form()
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
38
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
39 def _create_prefs_page(request, sel=None):
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
40 _ = request.getText
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
41 plugins = wikiutil.getPlugins('userprefs', request.cfg)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
42 ret = html.P()
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
43 ret.append(html.Text(_("Please choose:")))
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
44 ret.append(html.BR())
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
45 items = html.UL()
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
46 ret.append(items)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
47 for sub in plugins:
2306
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
48 if sub in request.cfg.disabled_userprefs:
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
49 continue
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
50 cls = wikiutil.importPlugin(request.cfg, 'userprefs', sub, 'Settings')
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
51 obj = cls(request)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
52 if not obj.allowed():
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
53 continue
2422
2142eea37033 fix userpreferences links
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2306
diff changeset
54 url = request.page.url(request, {'action': 'userprefs', 'sub': sub},
2142eea37033 fix userpreferences links
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2306
diff changeset
55 relative=False)
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
56 lnk = html.LI().append(html.A(href=url).append(html.Text(obj.title)))
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
57 items.append(lnk)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
58 return unicode(ret)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
59
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
60
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
61 def _create_page(request, cancel=False):
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
62 # returns text, title, msg
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
63 pagename = request.page.page_name
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
64
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
65 if 'handler' in request.form:
2296
f22518801de4 allow wizard-like userprefs (and document how to achieve that)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2294
diff changeset
66 msg = _handle_submission(request)
f22518801de4 allow wizard-like userprefs (and document how to achieve that)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2294
diff changeset
67 else:
f22518801de4 allow wizard-like userprefs (and document how to achieve that)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2294
diff changeset
68 msg = None
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
69
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
70 sub = request.form.get('sub', [''])[0]
2305
5c75990712ca make sure userprefs plugins that say not allowed() will never be invoked
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2296
diff changeset
71 cls = None
2306
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
72 if sub and not sub in request.cfg.disabled_userprefs:
2305
5c75990712ca make sure userprefs plugins that say not allowed() will never be invoked
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2296
diff changeset
73 try:
5c75990712ca make sure userprefs plugins that say not allowed() will never be invoked
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2296
diff changeset
74 cls = wikiutil.importPlugin(request.cfg, 'userprefs', sub, 'Settings')
5c75990712ca make sure userprefs plugins that say not allowed() will never be invoked
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2296
diff changeset
75 except wikiutil.PluginMissingError:
5c75990712ca make sure userprefs plugins that say not allowed() will never be invoked
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2296
diff changeset
76 # cls is already None
5c75990712ca make sure userprefs plugins that say not allowed() will never be invoked
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2296
diff changeset
77 pass
5c75990712ca make sure userprefs plugins that say not allowed() will never be invoked
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2296
diff changeset
78
5c75990712ca make sure userprefs plugins that say not allowed() will never be invoked
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2296
diff changeset
79 obj = cls and cls(request)
5c75990712ca make sure userprefs plugins that say not allowed() will never be invoked
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2296
diff changeset
80
5c75990712ca make sure userprefs plugins that say not allowed() will never be invoked
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2296
diff changeset
81 if not obj or not obj.allowed():
2296
f22518801de4 allow wizard-like userprefs (and document how to achieve that)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2294
diff changeset
82 return _create_prefs_page(request), None, msg
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
83
2296
f22518801de4 allow wizard-like userprefs (and document how to achieve that)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2294
diff changeset
84 return obj.create_form(), obj.title, msg
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
85
511
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
86
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
87 def execute(pagename, request):
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
88 _ = request.getText
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
89 text, title, msg = _create_page(request)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
90 if not title:
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
91 title = _("Settings", formatted=False)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
92 else:
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
93 lnk = html.A(href='xx').append(html.Text(_("Settings", formatted=False)))
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
94 lnk = unicode(lnk)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
95 title = _("Settings") + "/" + title
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
96 request.emit_http_headers()
2967
a310264ad186 Added a few add_msg calls (by Federico Lorenzi).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2422
diff changeset
97 request.theme.add_msg(msg, "dialog")
a310264ad186 Added a few add_msg calls (by Federico Lorenzi).
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 2422
diff changeset
98 request.theme.send_title(title, page=request.page, pagename=pagename)
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
99 # Start content (important for RTL support)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
100 request.write(request.formatter.startContent("content"))
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
101 request.write(text)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
102 request.write(request.formatter.endContent())
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
103 request.theme.send_footer(pagename)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
104 request.theme.send_closing_html()