annotate MoinMoin/apps/admin/views.py @ 2011:791bdedb0c20

fix lots of pep8 issues, mainly E12x
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 18 Feb 2013 00:46:53 +0100
parents bb2f526d961c
children 3e8c910f66f8
rev   line source
92
5ff01f07c67c admin/interwikihelp view (replaces InterWiki macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 91
diff changeset
1 # Copyright: 2007-2011 MoinMoin:ThomasWaldmann
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
2 # Copyright: 2001-2003 Juergen Hermann <jh@web.de>
54
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
3 # Copyright: 2008 MoinMoin:JohannesBerg
91
2e0766600e8f admin/highlighterhelp view (replaces HighlighterList macro), added table macro to utils.html template
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 55
diff changeset
4 # Copyright: 2009 MoinMoin:EugeneSyromyatnikov
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
5 # Copyright: 2010 MoinMoin:DiogenesAugusto
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
6 # Copyright: 2010 MoinMoin:ReimarBauer
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
7 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
8
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 """
54
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
10 MoinMoin - admin views
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11
54
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
12 This shows the user interface for wiki admins.
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
13 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14
186
5dd1db45ed55 implement require_permission decorator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 185
diff changeset
15 from flask import request, url_for, flash, redirect
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 from flask import current_app as app
109
e4c332436733 remove flask monkeypatch, use 'from flask import g as flaskg'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 107
diff changeset
17 from flask import g as flaskg
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19 from MoinMoin.i18n import _, L_, N_
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20 from MoinMoin.themes import render_template
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 from MoinMoin.apps.admin import admin
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22 from MoinMoin import user
1973
286e315935ae refactor usage of constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
23 from MoinMoin.constants.keys import NAME, ITEMID, SIZE, EMAIL
286e315935ae refactor usage of constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
24 from MoinMoin.constants.rights import SUPERUSER
186
5dd1db45ed55 implement require_permission decorator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 185
diff changeset
25 from MoinMoin.security import require_permission
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
27
1520
a9f837dee2d7 More splitted to Admin and User
Jaiditya Mathur <jaiditya.mathur@gmail.com>
parents: 1505
diff changeset
28 @admin.route('/superuser')
1720
ea19b98d4f94 Admin menu lock for non-admin users
Jaiditya Mathur <jaiditya.mathur@gmail.com>
parents: 1717
diff changeset
29 @require_permission(SUPERUSER)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30 def index():
1006
b65a998fab8e fixes #61 using title_name instead of item_name for pages without an item
Bruno Gola <brunogola@gmail.com>
parents: 997
diff changeset
31 return render_template('admin/index.html', title_name=_(u"Admin"))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
33
1606
e64047b16c4c Fix view.py error
Jaiditya Mathur <jaiditya.mathur@gmail.com>
parents: 1527
diff changeset
34 @admin.route('/user')
1520
a9f837dee2d7 More splitted to Admin and User
Jaiditya Mathur <jaiditya.mathur@gmail.com>
parents: 1505
diff changeset
35 def index_user():
a9f837dee2d7 More splitted to Admin and User
Jaiditya Mathur <jaiditya.mathur@gmail.com>
parents: 1505
diff changeset
36 return render_template('user/index_user.html', title_name=_(u"User"))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39 @admin.route('/userbrowser')
1717
7b7ec9dccf34 reverted changeset 6cd9347f7cc5
Jaiditya Mathur <jaiditya.mathur@gmail.com>
parents: 1705
diff changeset
40 @require_permission(SUPERUSER)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41 def userbrowser():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 User Account Browser
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45 groups = flaskg.groups
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
46 revs = user.search_users() # all users
1116
d56ce46d3e16 fix userbrowser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1006
diff changeset
47 user_accounts = [dict(uid=rev.meta[ITEMID],
d56ce46d3e16 fix userbrowser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1006
diff changeset
48 name=rev.meta[NAME],
1610
4374108a1189 userbrowser: add data for email field, fixes #227
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1606
diff changeset
49 email=rev.meta[EMAIL],
838
ff63eb0afd24 user browser: use whoosh index
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 799
diff changeset
50 disabled=False, # TODO: add to index
1116
d56ce46d3e16 fix userbrowser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1006
diff changeset
51 groups=[groupname for groupname in groups if rev.meta[NAME] in groups[groupname]],
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
52 ) for rev in revs]
1907
7324a1d71443 simplify and standardize headings and page titles on user and admin pages
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1720
diff changeset
53 return render_template('admin/userbrowser.html', user_accounts=user_accounts, title_name=_(u"Users"))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
55
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
56 @admin.route('/userprofile/<user_name>', methods=['GET', 'POST', ])
1717
7b7ec9dccf34 reverted changeset 6cd9347f7cc5
Jaiditya Mathur <jaiditya.mathur@gmail.com>
parents: 1705
diff changeset
57 @require_permission(SUPERUSER)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
58 def userprofile(user_name):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
59 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
60 Set values in user profile
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61 """
839
cc23787a37d0 use search_users() or User() instead of specialized lookup functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 838
diff changeset
62 u = user.User(auth_username=user_name)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
63 if request.method == 'GET':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
64 return _(u"User profile of %(username)s: %(email)r", username=user_name,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65 email=(u.email, u.disabled))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
67 if request.method == 'POST':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
68 key = request.form.get('key', '')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69 val = request.form.get('val', '')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
70 ok = False
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71 if hasattr(u, key):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
72 ok = True
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
73 oldval = getattr(u, key)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
74 if isinstance(oldval, bool):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
75 val = bool(val)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
76 elif isinstance(oldval, int):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
77 val = int(val)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78 elif isinstance(oldval, unicode):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
79 val = unicode(val)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
80 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
81 ok = False
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82 if ok:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83 setattr(u, key, val)
839
cc23787a37d0 use search_users() or User() instead of specialized lookup functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 838
diff changeset
84 u.save()
1414
614005b5edb3 fixed some .format() unicode issues, partially fixing bug #124
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1397
diff changeset
85 flash(u'{0}.{1}: {2} -> {3}'.format(user_name, key, unicode(oldval), unicode(val), ), "info")
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
86 else:
1414
614005b5edb3 fixed some .format() unicode issues, partially fixing bug #124
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1397
diff changeset
87 flash(u'modifying {0}.{1} failed'.format(user_name, key, ), "error")
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 186
diff changeset
88 return redirect(url_for('.userbrowser'))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
90
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
91 @admin.route('/mail_recovery_token', methods=['GET', 'POST', ])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92 def mail_recovery_token():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94 Send user an email so he can reset his password.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 flash("mail recovery token not implemented yet")
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 186
diff changeset
97 return redirect(url_for('.userbrowser'))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100 @admin.route('/sysitems_upgrade', methods=['GET', 'POST', ])
186
5dd1db45ed55 implement require_permission decorator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 185
diff changeset
101 @require_permission(SUPERUSER)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
102 def sysitems_upgrade():
1983
bb2f526d961c fix some stuff discovered by pycharm code inspection
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
103 from MoinMoin.storage.backends import upgrade_sysitems # XXX broken import, either fix or kill this
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104 from MoinMoin.storage.error import BackendError
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105 if request.method == 'GET':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
106 action = 'syspages_upgrade'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107 label = 'Upgrade System Pages'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
108 return render_template('admin/sysitems_upgrade.html',
1006
b65a998fab8e fixes #61 using title_name instead of item_name for pages without an item
Bruno Gola <brunogola@gmail.com>
parents: 997
diff changeset
109 title_name=_(u"System items upgrade"))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
110 if request.method == 'POST':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
111 xmlfile = request.files.get('xmlfile')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113 upgrade_sysitems(xmlfile)
135
75312c9b94e3 use except...as syntax, use raise Exception(...) syntax, fix some imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 109
diff changeset
114 except BackendError as e:
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
115 flash(_('System items upgrade failed due to the following error: %(error)s.', error=e), 'error')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117 flash(_('System items have been upgraded successfully!'))
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 186
diff changeset
118 return redirect(url_for('.index'))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
119
54
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
120
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
121 from MoinMoin.config import default as defaultconfig
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
122
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
123
54
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
124 @admin.route('/wikiconfig', methods=['GET', ])
1717
7b7ec9dccf34 reverted changeset 6cd9347f7cc5
Jaiditya Mathur <jaiditya.mathur@gmail.com>
parents: 1705
diff changeset
125 @require_permission(SUPERUSER)
54
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
126 def wikiconfig():
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
127 settings = {}
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
128 for groupname in defaultconfig.options:
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
129 heading, desc, opts = defaultconfig.options[groupname]
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
130 for name, default, description in opts:
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
131 name = groupname + '_' + name
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
132 if isinstance(default, defaultconfig.DefaultExpression):
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
133 default = default.value
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
134 settings[name] = default
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
135 for groupname in defaultconfig.options_no_group_name:
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
136 heading, desc, opts = defaultconfig.options_no_group_name[groupname]
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
137 for name, default, description in opts:
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
138 if isinstance(default, defaultconfig.DefaultExpression):
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
139 default = default.value
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
140 settings[name] = default
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
141
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
142 def iter_vnames(cfg):
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
143 dedup = {}
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
144 for name in cfg.__dict__:
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
145 dedup[name] = True
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
146 yield name, cfg.__dict__[name]
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
147 for cls in cfg.__class__.mro():
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
148 if cls == defaultconfig.ConfigFunctionality:
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
149 break
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
150 for name in cls.__dict__:
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
151 if not name in dedup:
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
152 dedup[name] = True
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
153 yield name, cls.__dict__[name]
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
154
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
155 found = []
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
156 for vname, value in iter_vnames(app.cfg):
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
157 if hasattr(defaultconfig.ConfigFunctionality, vname):
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
158 continue
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
159 if vname in settings and settings[vname] == value:
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
160 continue
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
161 found.append((vname, value))
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
162
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
163 found.sort()
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
164 return render_template('admin/wikiconfig.html',
1907
7324a1d71443 simplify and standardize headings and page titles on user and admin pages
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1720
diff changeset
165 title_name=_(u"Show Wiki Configuration"),
54
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
166 found=found, settings=settings)
2d6a32f75c2d WikiConfig: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
167
55
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
168
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
169 @admin.route('/wikiconfighelp', methods=['GET', ])
1717
7b7ec9dccf34 reverted changeset 6cd9347f7cc5
Jaiditya Mathur <jaiditya.mathur@gmail.com>
parents: 1705
diff changeset
170 @require_permission(SUPERUSER)
55
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
171 def wikiconfighelp():
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
172 def format_default(default):
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
173 if isinstance(default, defaultconfig.DefaultExpression):
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
174 default_txt = default.text
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
175 else:
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 953
diff changeset
176 default_txt = repr(default)
55
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
177 if len(default_txt) > 30:
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
178 default_txt = '...'
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
179 return default_txt
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
180
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
181 groups = []
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
182 for groupname in defaultconfig.options:
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
183 heading, desc, opts = defaultconfig.options[groupname]
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
184 opts = sorted([(groupname + '_' + name, format_default(default), description)
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
185 for name, default, description in opts])
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
186 groups.append((heading, desc, opts))
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
187 for groupname in defaultconfig.options_no_group_name:
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
188 heading, desc, opts = defaultconfig.options_no_group_name[groupname]
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
189 opts = sorted([(name, format_default(default), description)
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
190 for name, default, description in opts])
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
191 groups.append((heading, desc, opts))
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
192 groups.sort()
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
193 return render_template('admin/wikiconfighelp.html',
1006
b65a998fab8e fixes #61 using title_name instead of item_name for pages without an item
Bruno Gola <brunogola@gmail.com>
parents: 997
diff changeset
194 title_name=_(u"Wiki Configuration Help"),
55
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
195 groups=groups)
32b88d45d63c WikiConfigHelp: remove macro, create admin view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 54
diff changeset
196
91
2e0766600e8f admin/highlighterhelp view (replaces HighlighterList macro), added table macro to utils.html template
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 55
diff changeset
197
2e0766600e8f admin/highlighterhelp view (replaces HighlighterList macro), added table macro to utils.html template
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 55
diff changeset
198 @admin.route('/highlighterhelp', methods=['GET', ])
2e0766600e8f admin/highlighterhelp view (replaces HighlighterList macro), added table macro to utils.html template
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 55
diff changeset
199 def highlighterhelp():
2e0766600e8f admin/highlighterhelp view (replaces HighlighterList macro), added table macro to utils.html template
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 55
diff changeset
200 """display a table with list of available Pygments lexers"""
2e0766600e8f admin/highlighterhelp view (replaces HighlighterList macro), added table macro to utils.html template
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 55
diff changeset
201 import pygments.lexers
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
202 headings = [
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
203 _('Lexer description'),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
204 _('Lexer names'),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
205 _('File patterns'),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
206 _('Mimetypes'),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
207 ]
91
2e0766600e8f admin/highlighterhelp view (replaces HighlighterList macro), added table macro to utils.html template
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 55
diff changeset
208 lexers = pygments.lexers.get_all_lexers()
2e0766600e8f admin/highlighterhelp view (replaces HighlighterList macro), added table macro to utils.html template
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 55
diff changeset
209 rows = sorted([[desc, ' '.join(names), ' '.join(patterns), ' '.join(mimetypes), ]
2e0766600e8f admin/highlighterhelp view (replaces HighlighterList macro), added table macro to utils.html template
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 55
diff changeset
210 for desc, names, patterns, mimetypes in lexers])
1520
a9f837dee2d7 More splitted to Admin and User
Jaiditya Mathur <jaiditya.mathur@gmail.com>
parents: 1505
diff changeset
211 return render_template('user/highlighterhelp.html',
1907
7324a1d71443 simplify and standardize headings and page titles on user and admin pages
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1720
diff changeset
212 title_name=_(u"Highlighters"),
91
2e0766600e8f admin/highlighterhelp view (replaces HighlighterList macro), added table macro to utils.html template
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 55
diff changeset
213 headings=headings,
2e0766600e8f admin/highlighterhelp view (replaces HighlighterList macro), added table macro to utils.html template
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 55
diff changeset
214 rows=rows)
2e0766600e8f admin/highlighterhelp view (replaces HighlighterList macro), added table macro to utils.html template
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 55
diff changeset
215
94
990fdbe2d52c admin/itemsize view (replaces PageSize macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 92
diff changeset
216
92
5ff01f07c67c admin/interwikihelp view (replaces InterWiki macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 91
diff changeset
217 @admin.route('/interwikihelp', methods=['GET', ])
5ff01f07c67c admin/interwikihelp view (replaces InterWiki macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 91
diff changeset
218 def interwikihelp():
5ff01f07c67c admin/interwikihelp view (replaces InterWiki macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 91
diff changeset
219 """display a table with list of known interwiki names / urls"""
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
220 headings = [
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
221 _('InterWiki name'),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
222 _('URL'),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
223 ]
92
5ff01f07c67c admin/interwikihelp view (replaces InterWiki macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 91
diff changeset
224 rows = sorted(app.cfg.interwiki_map.items())
1520
a9f837dee2d7 More splitted to Admin and User
Jaiditya Mathur <jaiditya.mathur@gmail.com>
parents: 1505
diff changeset
225 return render_template('user/interwikihelp.html',
1907
7324a1d71443 simplify and standardize headings and page titles on user and admin pages
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1720
diff changeset
226 title_name=_(u"Interwiki Names"),
92
5ff01f07c67c admin/interwikihelp view (replaces InterWiki macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 91
diff changeset
227 headings=headings,
5ff01f07c67c admin/interwikihelp view (replaces InterWiki macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 91
diff changeset
228 rows=rows)
5ff01f07c67c admin/interwikihelp view (replaces InterWiki macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 91
diff changeset
229
94
990fdbe2d52c admin/itemsize view (replaces PageSize macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 92
diff changeset
230
990fdbe2d52c admin/itemsize view (replaces PageSize macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 92
diff changeset
231 @admin.route('/itemsize', methods=['GET', ])
990fdbe2d52c admin/itemsize view (replaces PageSize macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 92
diff changeset
232 def itemsize():
990fdbe2d52c admin/itemsize view (replaces PageSize macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 92
diff changeset
233 """display a table with item sizes"""
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
234 headings = [
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
235 _('Size'),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
236 _('Item name'),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
237 ]
1039
b521a6667a54 access to Item's name through name property instead of meta directly.
Luis Henrique Fagundes <lhfagundes@gmail.com>
parents: 1006
diff changeset
238 rows = [(rev.meta[SIZE], rev.name)
997
3e912ed37167 fix item sizes view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 969
diff changeset
239 for rev in flaskg.storage.documents(wikiname=app.cfg.interwikiname)]
94
990fdbe2d52c admin/itemsize view (replaces PageSize macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 92
diff changeset
240 rows = sorted(rows, reverse=True)
1520
a9f837dee2d7 More splitted to Admin and User
Jaiditya Mathur <jaiditya.mathur@gmail.com>
parents: 1505
diff changeset
241 return render_template('user/itemsize.html',
1907
7324a1d71443 simplify and standardize headings and page titles on user and admin pages
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1720
diff changeset
242 title_name=_(u"Item Sizes"),
94
990fdbe2d52c admin/itemsize view (replaces PageSize macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 92
diff changeset
243 headings=headings,
990fdbe2d52c admin/itemsize view (replaces PageSize macro)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 92
diff changeset
244 rows=rows)