Code review comment for lp:~sinzui/launchpad/noneable-bug-475433

Revision history for this message
Curtis Hovey (sinzui) wrote :

It has been more than an hour and still no diff.

=== modified file 'lib/canonical/launchpad/doc/stripped-text-widget.txt'
--- lib/canonical/launchpad/doc/stripped-text-widget.txt 2009-08-13 19:36:01 +0000
+++ lib/canonical/launchpad/doc/stripped-text-widget.txt 2009-11-05 17:12:19 +0000
@@ -1,4 +1,32 @@
-= StrippedTextLine Widget =
+StrippedTextLine field
+======================
+
+The StrippedTextLine field strips the leading and trailing text from the
+set value.
+
+ >>> from canonical.launchpad.fields import StrippedTextLine
+
+ >>> 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_field.set(thing, ' egf ')
+ >>> non_required_field.get(thing)
+ 'egf'
+
+None is an accepted field value.
+
+ >>> non_required_field.set(thing, None)
+ >>> print non_required_field.get(thing)
+ 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
- >>> non_required_field = StrippedTextLine(
- ... __name__='field', title=u'Title', required=False)
   >>> non_required_field.missing_value is None
   True
   >>> request = LaunchpadTestRequest(form={'field.field':' \n '})

=== modified file 'lib/canonical/launchpad/fields/__init__.py'
--- lib/canonical/launchpad/fields/__init__.py 2009-10-23 00:48:47 +0000
+++ lib/canonical/launchpad/fields/__init__.py 2009-11-05 16:52:54 +0000
@@ -203,13 +203,14 @@

     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):

« Back to merge proposal