annotate MoinMoin/action/userprefs.py @ 3175:2a3a6cb34e45

pylint findings: fix some harmless stuff
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 03 Mar 2008 02:02:55 +0100
parents a1322262398a
children a739558ca3dc
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.widget import html
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
14
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
15 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
16 """ 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
17
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
18 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
19 """
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
20 _ = request.getText
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
21 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
22
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
23 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
24 return None
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
25
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
26 try:
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
27 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
28 except wikiutil.PluginMissingError:
2306
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
29 # 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
30 # give a message here
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
31 return None
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
32
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
33 obj = cls(request)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
34 if not obj.allowed():
2306
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
35 return None
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
36 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
37
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
38 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
39 _ = request.getText
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
40 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
41 ret = html.P()
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
42 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
43 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
44 items = html.UL()
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
45 ret.append(items)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
46 for sub in plugins:
2306
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
47 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
48 continue
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
49 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
50 obj = cls(request)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
51 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
52 continue
2422
2142eea37033 fix userpreferences links
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2306
diff changeset
53 url = request.page.url(request, {'action': 'userprefs', 'sub': sub},
2142eea37033 fix userpreferences links
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2306
diff changeset
54 relative=False)
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
55 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
56 items.append(lnk)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
57 return unicode(ret)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
58
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 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
61 # 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
62 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
63
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
64 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
65 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
66 else:
f22518801de4 allow wizard-like userprefs (and document how to achieve that)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2294
diff changeset
67 msg = None
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
68
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
69 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
70 cls = None
2306
5cf429e40f18 allow disabling certain userprefs plugins from config
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2305
diff changeset
71 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
72 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
73 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
74 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
75 # 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
76 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
77
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 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
79
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 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
81 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
82
2296
f22518801de4 allow wizard-like userprefs (and document how to achieve that)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2294
diff changeset
83 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
84
511
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
85
8ee8ced7dded moved UserPreferences back to header, add Cancel button
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
86 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
87 _ = request.getText
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
88 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
89 if not title:
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2967
diff changeset
90 title = _("Settings")
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
91 else:
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2967
diff changeset
92 lnk = html.A(href='xx').append(html.Text(_("Settings")))
2294
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
93 lnk = unicode(lnk)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
94 title = _("Settings") + "/" + title
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
95 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
96 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
97 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
98 # 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
99 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
100 request.write(text)
22749e92a461 new userprefs handling including plugins; todo: refactor prefs.py
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
101 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
102 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
103 request.theme.send_closing_html()