merge master into improve-health-2

This commit is contained in:
Stefan Wojcik 2016-12-11 15:02:51 -05:00
commit dc15195dd8
5 changed files with 43 additions and 14 deletions

View File

@ -242,3 +242,4 @@ that much better:
* xiaost7 (https://github.com/xiaost7) * xiaost7 (https://github.com/xiaost7)
* Victor Varvaryuk * Victor Varvaryuk
* Stanislav Kaledin (https://github.com/sallyruthstruik) * Stanislav Kaledin (https://github.com/sallyruthstruik)
* Dmitry Yantsen (https://github.com/mrTable)

View File

@ -2,11 +2,25 @@
Changelog Changelog
========= =========
Development
===========
- Fixed absent rounding for DecimalField when `force_string` is set. #1103
Changes in 0.10.8 Changes in 0.10.8
================= =================
- Added support for QuerySet.batch_size (#1426)
- Fixed query set iteration within iteration #1427
- Fixed an issue where specifying a MongoDB URI host would override more information than it should #1421
- Added ability to filter the generic reference field by ObjectId and DBRef #1425
- Fixed delete cascade for models with a custom primary key field #1247
- Added ability to specify an authentication mechanism (e.g. X.509) #1333 - Added ability to specify an authentication mechanism (e.g. X.509) #1333
- Added support for falsey primary keys (e.g. doc.pk = 0) #1354 - Added support for falsey primary keys (e.g. doc.pk = 0) #1354
- Fixed BaseQuerySet#sum/average for fields w/ explicit db_field #1417 - Fixed QuerySet#sum/average for fields w/ explicit db_field #1417
- Fixed filtering by embedded_doc=None #1422
- Added support for cursor.comment #1420
- Fixed doc.get_<field>_display #1419
- Fixed __repr__ method of the StrictDict #1424
- Added a deprecation warning for Python 2.6
Changes in 0.10.7 Changes in 0.10.7
================= =================

View File

@ -23,7 +23,7 @@ __all__ = (list(document.__all__) + list(fields.__all__) +
list(signals.__all__) + list(errors.__all__)) list(signals.__all__) + list(errors.__all__))
VERSION = (0, 10, 7) VERSION = (0, 10, 9)
def get_version(): def get_version():

View File

@ -326,7 +326,7 @@ class DecimalField(BaseField):
if value is None: if value is None:
return value return value
if self.force_string: if self.force_string:
return six.text_type(value) return six.text_type(self.to_python(value))
return float(self.to_python(value)) return float(self.to_python(value))
def validate(self, value): def validate(self, value):

View File

@ -478,27 +478,41 @@ class FieldTest(unittest.TestCase):
def test_decimal_storage(self): def test_decimal_storage(self):
class Person(Document): class Person(Document):
btc = DecimalField(precision=4) float_value = DecimalField(precision=4)
string_value = DecimalField(precision=4, force_string=True)
Person.drop_collection() Person.drop_collection()
Person(btc=10).save() values_to_store = [10, 10.1, 10.11, "10.111", Decimal("10.1111"), Decimal("10.11111")]
Person(btc=10.1).save() for store_at_creation in [True, False]:
Person(btc=10.11).save() for value in values_to_store:
Person(btc="10.111").save() # to_python is called explicitly if values were sent in the kwargs of __init__
Person(btc=Decimal("10.1111")).save() if store_at_creation:
Person(btc=Decimal("10.11111")).save() Person(float_value=value, string_value=value).save()
else:
person = Person.objects.create()
person.float_value = value
person.string_value = value
person.save()
# How its stored # How its stored
expected = [{'btc': 10.0}, {'btc': 10.1}, {'btc': 10.11}, expected = [
{'btc': 10.111}, {'btc': 10.1111}, {'btc': 10.1111}] {'float_value': 10.0, 'string_value': '10.0000'},
{'float_value': 10.1, 'string_value': '10.1000'},
{'float_value': 10.11, 'string_value': '10.1100'},
{'float_value': 10.111, 'string_value': '10.1110'},
{'float_value': 10.1111, 'string_value': '10.1111'},
{'float_value': 10.1111, 'string_value': '10.1111'}]
expected.extend(expected)
actual = list(Person.objects.exclude('id').as_pymongo()) actual = list(Person.objects.exclude('id').as_pymongo())
self.assertEqual(expected, actual) self.assertEqual(expected, actual)
# How it comes out locally # How it comes out locally
expected = [Decimal('10.0000'), Decimal('10.1000'), Decimal('10.1100'), expected = [Decimal('10.0000'), Decimal('10.1000'), Decimal('10.1100'),
Decimal('10.1110'), Decimal('10.1111'), Decimal('10.1111')] Decimal('10.1110'), Decimal('10.1111'), Decimal('10.1111')]
actual = list(Person.objects().scalar('btc')) expected.extend(expected)
self.assertEqual(expected, actual) for field_name in ['float_value', 'string_value']:
actual = list(Person.objects().scalar(field_name))
self.assertEqual(expected, actual)
def test_boolean_validation(self): def test_boolean_validation(self):
"""Ensure that invalid values cannot be assigned to boolean fields. """Ensure that invalid values cannot be assigned to boolean fields.