X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=bluechips%2Flib%2Fhelpers.py;h=0f49a54b6293f6175f1fef9c120296b112a0fb65;hb=4eb26869c8a67e39b0444a0b57a9df26f7b6e950;hp=8da5a575b21d8adf6b6f619147ea416b0f5729c3;hpb=9cc05ca9160a9432d037afb9cc22c511e2542947;p=bluechips.git diff --git a/bluechips/lib/helpers.py b/bluechips/lib/helpers.py index 8da5a57..0f49a54 100644 --- a/bluechips/lib/helpers.py +++ b/bluechips/lib/helpers.py @@ -3,6 +3,10 @@ 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 * @@ -10,7 +14,6 @@ from webhelpers.html.secure_form import * from webhelpers.pylonslib import Flash as _Flash -from decimal import Decimal def currency(name, value, *args, **kwargs): if 'class_' not in kwargs: @@ -19,4 +22,18 @@ def currency(name, value, *args, **kwargs): value = "%0.2f" % (int(value) / 100.) return text(name, value, *args, **kwargs) + +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()