roskakori / cutplace

validate data stored in CSV, PRN, ODS or Excel files
http://cutplace.readthedocs.org/
GNU Lesser General Public License v3.0
18 stars 20 forks source link

Impossible to set range on Integers:"must be within range: '-2147483648:2147483647'" #43

Closed roskakori closed 12 years ago

roskakori commented 12 years ago

Original request by SourceForge user rufus-devrel:

It is impossible to change the range (length) of Integer fields: length is ignored.

Please change fields.py:IntegerFieldFormat:init from self.rangeRule = ranges.Range(rule, length) to: if not length: length = IntegerFieldFormat._DEFAULT_RANGE self.rangeRule = ranges.Range(rule, length)

Version information: cutplace 0.6.8 (2011-07-26, r541) Python 2.6.5, Linux-2.6.38.8-gg683-x86_64-with-Ubuntu-10.04-lucid

Specific error: error: 100-data.csv (R2C1): field u'customer_id' must match format: value is 9999125515L but must be within range: '-2147483648:2147483647'

roskakori commented 12 years ago

The length parameter describes the number of characters the field must have.

In order to change the valid range of an IntegerField, use the rule parameter.

Example:

integerField = fields.IntegerFieldFormat('testField', False, length=None, rule='0:9999999999', data.createDataFormat(data.FORMAT_CSV)
print integerField.validated('9999125515')

So the existing code should already be correct.

roskakori commented 12 years ago

Feedback from SourceForge user rufus-devrel:

Thanks. Fix to user is confirmed :-)