Commit de2c7d9f authored by Justin Bronn's avatar Justin Bronn
Browse files

[1.1.X] Fixed #12390 -- `Distance` and `Area` objects now support...

[1.1.X] Fixed #12390 -- `Distance` and `Area` objects now support multiplication when they are the right-hand side.

Backport of r11898 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11899 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent de649700
Loading
Loading
Loading
Loading
+28 −22
Original line number Diff line number Diff line
@@ -225,6 +225,9 @@ class Distance(MeasureBase):
        else:
            raise TypeError('Distance must be multiplied with number')

    def __rmul__(self, other):
        return self * other

    def __div__(self, other):
        if isinstance(other, (int, float, long, Decimal)):
            return Distance(default_unit=self._default_unit, m=(self.m / float(other)))
@@ -309,6 +312,9 @@ class Area(MeasureBase):
        else:
            raise TypeError('Area must be multiplied with number')

    def __rmul__(self, other):
        return self * other

    def __div__(self, other):
        if isinstance(other, (int, float, long, Decimal)):
            return Area(default_unit=self._default_unit, sq_m=(self.sq_m / float(other)))
+4 −1
Original line number Diff line number Diff line
@@ -95,6 +95,8 @@ class DistanceTest(unittest.TestCase):

        d3 = d1 * 2
        self.assertEqual(d3.m, 200)
        d3 = 2 * d1
        self.assertEqual(d3.m, 200)
        d3 *= 5
        self.assertEqual(d3.m, 1000)
        
@@ -248,6 +250,8 @@ class AreaTest(unittest.TestCase):

        a3 = a1 * 2
        self.assertEqual(a3.sq_m, 200)
        a3 = 2 * a1
        self.assertEqual(a3.sq_m, 200)
        a3 *= 5
        self.assertEqual(a3.sq_m, 1000)
        
@@ -319,7 +323,6 @@ class AreaTest(unittest.TestCase):
        self.assertEqual(repr(a1), 'Area(sq_m=100.0)')
        self.assertEqual(repr(a2), 'Area(sq_km=3.5)')

        
def suite():
    s = unittest.TestSuite()
    s.addTest(unittest.makeSuite(DistanceTest))