Code

Opened 15 months ago

Closed 15 months ago

Last modified 4 months ago

#19583 closed New feature (wontfix)

FloatFields won't accept locale separators

Reported by: sylvain.lebon@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The locale decimal separator is used when generating a template using a floatfield. But if the same value is passed back to the model, it raises an exception: "invalid literal for float()".
This means that a form including <input value="{{mymodel.myfloatfield}}" /> won't work, which seems inconsistent to me.

Attachments (0)

Change History (6)

comment:1 Changed 15 months ago by akaariai

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

To me this seems like working as expected.

The localization formats are for input/output between the user and Django. It is supposed that you do input validation/conversions using Django's forms. If not, then you should do input validation by hand, that is you are responsible for converting POST['myfloatfield'] to Python's accepted float formats.

In short, the model layer should not know about the localization formats. The conversions from localized to Python formats should happen in upper layers of the code.

comment:2 Changed 15 months ago by anonymous

  • Component changed from Database layer (models, ORM) to contrib.formtools
  • Resolution invalid deleted
  • Status changed from closed to new
  • Type changed from Bug to New feature

I understand. Then I think Django lacks a tool to validate data without the whole form machinery, e.g. updating just one field through Ajax. I reopen it as a feature request, unless I am not aware of this feature somehow already existing.

comment:3 Changed 15 months ago by charettes

  • Component changed from contrib.formtools to Database layer (models, ORM)

You should use forms to validate/sanitize inputs, even if it's just for a single value.

That's what they are made for.

The fact that you're updating a model through Ajax makes no difference at all.

comment:4 Changed 15 months ago by aaugustin

  • Resolution set to wontfix
  • Status changed from new to closed

I confirmed what Anssi and Simon said.

The model layer shouldn't know about localization. Otherwise we'll introduce excessive coupling.

comment:5 Changed 15 months ago by anonymous

I'm not sure to understand how to do that. Am I supposed to create one different Form class for every single field I want to update this way?

comment:6 Changed 4 months ago by libraM@…

For Django >= 1.6, comment:4:ticket:18509 may help.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.