1
1
# -*- coding: iso-8859-1 -*-
3
MoinMoin - UserPreferences action
5
This is a simple plugin, that adds a "UserPreferences" action.
6
This action will display the UserPreferences page (or appropriate
7
page in the reader's language), so that the user can login, or
8
change his/her preferences.
10
However, as it is an action, the page that is displayed is not
11
changed. After submitting the form, the user is presented the
12
same page he/she was seeing before, and the trail is not modified.
14
@copyright: 2006 by Radomir Dopieralski
3
MoinMoin - user settings action
5
@copyright: 2006 Radomir Dopieralski
6
2007, 2008 MoinMoin:JohannesBerg
15
7
@license: GNU GPL, see COPYING for details.
18
from MoinMoin import wikiutil
10
from MoinMoin import Page, wikiutil
11
from MoinMoin.widget import html
13
def _handle_submission(request):
14
""" Handle GET and POST requests of preferences forms.
16
Return error msg_class, msg tuple or None, None.
19
sub = request.form.get('handler', [None])[0]
21
if sub in request.cfg.userprefs_disabled:
25
cls = wikiutil.importPlugin(request.cfg, 'userprefs', sub, 'Settings')
26
except wikiutil.PluginMissingError:
27
# we never show this plugin to click on so no need to
34
res = obj.handle_form()
35
if isinstance(res, tuple):
37
# backward compatibility for userprefs plugins,
38
# they just get 'dialog'-style messages.
41
def _create_prefs_page(request, sel=None):
43
plugins = wikiutil.getPlugins('userprefs', request.cfg)
45
ret.append(html.Text(_("Please choose:")))
50
if sub in request.cfg.userprefs_disabled:
52
cls = wikiutil.importPlugin(request.cfg, 'userprefs', sub, 'Settings')
56
url = request.page.url(request, {'action': 'userprefs', 'sub': sub})
57
lnk = html.LI().append(html.A(href=url).append(html.Text(obj.title)))
62
def _create_page(request, cancel=False):
63
# returns text, title, msg_class, msg
64
pagename = request.page.page_name
66
if 'handler' in request.form:
67
msg_class, msg = _handle_submission(request)
69
msg_class, msg = None, None
71
sub = request.form.get('sub', [''])[0]
73
if sub and sub not in request.cfg.userprefs_disabled:
75
cls = wikiutil.importPlugin(request.cfg, 'userprefs', sub, 'Settings')
76
except wikiutil.PluginMissingError:
80
obj = cls and cls(request)
82
if not obj or not obj.allowed():
83
return _create_prefs_page(request), None, msg_class, msg
85
return obj.create_form(), obj.title, msg_class, msg
20
88
def execute(pagename, request):
21
page = wikiutil.getSysPage(request, 'UserPreferences')
22
page.send_page(request)
90
if not request.user.valid:
91
actname = __name__.split('.')[-1]
92
request.theme.add_msg(_("You must login to use this action: %(action)s.") % {"action": actname}, "error")
93
return Page.Page(request, pagename).send_page()
95
text, title, msg_class, msg = _create_page(request)
97
# XXX: we would like to make "Settings" here a link back
98
# to the generic userprefs page but that is impossible
99
# due to the way the title is emitted and the theme is
100
# responsible for doing the linking....
101
title = _("Settings") + ":" + title
103
title = _("Settings")
104
request.emit_http_headers()
105
request.theme.add_msg(msg, msg_class)
106
request.theme.send_title(title, page=request.page, pagename=pagename)
107
# Start content (important for RTL support)
108
request.write(request.formatter.startContent("content"))
110
request.write(request.formatter.endContent())
111
request.theme.send_footer(pagename)
112
request.theme.send_closing_html()