Skip to content
Myr

Added support for subdomain bound modules

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent b49afa2 · Browse files · 4 files+35 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+35 added−2 removed

  • tests:+21 added−0 removed
  • other:+14 added−2 removed

4 files+35 added−2 removed

modified:flask/app.py+1 added
452 unmodified lines
453 :class:`Module` class and will override the values of the module if454 provided.455 """456 options.setdefault('url_prefix', module.url_prefix)457 options.setdefault('subdomain', module.subdomain)458 state = _ModuleSetupState(self, **options)459 for func in module._register_events:460 func(state)461
414 unmodified lines
modified:flask/module.py+10 added-2 removed
35 unmodified lines
363738class _ModuleSetupState(object):3940 def __init__(self, app, url_prefix=None):40 def __init__(self, app, url_prefix=None, subdomain=None):41 self.app = app42 self.url_prefix = url_prefix43 self.subdomain = subdomain444546class Module(_PackageBoundObject):47 """Container object that enables pluggable applications. A module can
46 unmodified lines
94 The `static_path` parameter was added and it's now possible for95 modules to refer to their own templates and static files. See96 :ref:`modules-and-resources` for more information.9798 .. versionadded:: 0.699 The `subdomain` parameter was added.100101 :param import_name: the name of the Python package or module102 implementing this :class:`Module`.103 :param name: the internal short name for the module. Unless specified104 the rightmost part of the import name105 :param url_prefix: an optional string that is used to prefix all the106 URL rules of this module. This can also be specified107 when registering the module with the application.108 :param subdomain: used to set the subdomain setting for URL rules that109 do not have a subdomain setting set.110 :param static_path: can be used to specify a different path for the111 static files on the web. Defaults to ``/static``.112 This does not affect the folder the files are served113 *from*.114 """115116 def __init__(self, import_name, name=None, url_prefix=None,111 static_path=None):117 static_path=None, subdomain=None):118 if name is None:119 assert '.' in import_name, 'name required if package name ' \120 'does not point to a submodule'121 name = import_name.rsplit('.', 1)[1]122 _PackageBoundObject.__init__(self, import_name)123 self.name = name124 self.url_prefix = url_prefix125 self.subdomain = subdomain126 self._register_events = [_register_module(self, static_path)]127128 def route(self, rule, **options):129 """Like :meth:`Flask.route` but for a module. The endpoint for the
16 unmodified lines
146 def register_rule(state):147 the_rule = rule148 if state.url_prefix:149 the_rule = state.url_prefix + rule150 options.setdefault('subdomain', state.subdomain)151 the_endpoint = endpoint152 if the_endpoint is None:153 the_endpoint = _endpoint_from_view_func(view_func)154 state.app.add_url_rule(the_rule, '%s.%s' % (self.name,
67 unmodified lines
modified:tests/flask_tests.py+21 added
1036 unmodified lines
1037 c = app.test_client()1038 rv = c.get('/', 'http://mitsuhiko.localhost/')1039 assert rv.data == 'index for mitsuhiko'10401041 def test_module_subdomain_support(self):1042 app = flask.Flask(__name__)1043 mod = flask.Module(__name__, 'test', subdomain='testing')1044 app.config['SERVER_NAME'] = 'localhost'10451046 @mod.route('/test')1047 def test():1048 return 'Test'10491050 @mod.route('/outside', subdomain='xtesting')1051 def bar():1052 return 'Outside'10531054 app.register_module(mod)10551056 c = app.test_client()1057 rv = c.get('/test', 'http://testing.localhost/')1058 assert rv.data == 'Test'1059 rv = c.get('/outside', 'http://xtesting.localhost/')1060 assert rv.data == 'Outside'106110621063class TestSignals(unittest.TestCase):10641065 def test_template_rendered(self):1066 app = flask.Flask(__name__)
102 unmodified lines
modified:CHANGES+3 added
32 unmodified lines
33 you want to use it, make sure to have `blinker`_ installed.34- refactored the way url adapters are created. This process is now35 fully customizable with the :meth:`~flask.Flask.create_url_adapter`36 method.37- modules can now register for a subdomain instead of just an URL38 prefix. This makes it possible to bind a whole module to a39 configurable subdomain.4041.. _blinker: http://pypi.python.org/pypi/blinker4243Version 0.5.2
108 unmodified lines