Skip to content

Commit

Permalink
This enables configuration of the deform static path in the Pyramid
Browse files Browse the repository at this point in the history
configuration file.  If the Pyramid configuration includes a value
for ``pyramid_deform.static_path`` that will be used to configure the
static path, else the default value of static-deform will be used.
	modified:   CONTRIBUTORS.txt
	modified:   pyramid_deform/__init__.py
	modified:   pyramid_deform/tests.py
  • Loading branch information
lanestevens committed Sep 11, 2012
1 parent 5e0dedd commit 2dee7c7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Expand Up @@ -110,3 +110,4 @@ Chris McDonough, 2010/11/27
Daniel Nouri, 2012/03/30
Josh Jaques, 2012/04/26
Alexander Fedorov, 2012/04/26
Lane Stevens, 2012/09/11
12 changes: 8 additions & 4 deletions pyramid_deform/__init__.py
Expand Up @@ -478,9 +478,11 @@ def chunks(stream, chunk_size=10000):
def includeme(config):
""" Provide useful configuration to a Pyramid ``Configurator`` instance.
Currently, this hook will set up and register translation paths so
for Deform and Colander, add a static view for Deform resources, and
configures a template search path (if one is specified by
Currently, this hook will set up and register translation paths
for Deform and Colander, add a static view for Deform resources (uses
``pyramid_deform.static_path`` from the Pyramid configuration if
specified else ``static-deform`` by default), and configures a
template search path (if one is specified by
``pyramid_deform.template_search_path`` in your Pyramid
configuration).
"""
Expand All @@ -489,6 +491,8 @@ def includeme(config):
'pyramid_deform.template_search_path', '').strip()

config.add_translation_dirs('colander:locale', 'deform:locale')
config.add_static_view('static-deform', 'deform:static')
static_path = settings.get(
'pyramid_deform.static_path', 'static-deform').strip()
config.add_static_view(static_path, 'deform:static')

configure_zpt_renderer(search_path.split())
17 changes: 17 additions & 0 deletions pyramid_deform/tests.py
Expand Up @@ -718,6 +718,23 @@ def test_default(self, Form, configure_zpt_renderer):

assert config.add_translation_dirs.call_count == 1
assert config.add_static_view.call_count == 1
config.add_static_view.assert_called_with('static-deform', 'deform:static')
configure_zpt_renderer.assert_called_with([])

@patch('pyramid_deform.configure_zpt_renderer')
@patch('deform.form.Form')
def test_static_path(self, Form, configure_zpt_renderer):
from pyramid_deform import includeme

config = Mock()
config.registry.settings = {
'pyramid_deform.static_path': 'http://some.domain.com/override/path ', #also tests strip
}
includeme(config)

assert config.add_translation_dirs.call_count == 1
assert config.add_static_view.call_count == 1
config.add_static_view.assert_called_with('http://some.domain.com/override/path', 'deform:static')
configure_zpt_renderer.assert_called_with([])

@patch('pyramid_deform.configure_zpt_renderer')
Expand Down

0 comments on commit 2dee7c7

Please sign in to comment.