#2760 closed defect (fixed)
[patch] Admin interface doesn't handle negative FloatFields
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
- Create a model with
FloatField(max_digits=8, decimal_places=5, blank=True)
- Use the Admin interface to set the FloatField to '-122.19217'
Expected:
Changes saved.
Bug:
- "Please correct the error below."
- "Please enter a valid decimal number with a whole part of at most 3 digits."
- Entry truncated to '-122.1921', because the HTML input can only take 9 characters (max_digits=8 plus the decimal separator '.')
Attachments (2)
Change History (9)
by , 18 years ago
Attachment: | validators.diff added |
---|
comment:1 by , 18 years ago
Summary: | Admin interface doesn't handle negative FloatFields → [patch] Admin interface doesn't handle negative FloatFields |
---|
I've attached a patch which changes the IsValidFloat
validator to allow an extra character in the float if it starts with a '-'; I'm not 100% certain, but I think this fixes the bug.
comment:2 by , 18 years ago
Thanx for the speedy patch. Patch didn't fix the issue, because the HTML <input> still only allows 9 characters, so len(data) POSTed to the view still is 9 chars long, so we never enter the negative-sign-handling code.
if len(data) > (self.max_digits + 1): max_allowed_length = data.startswith('-') and (self.max_digits + 2) or ...
We probably need to change the template/widget to have <input size="{{ max_digits + 2 }}">.
comment:3 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:5 by , 18 years ago
The asymmetry (both in the original patch and in this revised one) bothers me. It looks like we should be using max_allowed_length
or self.max_digits
consistently.
I'll test this out and commit a patch shortly. Sorry about screwing it up the first time; I didn't check it with my brain switched on.
comment:6 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
comment:7 by , 18 years ago
So r3845 seems to allow all legal combinations and rejects -1234, -123.456789, 1234, and 123.456789. I think that's got all the possibilities.
If I have missed a case, can you post the float that fails when you reopen, please.
Patch which hopefully fixes this