allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [1/3] allura git commit: [#6057] ticket:792 Allow ConfigOption to specify extra attrs for html input tag
Date Tue, 09 Jun 2015 14:33:34 GMT
Repository: allura
Updated Branches:
  refs/heads/ib/6057 ed3eac3dc -> 1cb2df179


[#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/a186ea5b
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/a186ea5b
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/a186ea5b

Branch: refs/heads/ib/6057
Commit: a186ea5bb5602a914e5b02b0f16b7bfae521ad21
Parents: ed3eac3
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Jun 9 13:41:25 2015 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Tue Jun 9 13:46:50 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/a186ea5b/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/a186ea5b/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/a186ea5b/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/a186ea5b/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/a186ea5b/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


Mime
View raw message