From e0bd20ee23356d562b27943a6a66b33b44602e4b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 29 Jun 2016 18:59:56 -0500 Subject: [PATCH] Always strip whitespace from label profile 'spec' field input Otherwise we can't properly load (import) the spec object... --- tailbone/forms/renderers/__init__.py | 2 +- tailbone/forms/renderers/common.py | 12 ++++++++++++ tailbone/views/labels/profiles.py | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tailbone/forms/renderers/__init__.py b/tailbone/forms/renderers/__init__.py index 9607e5c4..e679a361 100644 --- a/tailbone/forms/renderers/__init__.py +++ b/tailbone/forms/renderers/__init__.py @@ -28,7 +28,7 @@ from __future__ import unicode_literals, absolute_import from .core import CustomFieldRenderer, DateFieldRenderer -from .common import (AutocompleteFieldRenderer, +from .common import (StrippedTextFieldRenderer, AutocompleteFieldRenderer, DecimalFieldRenderer, CurrencyFieldRenderer, DateTimeFieldRenderer, DateTimePrettyFieldRenderer, TimeFieldRenderer, EnumFieldRenderer, YesNoFieldRenderer) diff --git a/tailbone/forms/renderers/common.py b/tailbone/forms/renderers/common.py index 052507c0..5073382b 100644 --- a/tailbone/forms/renderers/common.py +++ b/tailbone/forms/renderers/common.py @@ -40,6 +40,18 @@ from pyramid.renderers import render from tailbone.util import pretty_datetime, raw_datetime +class StrippedTextFieldRenderer(formalchemy.TextFieldRenderer): + """ + Standard text field renderer, which strips whitespace from either end of + the input value on deserialization. + """ + + def deserialize(self): + value = super(StrippedTextFieldRenderer, self).deserialize() + if value is not None: + return value.strip() + + class AutocompleteFieldRenderer(FieldRenderer): """ Custom renderer for an autocomplete field. diff --git a/tailbone/views/labels/profiles.py b/tailbone/views/labels/profiles.py index 3f458cfc..4182e84a 100644 --- a/tailbone/views/labels/profiles.py +++ b/tailbone/views/labels/profiles.py @@ -32,6 +32,7 @@ import formalchemy from webhelpers.html import HTML from pyramid.httpexceptions import HTTPFound +from tailbone import forms from tailbone.db import Session from tailbone.views import MasterView from tailbone.views.continuum import VersionView, version_defaults @@ -70,6 +71,8 @@ class ProfilesView(MasterView): readonly=True) def configure_fieldset(self, fs): + fs.printer_spec.set(renderer=forms.renderers.StrippedTextFieldRenderer) + fs.formatter_spec.set(renderer=forms.renderers.StrippedTextFieldRenderer) fs.format.set(renderer=FormatFieldRenderer) fs.configure( include=[