[formwidgets] move TextArea constants to the class level
authorAurelien Campeas <aurelien.campeas@pythonian.fr>
Wed, 03 Jun 2015 12:36:31 +0200
changeset 10404 797db633d60c
parent 10403 fe614ec1688c
child 10405 7b27a7443180
[formwidgets] move TextArea constants to the class level This will make it easy to override them.
web/formwidgets.py
--- a/web/formwidgets.py	Mon Jun 22 12:23:50 2015 +0200
+++ b/web/formwidgets.py	Wed Jun 03 12:36:31 2015 +0200
@@ -400,6 +400,9 @@
 
 class TextArea(FieldWidget):
     """Simple <textarea>, will return a unicode string."""
+    _minrows = 2
+    _maxrows = 15
+    _columns = 80
 
     def _render(self, form, field, renderer):
         values, attrs = self.values_and_attributes(form, field)
@@ -413,9 +416,9 @@
         lines = value.splitlines()
         linecount = len(lines)
         for line in lines:
-            linecount += len(line) / 80
-        attrs.setdefault('cols', 80)
-        attrs.setdefault('rows', min(15, linecount + 2))
+            linecount += len(line) / self._columns
+        attrs.setdefault('cols', self._columns)
+        attrs.setdefault('rows', min(self._maxrows, linecount + self._minrows))
         return tags.textarea(value, name=field.input_name(form, self.suffix),
                              **attrs)