Sizefield default value with different localization
kviktor opened this issue · 1 comments
The default value for sizefield with different languages for our form is:
english: 10.0GB
hungarian: 10,0GB (note the comma)
The code for our form:
size = forms.CharField(
widget=FileSizeWidget, initial=(10 << 30), label=_('Size'),
help_text=_('Size of xy to create in bytes or with units '
like MB or GB.'))
The end of the traceback (full):
File "/site-packages/django/forms/forms.py", line 425, in __str__
return self.as_widget()
File "/site-packages/django/forms/forms.py", line 475, in as_widget
return widget.render(name, self.value(), attrs=attrs)
File "site-packages/sizefield/widgets.py", line 11, in render
value = filesizeformat(value)
File "site-packages/sizefield/utils.py", line 35, in filesizeformat
raise ValueError
ValueError
The english 10.0GB is fine, the error occurs when the site is switched to hungarian, then the default value is 10,0GB. (also note that the comma version is the way numbers are written in hungarian, so the problem is not with default value, but the processing part)
Thanks for reporting this !
Indeed, we have the same in french :)
I won't have time to invest on this library. If any has time and the skills, please open a pull-request :
You could change the following regex :
https://github.com/leplatrem/django-sizefield/blob/master/sizefield/utils.py#L14
And unlocalize the value before parsing it to float here :
https://github.com/leplatrem/django-sizefield/blob/master/sizefield/utils.py#L66