]> asedeno.scripts.mit.edu Git - bluechips.git/commitdiff
Add some documentation to the Currency type
authorEvan Broder <broder@mit.edu>
Fri, 18 Jul 2008 17:15:00 +0000 (17:15 +0000)
committerEvan Broder <broder@mit.edu>
Fri, 18 Jul 2008 17:15:00 +0000 (17:15 +0000)
bluechips/model/types.py

index 1c54e764fb91e4d6907f68575cab22ffb6f59b17..4de0033c3a2b8b86c7256210b8f13ef655382567 100644 (file)
@@ -6,6 +6,9 @@ import sqlalchemy as sa
 from bluechips.lib.subclass import SmartSubclass
 
 class Currency(object):
 from bluechips.lib.subclass import SmartSubclass
 
 class Currency(object):
+    """
+    Store currency values as an integral number of cents
+    """
     __metaclass__ = SmartSubclass(int)
     def __init__(self, value):
         if isinstance(value, str):
     __metaclass__ = SmartSubclass(int)
     def __init__(self, value):
         if isinstance(value, str):
@@ -14,24 +17,51 @@ class Currency(object):
             self.value = int(value)
     
     def __int__(self):
             self.value = int(value)
     
     def __int__(self):
+        """
+        If I don't define this, SmartSubclass will return
+        Currency(int(self.value))
+        """
         return self.value
     def __float__(self):
         return self.value
     def __float__(self):
+        """
+        If I don't define this, SmartSubclass will return
+        Currency(float(self.value))
+        """
         return float(self.value)
     def __long__(self):
         return float(self.value)
     def __long__(self):
+        """
+        If I don't define this, SmartSubclass will return
+        Currency(long(self.value))
+        """
         return long(self.value)
     
     def __cmp__(self, other):
         return long(self.value)
     
     def __cmp__(self, other):
-        try:
+        """
+        This is overridden for when validators compare a Currency to
+        ''
+        """
+        if other == '':
+            return 1
+        else:
             return self.value.__cmp__(int(other))
             return self.value.__cmp__(int(other))
-        except:
-            return self.value.__cmp__(0)
     
     def __mul__(self, other):
     
     def __mul__(self, other):
+        """
+        If I don't define this, SmartSubclass will convert the other
+        argument to an int
+        """
         return Currency(self.value * other)
     def __rmul__(self, other):
         return Currency(self.value * other)
     def __rmul__(self, other):
+        """
+        If I don't define this, SmartSubclass will convert the other
+        argument to an int
+        """
         return self.__mul__(other)
     
     def __str_no_dollar__(self):
         return self.__mul__(other)
     
     def __str_no_dollar__(self):
+        """
+        Get to the formatted string without the dollar sign
+        """
         return str(self)[1:]
     
     def __repr__(self):
         return str(self)[1:]
     
     def __repr__(self):