1. Matthew Frazier
  2. flask-uploads

Commits

Matthew Frazier  committed ba4d181

added Flask 0.7 support

  • Participants
  • Parent commits 5834730
  • Branches default
  • Tags 0.1.2

Comments (0)

Files changed (2)

File docs/index.rst

View file
  • Ignore whitespace
 
 Backwards Compatibility
 =======================
+Version 0.1.2
+-------------
+* The `_uploads` module/blueprint will not be registered if it is not needed
+  to serve uploads.
+
 
 Version 0.1.1
 -------------

File flaskext/uploads.py

View file
  • Ignore whitespace
 from flask import current_app, Module, send_from_directory, abort, url_for
 from itertools import chain
 from werkzeug import secure_filename, FileStorage
+try:
+    from flask import Blueprint
+except ImportError:
+    from flask import Module
+    using_blueprints = False
+else:
+    using_blueprints = True
 
 # Extension presets
 
     app. It will also register the uploads module if it hasn't been set. This
     can be called multiple times with different upload sets.
     
+    .. versionchanged:: 0.1.2
+       The uploads module/blueprint will only be registered if it is needed
+       to serve the upload sets.
+    
     :param app: The `~flask.Flask` instance to get the configuration from.
     :param upload_sets: The `UploadSet` instances to configure.
     """
         set_config[uset.name] = config
     
     should_serve = any(s.base_url is None for s in set_config.itervalues())
-    if '_uploads' not in app.modules and should_serve:
-        app.register_module(uploads_mod)
+    if using_blueprints:
+        if '_uploads' not in app.blueprints and should_serve:
+            app.register_blueprint(uploads_mod)
+    else:
+        if '_uploads' not in app.modules and should_serve:
+            app.register_module(uploads_mod)
 
 
 class All(object):
                 return newname
 
 
-uploads_mod = Module(__name__, name='_uploads', url_prefix='/_uploads')
+if using_blueprints:
+    uploads_mod = Blueprint('_uploads', __name__, url_prefix='/_uploads')
+else:
+    uploads_mod = Module(__name__, name='_uploads', url_prefix='/_uploads')
 
 @uploads_mod.route('/<setname>/<path:filename>')
 def uploaded_file(setname, filename):