~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/action/userprefs.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: iso-8859-1 -*-
2
2
"""
3
 
    MoinMoin - UserPreferences action
4
 
    
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.
9
 
 
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.
13
 
 
14
 
    @copyright: 2006 by Radomir Dopieralski
 
3
    MoinMoin - user settings action
 
4
 
 
5
    @copyright: 2006 Radomir Dopieralski
 
6
                2007, 2008 MoinMoin:JohannesBerg
15
7
    @license: GNU GPL, see COPYING for details.
16
8
"""
17
9
 
18
 
from MoinMoin import wikiutil
 
10
from MoinMoin import Page, wikiutil
 
11
from MoinMoin.widget import html
 
12
 
 
13
def _handle_submission(request):
 
14
    """ Handle GET and POST requests of preferences forms.
 
15
 
 
16
    Return error msg_class, msg tuple or None, None.
 
17
    """
 
18
    _ = request.getText
 
19
    sub = request.form.get('handler', [None])[0]
 
20
 
 
21
    if sub in request.cfg.userprefs_disabled:
 
22
        return None, None
 
23
 
 
24
    try:
 
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
 
28
        # give a message here
 
29
        return None, None
 
30
 
 
31
    obj = cls(request)
 
32
    if not obj.allowed():
 
33
        return None, None
 
34
    res = obj.handle_form()
 
35
    if isinstance(res, tuple):
 
36
        return res
 
37
    # backward compatibility for userprefs plugins,
 
38
    # they just get 'dialog'-style messages.
 
39
    return None, res
 
40
 
 
41
def _create_prefs_page(request, sel=None):
 
42
    _ = request.getText
 
43
    plugins = wikiutil.getPlugins('userprefs', request.cfg)
 
44
    ret = html.P()
 
45
    ret.append(html.Text(_("Please choose:")))
 
46
    ret.append(html.BR())
 
47
    items = html.UL()
 
48
    ret.append(items)
 
49
    for sub in plugins:
 
50
        if sub in request.cfg.userprefs_disabled:
 
51
            continue
 
52
        cls = wikiutil.importPlugin(request.cfg, 'userprefs', sub, 'Settings')
 
53
        obj = cls(request)
 
54
        if not obj.allowed():
 
55
            continue
 
56
        url = request.page.url(request, {'action': 'userprefs', 'sub': sub})
 
57
        lnk = html.LI().append(html.A(href=url).append(html.Text(obj.title)))
 
58
        items.append(lnk)
 
59
    return unicode(ret)
 
60
 
 
61
 
 
62
def _create_page(request, cancel=False):
 
63
    # returns text, title, msg_class, msg
 
64
    pagename = request.page.page_name
 
65
 
 
66
    if 'handler' in request.form:
 
67
        msg_class, msg = _handle_submission(request)
 
68
    else:
 
69
        msg_class, msg = None, None
 
70
 
 
71
    sub = request.form.get('sub', [''])[0]
 
72
    cls = None
 
73
    if sub and sub not in request.cfg.userprefs_disabled:
 
74
        try:
 
75
            cls = wikiutil.importPlugin(request.cfg, 'userprefs', sub, 'Settings')
 
76
        except wikiutil.PluginMissingError:
 
77
            # cls is already None
 
78
            pass
 
79
 
 
80
    obj = cls and cls(request)
 
81
 
 
82
    if not obj or not obj.allowed():
 
83
        return _create_prefs_page(request), None, msg_class, msg
 
84
 
 
85
    return obj.create_form(), obj.title, msg_class, msg
 
86
 
19
87
 
20
88
def execute(pagename, request):
21
 
    page = wikiutil.getSysPage(request, 'UserPreferences')
22
 
    page.send_page(request)
 
89
    _ = request.getText
 
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()
23
94
 
 
95
    text, title, msg_class, msg = _create_page(request)
 
96
    if title:
 
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
 
102
    else:
 
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"))
 
109
    request.write(text)
 
110
    request.write(request.formatter.endContent())
 
111
    request.theme.send_footer(pagename)
 
112
    request.theme.send_closing_html()