annotate MoinMoin/app.py @ 300:e8bd41ab7bdd

AccessControlList: do not require cfg object Giving the cfg to the ACL object caused some issues (for example, the AclTokenizer in the whoosh branch needed cfg and was part of the schema. whoosh tries to pickle the schema and that did not work for cfg). Refactored "auth_trusted" - this is now a user object attribute, so the ACL code does not need to know the list of trusted auth methods (which is still in cfg, but it shouldn't even be there). It is AccessControlList(acl_lines=[], default='', valid=None) now, you need to give the list of valid rights strings via valid param. TODO: deal with cfg.acl_rights_functions, cfg.acl_rights_contents (defaults?) Got rid of ContentACL and FunctionACL classes, they were pointless as "valid" needs to be given anyway.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 01 Aug 2011 20:08:15 +0200
parents e6f585ac9766
children 2305be335d83 8f36c9135963
rev   line source
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
1 # Copyright: 2000-2006 by Juergen Hermann <jh@web.de>
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
2 # Copyright: 2002-2011 MoinMoin:ThomasWaldmann
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
3 # Copyright: 2008 MoinMoin:FlorianKrupicka
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
4 # 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
5 # 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
6
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8 MoinMoin - wsgi application setup and related code
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 Use create_app(config) to create the WSGI application (using Flask).
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
11 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12
134
901bd4e1861e import absolute_import, division from __future__ in every module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 109
diff changeset
13 from __future__ import absolute_import, division
901bd4e1861e import absolute_import, division from __future__ in every module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 109
diff changeset
14
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15 import os
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17 # do this early, but not in MoinMoin/__init__.py because we need to be able to
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 # "import MoinMoin" from setup.py even before flask, werkzeug, ... is installed.
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.util import monkeypatch
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20
109
e4c332436733 remove flask monkeypatch, use 'from flask import g as flaskg'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 83
diff changeset
21 from flask import Flask, request, session
0
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 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: 83
diff changeset
23 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
24
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 from flaskext.cache import Cache
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26 from flaskext.themes import setup_themes
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
27
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
28 from werkzeug.exceptions import HTTPException
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
29
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30 from jinja2 import ChoiceLoader, FileSystemLoader
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32 from MoinMoin import log
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33 logging = log.getLogger(__name__)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35 from MoinMoin.i18n import i18n_init
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 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
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 from MoinMoin.themes import setup_jinja_env, themed_error
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39
287
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
40 from MoinMoin.util.clock import Clock
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
41
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
42
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 def create_app(config=None):
287
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
44 """
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
45 simple wrapper around create_app_ext() for flask-script
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
46 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
47 return create_app_ext(flask_config_file=config)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
48
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
50 def create_app_ext(flask_config_file=None, flask_config_dict=None,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 moin_config_class=None, warn_default=True, **kwargs
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52 ):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54 Factory for moin wsgi apps
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
55
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 36
diff changeset
56 :param flask_config_file: a flask config file name (may have a MOINCFG class),
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57 if not given, a config pointed to by MOINCFG env var
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
58 will be loaded (if possible).
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 36
diff changeset
59 :param flask_config_dict: a dict used to update flask config (applied after
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
60 flask_config_file was loaded [if given])
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 36
diff changeset
61 :param moin_config_class: if you give this, it'll be instantiated as app.cfg,
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
62 otherwise it'll use MOINCFG from flask config. If that
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
63 also is not there, it'll use the DefaultConfig built
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
64 into MoinMoin.
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 36
diff changeset
65 :param warn_default: emit a warning if moin falls back to its builtin default
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66 config (maybe user forgot to specify MOINCFG?)
50
8102f92d21b8 docstrings: fix some rst markup warnings of sphinx
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
67 :param kwargs: if you give additional keyword args, the keys/values will get patched
8102f92d21b8 docstrings: fix some rst markup warnings of sphinx
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
68 into the moin configuration class (before its instance is created)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
70 clock = Clock()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71 clock.start('create_app total')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
72 app = Flask('MoinMoin')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
73 clock.start('create_app load config')
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 flask_config_file:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
75 app.config.from_pyfile(flask_config_file)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
76 else:
83
8a5be4814a48 use console_script entry point - setup.py now installs a "moin" script for the platform
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 50
diff changeset
77 if not app.config.from_envvar('MOINCFG', silent=True):
8a5be4814a48 use console_script entry point - setup.py now installs a "moin" script for the platform
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 50
diff changeset
78 # no MOINCFG env variable set, try stuff in cwd:
8a5be4814a48 use console_script entry point - setup.py now installs a "moin" script for the platform
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 50
diff changeset
79 from os import path
8a5be4814a48 use console_script entry point - setup.py now installs a "moin" script for the platform
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 50
diff changeset
80 flask_config_file = path.abspath('wikiconfig_local.py')
8a5be4814a48 use console_script entry point - setup.py now installs a "moin" script for the platform
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 50
diff changeset
81 if not path.exists(flask_config_file):
8a5be4814a48 use console_script entry point - setup.py now installs a "moin" script for the platform
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 50
diff changeset
82 flask_config_file = path.abspath('wikiconfig.py')
8a5be4814a48 use console_script entry point - setup.py now installs a "moin" script for the platform
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 50
diff changeset
83 if not path.exists(flask_config_file):
8a5be4814a48 use console_script entry point - setup.py now installs a "moin" script for the platform
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 50
diff changeset
84 flask_config_file = None
8a5be4814a48 use console_script entry point - setup.py now installs a "moin" script for the platform
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 50
diff changeset
85 if flask_config_file:
8a5be4814a48 use console_script entry point - setup.py now installs a "moin" script for the platform
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 50
diff changeset
86 app.config.from_pyfile(flask_config_file)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
87 if flask_config_dict:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
88 app.config.update(flask_config_dict)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89 Config = moin_config_class
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
90 if not Config:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
91 Config = app.config.get('MOINCFG')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92 if not Config:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93 if warn_default:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94 logging.warning("using builtin default configuration")
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95 from MoinMoin.config.default import DefaultConfig as Config
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 for key, value in kwargs.iteritems():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
97 setattr(Config, key, value)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 if Config.secrets is None:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 # reuse the secret configured for flask (which is required for sessions)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100 Config.secrets = app.config.get('SECRET_KEY')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
101 app.cfg = Config()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
102 clock.stop('create_app load config')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
103 clock.start('create_app register')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104 # register converters
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105 from werkzeug.routing import PathConverter
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
106 app.url_map.converters['itemname'] = PathConverter
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107 # register modules, before/after request functions
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
108 from MoinMoin.apps.frontend import frontend
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
109 frontend.before_request(before_wiki)
288
e6f585ac9766 use teardown_request (teardown_wiki) instead of after_request (after_wiki), because it is called when an exception happened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 287
diff changeset
110 frontend.teardown_request(teardown_wiki)
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 180
diff changeset
111 app.register_blueprint(frontend)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112 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
113 admin.before_request(before_wiki)
288
e6f585ac9766 use teardown_request (teardown_wiki) instead of after_request (after_wiki), because it is called when an exception happened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 287
diff changeset
114 admin.teardown_request(teardown_wiki)
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 180
diff changeset
115 app.register_blueprint(admin, url_prefix='/+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
116 from MoinMoin.apps.feed import feed
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117 feed.before_request(before_wiki)
288
e6f585ac9766 use teardown_request (teardown_wiki) instead of after_request (after_wiki), because it is called when an exception happened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 287
diff changeset
118 feed.teardown_request(teardown_wiki)
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 180
diff changeset
119 app.register_blueprint(feed, url_prefix='/+feed')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
120 from MoinMoin.apps.misc import misc
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
121 misc.before_request(before_wiki)
288
e6f585ac9766 use teardown_request (teardown_wiki) instead of after_request (after_wiki), because it is called when an exception happened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 287
diff changeset
122 misc.teardown_request(teardown_wiki)
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 180
diff changeset
123 app.register_blueprint(misc, url_prefix='/+misc')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
124 from MoinMoin.apps.serve import serve
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 180
diff changeset
125 app.register_blueprint(serve, url_prefix='/+serve')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
126 clock.stop('create_app register')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
127 clock.start('create_app flask-cache')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128 cache = Cache()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
129 cache.init_app(app)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
130 app.cache = cache
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131 clock.stop('create_app flask-cache')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
132 # init storage
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133 clock.start('create_app init backends')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
134 app.unprotected_storage, app.storage = init_backends(app)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
135 clock.stop('create_app init backends')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
136 clock.start('create_app index rebuild')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137 if app.cfg.index_rebuild:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
138 app.unprotected_storage.index_rebuild() # XXX run this from a script
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139 clock.stop('create_app index rebuild')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
140 clock.start('create_app load/save xml')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
141 import_export_xml(app)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
142 clock.stop('create_app load/save xml')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
143 clock.start('create_app flask-babel')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
144 i18n_init(app)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
145 clock.stop('create_app flask-babel')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
146 # configure templates
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
147 clock.start('create_app flask-themes')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
148 setup_themes(app)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
149 if app.cfg.template_dirs:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
150 app.jinja_env.loader = ChoiceLoader([
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
151 FileSystemLoader(app.cfg.template_dirs),
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
152 app.jinja_env.loader,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
153 ])
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 180
diff changeset
154 app.register_error_handler(403, themed_error)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
155 clock.stop('create_app flask-themes')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
156 clock.stop('create_app total')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
157 del clock
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
158 return app
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
159
177
9cc75ad9d6d1 infrastructure to shutdown / close resources of the app, storage, etc.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 135
diff changeset
160 def destroy_app(app):
9cc75ad9d6d1 infrastructure to shutdown / close resources of the app, storage, etc.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 135
diff changeset
161 deinit_backends(app)
9cc75ad9d6d1 infrastructure to shutdown / close resources of the app, storage, etc.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 135
diff changeset
162
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
163
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
164 from MoinMoin.storage.error import StorageError
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
165 from MoinMoin.storage.serialization import serialize, unserialize
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
166 from MoinMoin.storage.backends import router, acl, memory
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
167 from MoinMoin import auth, config, user
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
168
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
169
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
170 def init_backends(app):
287
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
171 """
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
172 initialize the backends
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
173 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
174 # A ns_mapping consists of several lines, where each line is made up like this:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
175 # mountpoint, unprotected backend, protection to apply as a dict
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
176 ns_mapping = app.cfg.namespace_mapping
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
177 index_uri = app.cfg.router_index_uri
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
178 # Just initialize with unprotected backends.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
179 unprotected_mapping = [(ns, backend) for ns, backend, acls in ns_mapping]
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
180 unprotected_storage = router.RouterBackend(unprotected_mapping, index_uri=index_uri)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
181 # Protect each backend with the acls provided for it in the mapping at position 2
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
182 amw = acl.AclWrapperBackend
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
183 protected_mapping = [(ns, amw(app.cfg, backend, **acls)) for ns, backend, acls in ns_mapping]
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
184 storage = router.RouterBackend(protected_mapping, index_uri=index_uri)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
185 return unprotected_storage, storage
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
186
177
9cc75ad9d6d1 infrastructure to shutdown / close resources of the app, storage, etc.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 135
diff changeset
187 def deinit_backends(app):
9cc75ad9d6d1 infrastructure to shutdown / close resources of the app, storage, etc.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 135
diff changeset
188 app.storage.close()
9cc75ad9d6d1 infrastructure to shutdown / close resources of the app, storage, etc.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 135
diff changeset
189 app.unprotected_storage.close()
9cc75ad9d6d1 infrastructure to shutdown / close resources of the app, storage, etc.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 135
diff changeset
190
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
191
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
192 def import_export_xml(app):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
193 # If the content was already pumped into the backend, we don't want
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
194 # to do that again. (Works only until the server is restarted.)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
195 xmlfile = app.cfg.load_xml
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
196 if xmlfile:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
197 app.cfg.load_xml = None
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
198 tmp_backend = router.RouterBackend([('/', memory.MemoryBackend())],
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
199 index_uri='sqlite://')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
200 unserialize(tmp_backend, xmlfile)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
201 # TODO optimize this, maybe unserialize could count items it processed
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
202 item_count = 0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
203 for item in tmp_backend.iteritems():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
204 item_count += 1
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
205 logging.debug("loaded xml into tmp_backend: %s, %d items" % (xmlfile, item_count))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
206 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
207 # In case the server was restarted we cannot know whether
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
208 # the xml data already exists in the target backend.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
209 # Hence we check the existence of the items before we unserialize
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
210 # them to the backend.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
211 backend = app.unprotected_storage
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
212 for item in tmp_backend.iteritems():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
213 item = backend.get_item(item.name)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
214 except StorageError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
215 # if there is some exception, we assume that backend needs to be filled
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
216 # we need to use it as unserialization target so that update mode of
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
217 # unserialization creates the correct item revisions
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
218 logging.debug("unserialize xml file %s into %r" % (xmlfile, backend))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
219 unserialize(backend, xmlfile)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
220 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
221 item_count = 0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
222
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
223 # XXX wrong place / name - this is a generic preload functionality, not just for tests
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
224 # To make some tests happy
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
225 app.cfg.test_num_pages = item_count
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
226
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
227 xmlfile = app.cfg.save_xml
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
228 if xmlfile:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
229 app.cfg.save_xml = None
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
230 backend = app.unprotected_storage
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
231 serialize(backend, xmlfile)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
232
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
233
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
234 def setup_user():
287
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
235 """
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
236 Try to retrieve a valid user object from the request, be it
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
237 either through the session or through a login.
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
238 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
239 # init some stuff for auth processing:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
240 flaskg._login_multistage = None
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
241 flaskg._login_multistage_name = None
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
242 flaskg._login_messages = []
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
243
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
244 # first try setting up from session
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
245 userobj = auth.setup_from_session()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
246
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
247 # then handle login/logout forms
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
248 form = request.values.to_dict()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
249 if 'login_submit' in form:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
250 # this is a real form, submitted by POST
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
251 userobj = auth.handle_login(userobj, **form)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
252 elif 'logout_submit' in form:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
253 # currently just a GET link
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
254 userobj = auth.handle_logout(userobj)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
255 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
256 userobj = auth.handle_request(userobj)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
257
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
258 # if we still have no user obj, create a dummy:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
259 if not userobj:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
260 userobj = user.User(auth_method='invalid')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
261 # if we have a valid user we store it in the session
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
262 if userobj.valid:
300
e8bd41ab7bdd AccessControlList: do not require cfg object
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 288
diff changeset
263 # TODO: auth_trusted should be set by the auth method (auth class
e8bd41ab7bdd AccessControlList: do not require cfg object
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 288
diff changeset
264 # could have a param where the admin could tell whether he wants to
e8bd41ab7bdd AccessControlList: do not require cfg object
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 288
diff changeset
265 # trust it)
e8bd41ab7bdd AccessControlList: do not require cfg object
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 288
diff changeset
266 userobj.auth_trusted = userobj.auth_method in app.cfg.auth_methods_trusted
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
267 session['user.id'] = userobj.id
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
268 session['user.auth_method'] = userobj.auth_method
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
269 session['user.auth_attribs'] = userobj.auth_attribs
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
270 return userobj
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
271
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
272
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
273 def before_wiki():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
274 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
275 Setup environment for wiki requests, start timers.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
276 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
277 logging.debug("running before_wiki")
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
278 flaskg.clock = Clock()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
279 flaskg.clock.start('total')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
280 flaskg.clock.start('init')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
281 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
282 flaskg.unprotected_storage = app.unprotected_storage
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
283
267
e969c9318772 remove HTTPException handler for setup_user that is not needed any more for flask >= 0.7
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 266
diff changeset
284 flaskg.user = setup_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
285
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
286 flaskg.dicts = app.cfg.dicts()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
287 flaskg.groups = app.cfg.groups()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
288
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
289 flaskg.content_lang = app.cfg.language_default
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
290 flaskg.current_lang = app.cfg.language_default
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
291
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
292 flaskg.storage = app.storage
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
293
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
294 setup_jinja_env()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
295 finally:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
296 flaskg.clock.stop('init')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
297
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
298 # if return value is not None, it is the final response
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
299
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
300
288
e6f585ac9766 use teardown_request (teardown_wiki) instead of after_request (after_wiki), because it is called when an exception happened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 287
diff changeset
301 def teardown_wiki(response):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
302 """
288
e6f585ac9766 use teardown_request (teardown_wiki) instead of after_request (after_wiki), because it is called when an exception happened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 287
diff changeset
303 Teardown environment of wiki requests, stop timers.
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
304 """
288
e6f585ac9766 use teardown_request (teardown_wiki) instead of after_request (after_wiki), because it is called when an exception happened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 287
diff changeset
305 logging.debug("running teardown_wiki")
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
306 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
307 flaskg.clock.stop('total')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
308 del flaskg.clock
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
309 except AttributeError:
288
e6f585ac9766 use teardown_request (teardown_wiki) instead of after_request (after_wiki), because it is called when an exception happened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 287
diff changeset
310 # can happen if teardown_wiki() is called twice, e.g. by unit tests.
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
311 pass
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
312 return response
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
313