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

« back to all changes in this revision

Viewing changes to MoinMoin/macro/WikiConfig.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: iso-8859-1 -*-
2
 
"""
3
 
    MoinMoin - Wiki Configuration
4
 
"""
5
 
from MoinMoin.config import multiconfig
6
 
 
7
 
Dependencies = ['user'] # table headings are translated to user language
8
 
generates_headings = True
9
 
 
10
 
def macro_WikiConfig(macro):
11
 
    request = macro.request
12
 
    _ = request.getText
13
 
    f = macro.request.formatter
14
 
    ret = []
15
 
 
16
 
    if not request.user or not request.user.isSuperUser():
17
 
        return ''
18
 
 
19
 
    settings = {}
20
 
    for groupname in multiconfig.options:
21
 
        heading, desc, opts = multiconfig.options[groupname]
22
 
        for name, default, description in opts:
23
 
            name = groupname + '_' + name
24
 
            if isinstance(default, multiconfig.DefaultExpression):
25
 
                default = default.value
26
 
            settings[name] = default
27
 
    for groupname in multiconfig.options_no_group_name:
28
 
        heading, desc, opts = multiconfig.options_no_group_name[groupname]
29
 
        for name, default, description in opts:
30
 
            if isinstance(default, multiconfig.DefaultExpression):
31
 
                default = default.value
32
 
            settings[name] = default
33
 
 
34
 
    ret.extend([
35
 
        f.heading(1, 1, id='current_config'),
36
 
        f.text(_("Wiki configuration")),
37
 
        f.heading(0, 1),
38
 
        f.paragraph(1),
39
 
        _("This table shows all settings in this wiki that do not have default values. "
40
 
          "Settings that the configuration system doesn't know about are shown in ''italic'', "
41
 
          "those may be due to third-party extensions needing configuration or settings that "
42
 
          "were removed from Moin.",
43
 
          wiki=True),
44
 
        f.paragraph(0),
45
 
    ])
46
 
    ret.extend([
47
 
        f.table(1),
48
 
        f.table_row(1),
49
 
        f.table_cell(1), f.strong(1), f.text(_('Variable name')), f.strong(0), f.table_cell(0),
50
 
        f.table_cell(1), f.strong(1), f.text(_('Setting')), f.strong(0), f.table_cell(0),
51
 
        f.table_row(0),
52
 
    ])
53
 
 
54
 
    def iter_vnames(cfg):
55
 
        dedup = {}
56
 
        for name in cfg.__dict__:
57
 
            dedup[name] = True
58
 
            yield name, cfg.__dict__[name]
59
 
        for cls in cfg.__class__.mro():
60
 
            if cls == multiconfig.ConfigFunctionality:
61
 
                break
62
 
            for name in cls.__dict__:
63
 
                if not name in dedup:
64
 
                    dedup[name] = True
65
 
                    yield name, cls.__dict__[name]
66
 
 
67
 
    found = []
68
 
    for vname, value in iter_vnames(request.cfg):
69
 
        if hasattr(multiconfig.ConfigFunctionality, vname):
70
 
            continue
71
 
        if vname in settings and settings[vname] == value:
72
 
            continue
73
 
        found.append((vname, value))
74
 
    found.sort()
75
 
    for vname, value in found:
76
 
        vname = f.text(vname)
77
 
        if not vname in settings:
78
 
            vname = f.emphasis(1) + vname + f.emphasis(0)
79
 
        vtxt = '%r' % (value, )
80
 
        ret.extend([
81
 
            f.table_row(1),
82
 
            f.table_cell(1), vname, f.table_cell(0),
83
 
            f.table_cell(1), f.code(1, css="backtick"), f.text(vtxt), f.code(0), f.table_cell(0),
84
 
            f.table_row(0),
85
 
        ])
86
 
    ret.append(f.table(0))
87
 
 
88
 
    return ''.join(ret)