Skip to content

Conversation

@mmarta
Copy link
Contributor

@mmarta mmarta commented Apr 26, 2017

This will now use rounding direction in RoundedDecimalField if specified.

@coveralls
Copy link

coveralls commented Apr 26, 2017

Coverage Status

Coverage increased (+0.007%) to 99.396% when pulling d710d22 on mmarta:master into 8669b20 on dealertrack:master.

@coveralls
Copy link

coveralls commented Apr 26, 2017

Coverage Status

Coverage increased (+0.002%) to 99.391% when pulling a0862f8 on mmarta:master into 8669b20 on dealertrack:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 99.391% when pulling a0862f8 on mmarta:master into 8669b20 on dealertrack:master.

def to_internal_value(self, data):
return self.quantize(super(RoundedDecimalField, self).to_internal_value(data))
def quantize(self, value):
if self.max_digits is None and isinstance(value, float):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is no longer a DecimalField if it will return float in some cases. it must return float in all cases unless its not required field and value is not provided

)

def to_internal_value(self, data):
return self.quantize(super(RoundedDecimalField, self).to_internal_value(data))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

older versions of DRF dont always call quantize on validation https://github.com/encode/django-rest-framework/blob/3.2.5/rest_framework/fields.py#L935

@mmarta mmarta changed the title Modifying so floats can be used in RoundedDecimalField Modifying to use rounding direction in RoundedDecimalField. May 2, 2017
return data


class RoundedDecimalField(fields.DecimalField):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is duplicating the class definition

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I think this happened when I merged or something.

Currency field subclass of Decimal used for rounding currencies
to two decimal places.
"""
rounding = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary as its redefined in `init

rounding = None

def __init__(self, max_digits=None, decimal_places=2, rounding=None, *args, **kwargs):
max_digits = max_digits or self.MAX_STRING_LENGTH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be safely removed as quantize does not add the context.prec when max digits is None. it was to prevent exceptions with older versions of DRF

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 99.006% when pulling da6205d on mmarta:master into efeb919 on dealertrack:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 99.006% when pulling da6205d on mmarta:master into efeb919 on dealertrack:master.

@coveralls
Copy link

coveralls commented May 5, 2017

Coverage Status

Coverage decreased (-0.4%) to 99.006% when pulling da6205d on mmarta:master into efeb919 on dealertrack:master.

def test_init(self):
field = RoundedDecimalField()
self.assertIsNotNone(field.max_digits)
self.assertEqual(field.decimal_places, 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add assert about rounding being set

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 99.006% when pulling baa298b on mmarta:master into efeb919 on dealertrack:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 99.006% when pulling baa298b on mmarta:master into efeb919 on dealertrack:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 99.006% when pulling baa298b on mmarta:master into efeb919 on dealertrack:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 99.006% when pulling baa298b on mmarta:master into efeb919 on dealertrack:master.

@coveralls
Copy link

coveralls commented May 5, 2017

Coverage Status

Coverage decreased (-0.4%) to 99.006% when pulling 3525ee1 on mmarta:master into efeb919 on dealertrack:master.

@coveralls
Copy link

coveralls commented May 5, 2017

Coverage Status

Coverage decreased (-0.4%) to 99.006% when pulling e4ea7c4 on mmarta:master into efeb919 on dealertrack:master.

@miki725 miki725 merged commit 2b4fc71 into dealertrack:master May 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants