]> asedeno.scripts.mit.edu Git - bluechips.git/blobdiff - bluechips/lib/helpers.py
Convert the README to rST, since that's what distutils wants.
[bluechips.git] / bluechips / lib / helpers.py
index 4bb357663737b58c3dc15477f3fa77a8629e0529..0f49a54b6293f6175f1fef9c120296b112a0fb65 100644 (file)
@@ -3,18 +3,37 @@
 Consists of functions to typically be used within templates, but also
 available to Controllers. This module is available to both as 'h'.
 """
 Consists of functions to typically be used within templates, but also
 available to Controllers. This module is available to both as 'h'.
 """
+from datetime import date
+from decimal import Decimal
+
+from pylons import request
 from routes import url_for, redirect_to
 from webhelpers.html import escape, literal, url_escape
 from webhelpers.html.tags import *
 from routes import url_for, redirect_to
 from webhelpers.html import escape, literal, url_escape
 from webhelpers.html.tags import *
+from webhelpers.html.secure_form import *
 
 from webhelpers.pylonslib import Flash as _Flash
 
 
 from webhelpers.pylonslib import Flash as _Flash
 
-from decimal import Decimal
 
 
-def bluechips():
-    return '<span class="bluechips">BlueChips</span>'
+def currency(name, value, *args, **kwargs):
+    if 'class_' not in kwargs:
+        kwargs['class_'] = ''
+    kwargs['class_'] += 'currency'
+    value = "%0.2f" % (int(value) / 100.)
+    return text(name, value, *args, **kwargs)
+
 
 
-def round_currency(value):
-    return Decimal(value).quantize(Decimal('0.01'))
+def grab(obj, attr):
+    if obj:
+        return getattr(obj, attr)
+    else:
+        if attr == 'date':
+            return date.today()
+        elif attr in ('spender_id', 'creditor_id', 'debtor_id'):
+            return request.environ['user'].id
+        elif attr == 'amount':
+            return 0
+        else:
+            return ''
 
 flash = _Flash()
 
 flash = _Flash()