Skip to content

Commit bfdf30b

Browse files
committed
_uploads module is only attached if it is needed
1 parent 7722c3f commit bfdf30b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

.hgignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ syntax: glob
44
*.pyo
55
docs/_build/*
66
*egg-info*
7-
dist/*
7+
dist/*
8+
env/*

flaskext/uploads.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,14 @@ def configure_uploads(app, upload_sets):
164164
"""
165165
Call this after the app has been configured. It will go through all the
166166
upload sets, get their configuration, and store the configuration on the
167-
app. It will also register the uploads module if it hasn't been set.
167+
app. It will also register the uploads module if it hasn't been set. This
168+
can be called multiple times with different upload sets.
168169
169170
:param app: The `~flask.Flask` instance to get the configuration from.
170171
:param upload_sets: The `UploadSet` instances to configure.
171172
"""
172173
if isinstance(upload_sets, UploadSet):
173174
upload_sets = (upload_sets,)
174-
if '_uploads' not in app.modules:
175-
app.register_module(uploads_mod)
176175

177176
if not hasattr(app, 'upload_set_config'):
178177
app.upload_set_config = {}
@@ -183,6 +182,10 @@ def configure_uploads(app, upload_sets):
183182
for uset in upload_sets:
184183
config = config_for_set(uset, app, defaults)
185184
set_config[uset.name] = config
185+
186+
should_serve = any(s.base_url is None for s in set_config.itervalues())
187+
if '_uploads' not in app.modules and should_serve:
188+
app.register_module(uploads_mod)
186189

187190

188191
class All(object):

0 commit comments

Comments
 (0)