def set(self, object, value):
"""Strip the value and pass up."""
- super(StrippedTextLine, self).set(object, value.strip())
+ if value is not None:
+ value = value.strip()
+ super(StrippedTextLine, self).set(object, value)
class NoneableTextLine(StrippedTextLine):
implements(INoneableTextLine)
-
# Title
# A field to capture a launchpad object title
class Title(StrippedTextLine):
It has been more than an hour and still no diff.
=== modified file 'lib/canonical/ launchpad/ doc/stripped- text-widget. txt' launchpad/ doc/stripped- text-widget. txt 2009-08-13 19:36:01 +0000 launchpad/ doc/stripped- text-widget. txt 2009-11-05 17:12:19 +0000 ======= ======= == launchpad. fields import StrippedTextLine field.set( thing, ' egf ') field.get( thing) field.set( thing, None) field.get( thing) ------- ------- ---
--- lib/canonical/
+++ lib/canonical/
@@ -1,4 +1,32 @@
-= StrippedTextLine Widget =
+StrippedTextLine field
+======
+
+The StrippedTextLine field strips the leading and trailing text from the
+set value.
+
+ >>> from canonical.
+
+ >>> non_required_field = StrippedTextLine(
+ ... __name__='field', title=u'Title', required=False)
+
+ >>> class Thing:
+ ... def __init__(self, field):
+ ... self.field = field
+ >>> thing = Thing('abc')
+
+ >>> non_required_
+ >>> non_required_
+ 'egf'
+
+None is an accepted field value.
+
+ >>> non_required_
+ >>> print non_required_
+ None
+
+
+StrippedTextLine Widget
+------
This custom widget is used to strip leading and trailing whitespaces.
@@ -21,9 +49,6 @@
If only whitespace is provided, the widget acts like no input was
provided.
- >>> from canonical. launchpad. fields import StrippedTextLine field.missing_ value is None quest(form= {'field. field': ' \n '})
- >>> non_required_field = StrippedTextLine(
- ... __name__='field', title=u'Title', required=False)
>>> non_required_
True
>>> request = LaunchpadTestRe
=== modified file 'lib/canonical/ launchpad/ fields/ __init_ _.py' launchpad/ fields/ __init_ _.py 2009-10-23 00:48:47 +0000 launchpad/ fields/ __init_ _.py 2009-11-05 16:52:54 +0000
--- lib/canonical/
+++ lib/canonical/
@@ -203,13 +203,14 @@
def set(self, object, value): extLine, self).set(object, value.strip()) extLine, self).set(object, value)
"""Strip the value and pass up."""
- super(StrippedT
+ if value is not None:
+ value = value.strip()
+ super(StrippedT
class NoneableTextLin e(StrippedTextL ine): (INoneableTextL ine)
implements
- extLine) :
# Title
# A field to capture a launchpad object title
class Title(StrippedT