You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/07/08 18:50:25 UTC

[5/7] git commit: [#4213] ticket:345 fixed grammar errors and refactored

[#4213]  ticket:345 fixed grammar errors and refactored


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/8993951a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/8993951a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/8993951a

Branch: refs/heads/master
Commit: 8993951a56adb9e0374a4d9765d6285ab0735d4a
Parents: 0efd308
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Tue Jun 4 18:03:22 2013 +0400
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Sun Jul 7 06:09:58 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/helpers.py                     | 18 ++++++++++++++++++
 Allura/allura/tests/test_helpers.py              |  5 +++++
 ForgeTracker/forgetracker/import_support.py      | 17 +++++------------
 ForgeTracker/forgetracker/widgets/ticket_form.py | 18 ++----------------
 4 files changed, 30 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8993951a/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 144bef3..1604aa9 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -29,6 +29,7 @@ import cPickle as pickle
 from hashlib import sha1
 from datetime import datetime, timedelta
 from collections import defaultdict
+import shlex
 
 import tg
 import genshi.template
@@ -839,3 +840,20 @@ def ming_config_from_ini(ini_path):
     conf = appconfig('config:%s' % os.path.join(root, ini_path))
     with ming_config(**conf):
         yield
+
+
+def split_select_field_options(field_options):
+    try:
+        # shlex have problems with parsing unicode,
+        # it's better to pass properly encoded byte-string
+        field_options = shlex.split(field_options.encode('utf-8'))
+        # convert splitted string back to unicode
+        field_options = map(really_unicode, field_options)
+    except ValueError:
+        field_options = field_options.split()
+        # After regular split field_options might contain a " characters,
+        # which would break html when rendered inside tag's value attr.
+        # Escaping doesn't help here, 'cause it breaks EasyWidgets' validation,
+        # so we're getting rid of those.
+        field_options = [o.replace('"', '') for o in field_options]
+    return field_options

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8993951a/Allura/allura/tests/test_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index 904d188..42fb963 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -249,3 +249,8 @@ def test_inject_user(context):
 def test_datetimeformat():
     from datetime import date
     assert h.datetimeformat(date(2013, 01, 01)) == '2013-01-01 00:00:00'
+
+
+def test_split_select_field_options():
+    assert_equals(h.split_select_field_options('"test message" test2'), ['test message', 'test2'])
+    assert_equals(h.split_select_field_options('"test message test2'), ['test', 'message', 'test2'])

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8993951a/ForgeTracker/forgetracker/import_support.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/import_support.py b/ForgeTracker/forgetracker/import_support.py
index 56c6947..d23cf94 100644
--- a/ForgeTracker/forgetracker/import_support.py
+++ b/ForgeTracker/forgetracker/import_support.py
@@ -18,7 +18,6 @@
 #-*- python -*-
 import logging
 import json
-import shlex
 from datetime import datetime
 from cStringIO import StringIO
 
@@ -142,19 +141,13 @@ class ImportSupport(object):
             return u._id
         return None
 
-    def check_suctom_field(self, field, value):
+    def check_custom_field(self, field, value):
         field = c.app.globals.get_custom_field(field)
-        if (field['type'] == 'select') and (value != ''):
-            field_options = h.really_unicode(field['options'])
-            try:
-                field_options = shlex.split(field_options.encode('utf-8'))
-                field_options = map(h.really_unicode, field_options)
-            except ValueError:
-                field_options = field_options.split()
-            field_options = [o.replace('"', '') for o in field_options]
+        if (field['type'] == 'select') and value:
+            field_options = h.split_select_field_options(h.really_unicode(field['options']))
             if value not in field_options:
                 field['options'] = ' '.join([field['options'], value])
-        elif (field['type'] == 'milestone') and (value != ''):
+        elif (field['type'] == 'milestone') and value:
             milestones = field['milestones']
             is_exists = False
             for milestone in milestones:
@@ -177,7 +170,7 @@ class ImportSupport(object):
             ThreadLocalORMSession.flush_all()
         if 'custom_fields' not in ticket:
             ticket['custom_fields'] = {}
-        self.check_suctom_field(field, value)
+        self.check_custom_field(field, value)
         ticket['custom_fields'][field] = value
 
     #

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8993951a/ForgeTracker/forgetracker/widgets/ticket_form.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/widgets/ticket_form.py b/ForgeTracker/forgetracker/widgets/ticket_form.py
index 9139cda..cb05085 100644
--- a/ForgeTracker/forgetracker/widgets/ticket_form.py
+++ b/ForgeTracker/forgetracker/widgets/ticket_form.py
@@ -15,8 +15,6 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
-import shlex
-
 from pylons import tmpl_context as c
 from formencode import validators as fev
 
@@ -164,20 +162,8 @@ class TicketCustomField(object):
 
     def _select(field):
         options = []
-        field_options = h.really_unicode(field.options)
-        try:
-            # shlex have problems with parsing unicode,
-            # it's better to pass properly encoded byte-string
-            field_options = shlex.split(field_options.encode('utf-8'))
-            # convert splitted string back to unicode
-            field_options = map(h.really_unicode, field_options)
-        except ValueError:
-            field_options = field_options.split()
-            # After regular split field_options might contain a " characters,
-            # which would break html when rendered inside tag's value attr.
-            # Escaping doesn't help here, 'cause it breaks EasyWidgets' validation,
-            # so we're getting rid of those.
-            field_options = [o.replace('"', '') for o in field_options]
+        field_options = h.split_select_field_options(h.really_unicode(field.options))
+
         for opt in field_options:
             selected = False
             if opt.startswith('*'):