Automatically trim newforms text fields

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
def make_trimming(field):
    def clean_hook(self, old_clean, value):
        result = old_clean(value)
        if isinstance(result, (str, unicode,)):
            result = result.strip()
        return result
    old_clean = field.clean
    import new
    field.clean = new.instancemethod(
        lambda self, value: clean_hook(self, old_clean, value),
        field, field.__class__)

More like this

  1. DefaultValueWidget by miracle2k 5 years, 10 months ago
  2. filter/search a newforms select widget by miracle2k 5 years, 8 months ago
  3. Load templatetag libraries via settings by miracle2k 5 years, 10 months ago
  4. "Approved" field with timestamp by miracle2k 5 years, 10 months ago
  5. SeparatedValuesField by jezdez 5 years, 5 months ago

Comments

(Forgotten your password?)