annotate MoinMoin/action/userprefs.py @ 3333:928a45b60bb3

remove remaining mentions of "UserPreferences", add to CHANGES
author Johannes Berg <johannes AT sipsolutions DOT net>
date Wed, 19 Mar 2008 12:45:14 +0100
parents 6ed28a1edfe0
children b0a794176dc4
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 """
3333
928a45b60bb3 remove remaining mentions of "UserPreferences", add to CHANGES
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3329
diff changeset
3 MoinMoin - user settings action
511
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
4
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
5 @copyright: 2006 Radomir Dopieralski
3333
928a45b60bb3 remove remaining mentions of "UserPreferences", add to CHANGES
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3329
diff changeset
6 2007, 2008 MoinMoin:JohannesBerg
511
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
7 @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
8 """
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
9
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
10 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
11 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
12
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
13 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
14 """ 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
15
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
16 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
17 """
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
18 _ = request.getText
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
19 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
20
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
21 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
22 return None
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
23
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
24 try:
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
25 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
26 except wikiutil.PluginMissingError:
2306
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
27 # 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
28 # give a message here
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
29 return None
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
30
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
31 obj = cls(request)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
32 if not obj.allowed():
2306
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
33 return None
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
34 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
35
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
36 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
37 _ = request.getText
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
38 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
39 ret = html.P()
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
40 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
41 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
42 items = html.UL()
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
43 ret.append(items)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
44 for sub in plugins:
2306
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
45 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
46 continue
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
47 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
48 obj = cls(request)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
49 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
50 continue
3234
a739558ca3dc Page.url() default changed to relative=False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3175
diff changeset
51 url = request.page.url(request, {'action': 'userprefs', 'sub': sub})
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
52 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
53 items.append(lnk)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
54 return unicode(ret)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
55
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
56
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
57 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
58 # 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
59 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
60
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
61 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
62 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
63 else:
f22518801de4 allow wizard-like userprefs (and document how to achieve that)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2294
diff changeset
64 msg = None
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
65
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
66 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
67 cls = None
2306
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
68 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
69 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
70 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
71 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
72 # 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
73 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
74
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 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
76
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 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
78 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
79
2296
f22518801de4 allow wizard-like userprefs (and document how to achieve that)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2294
diff changeset
80 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
81
511
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
82
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
83 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
84 _ = request.getText
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
85 text, title, msg = _create_page(request)
3328
86b4a7ac35e6 userprefs action: clean up title code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3234
diff changeset
86 if title:
86b4a7ac35e6 userprefs action: clean up title code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3234
diff changeset
87 # XXX: we would like to make "Settings" here a link back
86b4a7ac35e6 userprefs action: clean up title code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3234
diff changeset
88 # to the generic userprefs page but that is impossible
86b4a7ac35e6 userprefs action: clean up title code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3234
diff changeset
89 # due to the way the title is emitted and the theme is
86b4a7ac35e6 userprefs action: clean up title code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3234
diff changeset
90 # responsible for doing the linking....
3329
6ed28a1edfe0 use colon instead of slash for settings title (to make it less confusing with real pages)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3328
diff changeset
91 title = _("Settings") + ":" + title
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
92 else:
3328
86b4a7ac35e6 userprefs action: clean up title code
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3234
diff changeset
93 title = _("Settings")
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
94 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
95 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
96 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
97 # 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
98 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
99 request.write(text)
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.endContent())
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
101 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
102 request.theme.send_closing_html()