annotate MoinMoin/app.py @ 1992:d06e56e20b91

use more constants: ANON for anonymous
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 12 Feb 2013 20:11:39 +0100
parents bb2f526d961c
children 791bdedb0c20
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 # 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
16 # "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
17 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
18
109
e4c332436733 remove flask monkeypatch, use 'from flask import g as flaskg'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 83
diff changeset
19 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
20 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
21 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
22
1767
54be46b8a0b4 flask ext import change
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1397
diff changeset
23 from flask.ext.cache import Cache
54be46b8a0b4 flask ext import change
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1397
diff changeset
24 from flask.ext.themes import setup_themes
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25
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 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
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 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
29 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
30
1992
d06e56e20b91 use more constants: ANON for anonymous
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
31 from MoinMoin.constants.misc import ANON
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 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
33 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
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.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
36
287
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
37 from MoinMoin.util.clock import Clock
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
38
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
39
854
c9a78e5a58c4 fix script startup deadlock, add script params to create storage and index, fix fs store
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 852
diff changeset
40 def create_app(config=None, create_index=False, create_storage=False):
287
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 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
43 """
854
c9a78e5a58c4 fix script startup deadlock, add script params to create storage and index, fix fs store
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 852
diff changeset
44 return create_app_ext(flask_config_file=config,
c9a78e5a58c4 fix script startup deadlock, add script params to create storage and index, fix fs store
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 852
diff changeset
45 create_index=create_index,
c9a78e5a58c4 fix script startup deadlock, add script params to create storage and index, fix fs store
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 852
diff changeset
46 create_storage=create_storage)
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
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 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
50 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
51 ):
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 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
54
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 36
diff changeset
55 :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
56 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
57 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
58 :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
59 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
60 :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
61 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
62 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
63 into MoinMoin.
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 36
diff changeset
64 :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
65 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
66 :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
67 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
68 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69 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
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 # 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
78 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
79 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
80 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
81 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
82 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
83 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
84 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
85 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
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93 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
94 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
95 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
96 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
97 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
98 # 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
99 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
100 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
101 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
102 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
103 # register converters
1899
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1780
diff changeset
104 from werkzeug.routing import BaseConverter
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1780
diff changeset
105
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1780
diff changeset
106 class ItemNameConverter(BaseConverter):
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1780
diff changeset
107 """Like the default :class:`UnicodeConverter`, but it also matches
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1780
diff changeset
108 slashes (except at the beginning AND end).
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1780
diff changeset
109 This is useful for wikis and similar applications::
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1780
diff changeset
110
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1780
diff changeset
111 Rule('/<itemname:wikipage>')
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1780
diff changeset
112 Rule('/<itemname:wikipage>/edit')
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1780
diff changeset
113 """
1919
20867923566a fix ItemNameConverter regex, fixes #316
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1899
diff changeset
114 regex = '[^/]+?(/[^/]+?)*'
1899
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1780
diff changeset
115 weight = 200
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1780
diff changeset
116
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1780
diff changeset
117 app.url_map.converters['itemname'] = ItemNameConverter
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
118 # 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
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 # 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
144 clock.start('create_app init backends')
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 846
diff changeset
145 init_backends(app)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
146 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
147 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
148 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
149 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
150 # 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
151 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
152 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
153 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
154 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
155 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
156 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
157 ])
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
158 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
159 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
160 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
161 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
162 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
163
950
57ac61f78053 MoinMoin.app: remove unneeded imports, cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 913
diff changeset
164
177
9cc75ad9d6d1 infrastructure to shutdown / close resources of the app, storage, etc.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 135
diff changeset
165 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
166 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
167
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
168
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 846
diff changeset
169 from MoinMoin.storage.middleware import protecting, indexing, routing
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
170 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
171
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
172
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
173 def init_backends(app):
287
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
174 """
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
175 initialize the backends
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
176 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
177 # A ns_mapping consists of several lines, where each line is made up like this:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 846
diff changeset
178 # mountpoint, unprotected backend
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
179 # Just initialize with unprotected backends.
1037
1aa200340d17 New routing middleware based on namespaces, details see below.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 975
diff changeset
180 app.router = routing.Backend(app.cfg.namespace_mapping, app.cfg.backend_mapping)
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 846
diff changeset
181 if app.cfg.create_storage:
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 846
diff changeset
182 app.router.create()
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 846
diff changeset
183 app.router.open()
1780
4a054063fbb0 make whoosh storage type and params configurable, updated docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1767
diff changeset
184 app.storage = indexing.IndexingMiddleware(app.cfg.index_storage, app.router,
862
e1a68b3721cc use the right tokenizers/analyzers in the schema, use name_exact for 1:1 matching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 854
diff changeset
185 wiki_name=app.cfg.interwikiname,
e1a68b3721cc use the right tokenizers/analyzers in the schema, use name_exact for 1:1 matching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 854
diff changeset
186 acl_rights_contents=app.cfg.acl_rights_contents)
854
c9a78e5a58c4 fix script startup deadlock, add script params to create storage and index, fix fs store
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 852
diff changeset
187 if app.cfg.create_index:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 846
diff changeset
188 app.storage.create()
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 846
diff changeset
189 app.storage.open()
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
190
950
57ac61f78053 MoinMoin.app: remove unneeded imports, cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 913
diff changeset
191
177
9cc75ad9d6d1 infrastructure to shutdown / close resources of the app, storage, etc.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 135
diff changeset
192 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
193 app.storage.close()
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 846
diff changeset
194 app.router.close()
854
c9a78e5a58c4 fix script startup deadlock, add script params to create storage and index, fix fs store
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 852
diff changeset
195 if app.cfg.destroy_index:
c9a78e5a58c4 fix script startup deadlock, add script params to create storage and index, fix fs store
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 852
diff changeset
196 app.storage.destroy()
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 846
diff changeset
197 if app.cfg.destroy_storage:
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 846
diff changeset
198 app.router.destroy()
177
9cc75ad9d6d1 infrastructure to shutdown / close resources of the app, storage, etc.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 135
diff changeset
199
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
200
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
201 def setup_user():
287
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
202 """
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
203 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
204 either through the session or through a login.
a4461b58fba3 app: cosmetic changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 267
diff changeset
205 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
206 # 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
207 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
208 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
209 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
210
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
211 # 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
212 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
213
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
214 # 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
215 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
216 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
217 # 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
218 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
219 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
220 # 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
221 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
222 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
223 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
224
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
225 # 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
226 if not userobj:
1992
d06e56e20b91 use more constants: ANON for anonymous
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
227 userobj = user.User(name=ANON, auth_method='invalid')
0
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 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
229 if userobj.valid:
889
4cac830aca1e user obj: use .itemid consistently
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 862
diff changeset
230 session['user.itemid'] = userobj.itemid
1277
f0d1cbe58e53 refactored "trusted" user handling
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1274
diff changeset
231 session['user.trusted'] = userobj.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
232 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
233 session['user.auth_attribs'] = userobj.auth_attribs
1339
8109d2d763d1 Fix for #94 password change should invalidate sessions
"Miks Kalnins <MiksKalnins@MaikuMori.com>"
parents: 1277
diff changeset
234 session['user.session_token'] = userobj.get_session_token()
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
235 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
236
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
237
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
238 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
239 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
240 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
241 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
242 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
243 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
244 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
245 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
246 try:
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 846
diff changeset
247 flaskg.unprotected_storage = app.storage
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
248
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
249 flaskg.user = setup_user()
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 846
diff changeset
250 flaskg.storage = protecting.ProtectingMiddleware(app.storage, flaskg.user, app.cfg.acl_mapping)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
251
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
252 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
253 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
254
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
255 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
256 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
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 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
259 finally:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
260 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
261
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 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
263
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
264
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
265 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
266 """
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
267 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
268 """
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
269 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
270 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
271 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
272 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
273 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
274 # 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
275 pass
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
276 return response