From 28c9c65bb98e6981a516a64850744335bf36f81b Mon Sep 17 00:00:00 2001 From: Scott Torborg Date: Wed, 11 Nov 2009 10:46:34 -0800 Subject: [PATCH] began work on iphone-targeted web interface --- bluechips/controllers/status.py | 1 + bluechips/lib/base.py | 17 ++- bluechips/public/css/mobile.css | 39 ++++++ bluechips/public/icons/apple-touch.png | Bin 0 -> 436 bytes bluechips/public/js/mobile.js | 20 +++ bluechips/templates/mobile/base.mako | 31 +++++ bluechips/templates/mobile/error.mako | 5 + bluechips/templates/mobile/status/index.mako | 130 +++++++++++++++++++ bluechips/templates/spend/index.mako | 4 - 9 files changed, 241 insertions(+), 6 deletions(-) create mode 100644 bluechips/public/css/mobile.css create mode 100644 bluechips/public/icons/apple-touch.png create mode 100644 bluechips/public/js/mobile.js create mode 100644 bluechips/templates/mobile/base.mako create mode 100644 bluechips/templates/mobile/error.mako create mode 100644 bluechips/templates/mobile/status/index.mako diff --git a/bluechips/controllers/status.py b/bluechips/controllers/status.py index 04ad79b..7e81cd5 100644 --- a/bluechips/controllers/status.py +++ b/bluechips/controllers/status.py @@ -66,6 +66,7 @@ class StatusController(BaseController): model.Transfer.debtor==request.environ['user'], model.Transfer.creditor==request.environ['user'])).\ limit(10).all() + c.users = meta.Session.query(model.User.id, model.User) return render('/status/index.mako') diff --git a/bluechips/lib/base.py b/bluechips/lib/base.py index 586336c..8e7c20c 100644 --- a/bluechips/lib/base.py +++ b/bluechips/lib/base.py @@ -2,12 +2,15 @@ Provides the BaseController class for subclassing. """ + from decorator import decorator -from pylons import request, tmpl_context as c +from pylons import request, session, tmpl_context as c from pylons.controllers import WSGIController from pylons.i18n import _, ungettext, N_ -from pylons.templating import render_mako as render +from pylons.templating import render_mako + +from mako.exceptions import TopLevelLookupException import bluechips.lib.helpers as h from bluechips import model @@ -48,6 +51,16 @@ def redirect_on_get(action): return func(*args, **kwargs) return redirect_on_get_wrap +def render(name, *args, **kwargs): + if 'iPhone' in request.user_agent: + if session.get('use_non_mobile'): + c.mobile_client = True + else: + try: + return render_mako('/mobile' + name, *args, **kwargs) + except TopLevelLookupException: + pass + return render_mako(name, *args, **kwargs) __all__ = ['c', 'h', 'render', 'model', 'meta', '_', 'ungettext', 'N_', 'BaseController', 'update_sar', 'redirect_on_get'] diff --git a/bluechips/public/css/mobile.css b/bluechips/public/css/mobile.css new file mode 100644 index 0000000..e79d9e5 --- /dev/null +++ b/bluechips/public/css/mobile.css @@ -0,0 +1,39 @@ +body { + width: auto; + font-size: 1em; +} +#tabs img { + width: 64px; + height: 64px; +} +#tabs a { + text-align: center; + display: block; + width: 98px; + float: left; + border-top: 1px solid #fff; + border-bottom: 1px solid #000; + padding: 5px 1px; +} +#tabs a.selected { + border: 1px solid #000; + border-bottom: 1px solid #fff; + padding: 5px 0; + -webkit-border-top-left-radius: 10px; + -webkit-border-top-right-radius: 10px; +} +#tabs:after { + content: "."; + display: block; + clear: both; + visibility: hidden; + line-height: 0; + height: 0; + margin-bottom: 10px; +} +div.tab { + display: none; +} +#tab-status { + display: block; +} diff --git a/bluechips/public/icons/apple-touch.png b/bluechips/public/icons/apple-touch.png new file mode 100644 index 0000000000000000000000000000000000000000..bce6f9d51dad04f2c7bac0109d876ff37fe8e1b3 GIT binary patch literal 436 zcmV;l0ZaagP)H$2O|nR>`LCs`x`nZylHi-n=dK39yak(*-blCoV(U`fc1B%D;!WcI}2 zWXc`#FuC$~SH`4kXf#N&7Iz7f`Vv=Yvi&sKGQVlj5E{=_R|wT=y6knK5S#8(f>3kb zDmK8Ix?Xmggj)P0PhTuBQffDmrejnp>QJ%;%AjN&I{}k4O%``FOqPoVm|TZaWUPNB z%P*=EBJ(`$FQgqa#pI1il-F&2G4yh4_>H==a!0CufQ0-64h}Y@*MbpPn^a3X=n3|J e-+oyS0R{m5I|n6NUfP8K0000 + + + + ${self.title()} + ${h.stylesheet_link('/css/main.css')} + + + + + + ${next.body()} + ${h.javascript_link('/js/jquery-1.3.2.js')} + ${h.javascript_link('/js/mobile.js')} + + + +<%def name="title()">BlueChips +% if c.title != '': + :: ${c.title} +% endif + + +<%def name="formatUser(user)"> + % if user == request.environ['user']: + Me + % else: + ${user.name} + % endif + diff --git a/bluechips/templates/mobile/error.mako b/bluechips/templates/mobile/error.mako new file mode 100644 index 0000000..bb891c7 --- /dev/null +++ b/bluechips/templates/mobile/error.mako @@ -0,0 +1,5 @@ +<%inherit file="/mobile/base.mako"/> + +

${c.code}

+ +

Return diff --git a/bluechips/templates/mobile/status/index.mako b/bluechips/templates/mobile/status/index.mako new file mode 100644 index 0000000..08069e1 --- /dev/null +++ b/bluechips/templates/mobile/status/index.mako @@ -0,0 +1,130 @@ +<%inherit file="/mobile/base.mako"/> + +<%! + from datetime import date +%> + + + +
+ % for message in h.flash.pop_messages(): +
${message | n}
+ % endfor + + % if len(c.settle) == 0: +

No need! The books are balanced!

+ % else: +

To balance the books, the following transfers need to be made:

+ + + + + + + + % for transfer in c.settle: + + + + + + % endfor +
FromToAmount
${transfer[0].name}${transfer[1].name}${transfer[2]}
+ % endif +
+ +
+
+ ${h.auth_token_hidden_field()} + + + + + + + + + + + + + + + + + +
${h.select('spender_id', [request.environ['user'].id], c.users)}
${h.currency('amount', 0, size=8)}
${h.text('date', date.today().strftime('%m/%d/%Y'), size=16)}
${h.text('description')}
+ +

Change how an expenditure is split up.

+ + + % for ii, user_row in enumerate(c.users): + <% + user_id, user = user_row + if user.resident: + percent = 1 + else: + percent = 0 + %> + + + + + % endfor + + + +
+ ${h.text('shares-%d.amount' % ii, percent)} + ${h.hidden('shares-%d.user_id' % ii, user.id)} +
+ ${h.submit(None, 'Submit', class_="submitbutton")} +
+
+
+ +
+
+ ${h.auth_token_hidden_field()} + + + + + + + + + + + + + + + + + + + + + + + + +
${h.select('debtor_id', request.environ['user'].id, c.users)}
${h.select('creditor_id', None, c.users)}
${h.currency('amount', 0, size=8)}
${h.text('date', date.today().strftime('%m/%d/%Y'), size=16)}
${h.text('description')}
+ +
+
+
diff --git a/bluechips/templates/spend/index.mako b/bluechips/templates/spend/index.mako index ff388a3..1b0c6e3 100644 --- a/bluechips/templates/spend/index.mako +++ b/bluechips/templates/spend/index.mako @@ -1,9 +1,5 @@ <%inherit file="/base.mako"/> -<%! - from decimal import Decimal -%> -
${h.auth_token_hidden_field()} -- 2.45.2