You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by he...@apache.org on 2015/06/09 23:08:28 UTC
[5/8] allura git commit: [#6057] ticket:792 Allow ConfigOption to
specify extra attrs for html input tag
[#6057] ticket:792 Allow ConfigOption to specify extra attrs for html input tag
and use it to pass type='url' to ForgeLink's url options
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/bc3c028c
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/bc3c028c
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/bc3c028c
Branch: refs/heads/master
Commit: bc3c028c7cc04430aaf0a1d81c8c194ed65301cb
Parents: a0b3aed
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Jun 9 13:41:25 2015 +0000
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Tue Jun 9 21:06:06 2015 +0000
----------------------------------------------------------------------
Allura/allura/app.py | 8 +++++++-
Allura/allura/templates/app_admin_options.html | 4 ++--
Allura/allura/templates/app_admin_options_on_install.html | 4 ++--
Allura/allura/tests/test_app.py | 5 +++++
ForgeLink/forgelink/link_main.py | 3 ++-
5 files changed, 18 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/bc3c028c/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index 58aa49d..2683e36 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -36,6 +36,7 @@ from formencode import validators as fev
from ming.orm import session
from ming.utils import LazyProperty
+import ew.jinja2_ew as ew
from allura.lib import helpers as h
from allura.lib.security import has_access, require_access
@@ -56,13 +57,14 @@ class ConfigOption(object):
"""
- def __init__(self, name, ming_type, default, label=None, validator=None):
+ def __init__(self, name, ming_type, default, label=None, validator=None, extra_attrs=None):
"""Create a new ConfigOption.
"""
self.name, self.ming_type, self._default, self.label = (
name, ming_type, default, label or name)
self.validator = validator
+ self.extra_attrs = extra_attrs
@property
def default(self):
@@ -78,6 +80,10 @@ class ConfigOption(object):
return self.validator.to_python(value)
return value
+ def render_attrs(self):
+ """Return extra_attrs formatted in a way that allows inserting into html tag"""
+ return ew._Jinja2Widget().j2_attrs(self.extra_attrs or {})
+
class SitemapEntry(object):
http://git-wip-us.apache.org/repos/asf/allura/blob/bc3c028c/Allura/allura/templates/app_admin_options.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/app_admin_options.html b/Allura/allura/templates/app_admin_options.html
index 8924823..bf013c4 100644
--- a/Allura/allura/templates/app_admin_options.html
+++ b/Allura/allura/templates/app_admin_options.html
@@ -26,9 +26,9 @@
{{app.config.options.get(o.name, o.default)}}
{% else%}
{% if o.ming_type.__name__ == 'bool' %}
- <input id="{{o.name}}" name="{{o.name}}" type="checkbox"{{ ' checked="checked"' if app.config.options.get(o.name, o.default)}}>
+ <input {{o.render_attrs()}} id="{{o.name}}" name="{{o.name}}" type="checkbox"{{ ' checked="checked"' if app.config.options.get(o.name, o.default)}}>
{% else %}
- <input id="{{o.name}}" name="{{o.name}}" value="{{app.config.options.get(o.name, o.default)}}">
+ <input {{o.render_attrs()}} id="{{o.name}}" name="{{o.name}}" value="{{app.config.options.get(o.name, o.default)}}">
{% endif %}
{% endif %}
</div>
http://git-wip-us.apache.org/repos/asf/allura/blob/bc3c028c/Allura/allura/templates/app_admin_options_on_install.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/app_admin_options_on_install.html b/Allura/allura/templates/app_admin_options_on_install.html
index bc0d8ea..218dd61 100644
--- a/Allura/allura/templates/app_admin_options_on_install.html
+++ b/Allura/allura/templates/app_admin_options_on_install.html
@@ -20,9 +20,9 @@
<label class="grid-13" for="{{o.name}}">{{o.label|capitalize}}</label>
<div class="grid-13">
{% if o.ming_type.__name__ == 'bool' %}
- <input id="{{o.name}}" name="{{o.name}}" type="checkbox"{{ ' checked="checked"' if o.default}}>
+ <input {{o.render_attrs()}}id="{{o.name}}" name="{{o.name}}" type="checkbox"{{ ' checked="checked"' if o.default}}>
{% else %}
- <input id="{{o.name}}" name="{{o.name}}" value="{{o.default or ''}}">
+ <input {{o.render_attrs()}} id="{{o.name}}" name="{{o.name}}" value="{{o.default or ''}}">
{% endif %}
</div>
{% endfor %}
http://git-wip-us.apache.org/repos/asf/allura/blob/bc3c028c/Allura/allura/tests/test_app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_app.py b/Allura/allura/tests/test_app.py
index 2642a95..230b5f9 100644
--- a/Allura/allura/tests/test_app.py
+++ b/Allura/allura/tests/test_app.py
@@ -54,6 +54,11 @@ def test_config_options():
assert options[1].default == 'MyTestValue'
+def test_config_options_render_attrs():
+ opt = app.ConfigOption('test1', str, None, extra_attrs={'type': 'url'})
+ assert_equal(opt.render_attrs(), 'type="url"')
+
+
def test_config_option_without_validator():
opt = app.ConfigOption('test1', str, None)
assert_equal(opt.validate(None), None)
http://git-wip-us.apache.org/repos/asf/allura/blob/bc3c028c/ForgeLink/forgelink/link_main.py
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/link_main.py b/ForgeLink/forgelink/link_main.py
index b50c22e..ec32974 100644
--- a/ForgeLink/forgelink/link_main.py
+++ b/ForgeLink/forgelink/link_main.py
@@ -51,7 +51,8 @@ class ForgeLinkApp(Application):
config_options = Application.config_options + [
ConfigOption(
'url', str, None,
- validator=fev.URL(not_empty=True, add_http=True)),
+ validator=fev.URL(not_empty=True, add_http=True),
+ extra_attrs={'type': 'url'}),
]
config_on_install = ['url']
searchable = True