Ticket #4468: oldforms-field_length-validation.diff

File oldforms-field_length-validation.diff, 1.0 KB (added by A. Murat Eren <meren@…>, 17 years ago)
  • oldforms/__init__.py

     
    388388            self.member_name = member_name
    389389
    390390    def isValidLength(self, data, form):
    391         if data and self.maxlength and len(data.decode(settings.DEFAULT_CHARSET)) > self.maxlength:
    392             raise validators.ValidationError, ngettext("Ensure your text is less than %s character.",
    393                 "Ensure your text is less than %s characters.", self.maxlength) % self.maxlength
     391        data_length = len(data.decode(settings.DEFAULT_CHARSET))
     392        if data and self.maxlength and data_length > self.maxlength:
     393            raise validators.ValidationError, ngettext("Ensure your text is less than %s character (it is %s).",
     394                "Ensure your text is less than %s characters (it is %s).", self.maxlength) % (self.maxlength, data_length)
    394395
    395396    def hasNoNewlines(self, data, form):
    396397        if data and '\n' in data:
Back to Top