Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8a2b66a
Add test hack not for use in production
izquierdo Jan 5, 2016
62427db
fix a type error
rtpg Jun 6, 2016
6af1453
make sure to consistently set the _currency subfield as a string-like
rtpg Jun 6, 2016
efbecc2
revert previous type change
rtpg Jun 6, 2016
7322d5d
Merge remote-tracking branch 'rtpg/type-fix' into django19
izquierdo Jul 19, 2016
4e878ed
Add missing fields specification in test form
izquierdo Jul 19, 2016
99fba04
Extend hack
izquierdo Jul 19, 2016
059a56c
Merge remote-tracking branch 'poswald/master' into django19
izquierdo Jul 19, 2016
994047c
Change supported Django version to 1.9
izquierdo Jul 19, 2016
7c83d64
Remove warning about production usage
izquierdo Aug 29, 2016
60f4f81
Merge pull request #1 from izquierdo/django19
izquierdo Aug 29, 2016
7dbce18
Add symbol for MMK currency
izquierdo Oct 18, 2016
45f2128
Merge remote-tracking branch 'makeleaps/master' into mmk
izquierdo Oct 18, 2016
d7e07b6
Allow higher Django point releases
izquierdo Oct 18, 2016
173dd8b
Merge pull request #2 from izquierdo/mmk
izquierdo Oct 27, 2016
391ef48
Have the money field proxy descriptor behave properly
Jan 20, 2020
294eb72
Merge pull request #5 from rtpg/patch-1
izquierdo Jan 20, 2020
9ed3ec0
Replace deprecated _get_val_from_obj method
nashsibanda Sep 26, 2022
fc88a93
Merge pull request #6 from nashsibanda/remove-deprecated-get-val-from…
izquierdo Sep 27, 2022
1826c4e
Removes ugettext and uses gettext
Jan 19, 2024
995cf24
Merge pull request #7 from makeleaps/switch_to_gettext
VictorTan93 Jan 19, 2024
5fc39b6
Specify utf-8 encoding in Popen
nashsibanda Jul 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions money/contrib/django/models/fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from decimal import Decimal

from django.db import models
from django.utils.translation import ugettext_lazy
from django.utils.translation import gettext_lazy

from money.contrib.django import forms
from money.money import Money
Expand Down Expand Up @@ -58,6 +58,8 @@ def _set_values(self, obj, amount, currency):
obj.__dict__[self.field.currency_field_name] = currency

def __get__(self, obj, *args):
if obj is None:
return self
amount, currency = self._get_values(obj)
if amount is None:
return None
Expand All @@ -67,7 +69,7 @@ def __set__(self, obj, value):
if value is None: # Money(0) is False
self._set_values(obj, None, '')
elif isinstance(value, Money):
self._set_values(obj, value.amount, value.currency)
self._set_values(obj, value.amount, value.currency.code)
elif isinstance(value, Decimal):
_, currency = self._get_values(obj) # use what is currently set
self._set_values(obj, value, currency)
Expand Down Expand Up @@ -126,12 +128,12 @@ def value_to_string(self, obj):
When serializing, we want to output as two values. This will be just
the currency part as stored directly in the database.
"""
value = self._get_val_from_obj(obj)
value = self.value_from_object(obj)
return value


class MoneyField(InfiniteDecimalField):
description = ugettext_lazy('An amount and type of currency')
description = gettext_lazy('An amount and type of currency')

# Don't extend SubfieldBase since we need to have access to both fields when
# to_python is called. We need our code there instead of subfieldBase
Expand Down Expand Up @@ -248,14 +250,20 @@ def value_to_string(self, obj):
Here we only need to output the value. The contributed currency field
will get called to output itself
"""
value = self._get_val_from_obj(obj)
value = self.value_from_object(obj)
return value.amount

def formfield(self, **kwargs):
defaults = {'form_class': forms.MoneyField}
defaults.update(kwargs)
return super(MoneyField, self).formfield(**defaults)

@property
def validators(self):
# Hack around the fact that we inherit from DecimalField but don't hold
# Decimals. The real fix is to stop inheriting from DecimalField.
return []


# South introspection rules
# (see http://south.aeracode.org/docs/customfields.html#extending-introspection)
Expand Down
2 changes: 1 addition & 1 deletion money/money.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def __ge__(self, other):
CURRENCY['MDL'] = Currency(code='MDL', numeric='498', decimals=2, symbol=u'', name=u'Moldovan Leu', countries=[u'MOLDOVA, REPUBLIC OF'])
CURRENCY['MGA'] = Currency(code='MGA', numeric='969', decimals=2, symbol=u'', name=u'Malagasy Ariary', countries=[u'MADAGASCAR'])
CURRENCY['MKD'] = Currency(code='MKD', numeric='807', decimals=2, symbol=u'ден', name=u'Denar', countries=[u'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF'])
CURRENCY['MMK'] = Currency(code='MMK', numeric='104', decimals=2, symbol=u'', name=u'Kyat', countries=[u'MYANMAR'])
CURRENCY['MMK'] = Currency(code='MMK', numeric='104', decimals=2, symbol=u'K', name=u'Kyat', countries=[u'MYANMAR'])
CURRENCY['MNT'] = Currency(code='MNT', numeric='496', decimals=2, symbol=u'₮', name=u'Tugrik', countries=[u'MONGOLIA'])
CURRENCY['MOP'] = Currency(code='MOP', numeric='446', decimals=2, symbol=u'', name=u'Pataca', countries=[u'MACAO'])
CURRENCY['MRO'] = Currency(code='MRO', numeric='478', decimals=2, symbol=u'', name=u'Ouguiya', countries=[u'MAURITANIA'])
Expand Down
1 change: 1 addition & 0 deletions money/tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SampleForm(forms.Form):
class SampleModelForm(forms.ModelForm):
class Meta:
model = SimpleMoneyModel
fields = '__all__'

fields = (
'name',
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def run_tests(self):
tests_require = [
'pytest-django',
'pytest-cov',
'django<1.9',
'django<1.10',
'psycopg2',
'six',
]
Expand All @@ -48,7 +48,7 @@ def run_tests(self):
]

extras_require = {
'django': ['Django < 1.8', ],
'django': ['Django<1.10', ],
}

dependency_links = []
Expand Down
8 changes: 6 additions & 2 deletions version.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ def call_git_describe(abbrev=5):

"""
try:
p = Popen(['git', 'describe', '--long', '--tags', '--always',
'--abbrev=%d' % abbrev], stdout=PIPE, stderr=PIPE)
p = Popen(
['git', 'describe', '--long', '--tags', '--always', '--abbrev=%d' % abbrev],
stdout=PIPE,
stderr=PIPE,
encoding='utf-8',
)
p.stderr.close()
line = p.stdout.readlines()[0].strip()

Expand Down