Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6E6021057A for ; Mon, 8 Jul 2013 19:28:14 +0000 (UTC) Received: (qmail 91834 invoked by uid 500); 8 Jul 2013 19:28:14 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 91772 invoked by uid 500); 8 Jul 2013 19:28:14 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 91593 invoked by uid 99); 8 Jul 2013 19:28:14 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jul 2013 19:28:14 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id DBB8E88851F; Mon, 8 Jul 2013 19:28:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: johnsca@apache.org To: allura-commits@incubator.apache.org Date: Mon, 08 Jul 2013 19:28:32 -0000 Message-Id: <292deb5b5ee34287b26c8dcacac00ebf@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [20/25] 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/cj/4656 Commit: 8993951a56adb9e0374a4d9765d6285ab0735d4a Parents: 0efd308 Author: Yuriy Arhipov Authored: Tue Jun 4 18:03:22 2013 +0400 Committer: Tim Van Steenburgh 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('*'):