From: Scott Torborg Date: Fri, 13 Nov 2009 01:17:57 +0000 (-0800) Subject: Merge branch 'master' into mobile_interface X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=0b9f273d12cbbe8790c4a9dec14d282a461e54be;hp=7d903a1a2ac54a31a66841051a96940060f7975e;p=bluechips.git Merge branch 'master' into mobile_interface --- 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 0000000..bce6f9d Binary files /dev/null and b/bluechips/public/icons/apple-touch.png differ diff --git a/bluechips/public/js/mobile.js b/bluechips/public/js/mobile.js new file mode 100644 index 0000000..6d01307 --- /dev/null +++ b/bluechips/public/js/mobile.js @@ -0,0 +1,20 @@ +try { + console.log("init"); +} catch(e) { + console = { log: function() {} }; +} + +$(function() { + console.log("ready()"); + + $('#tabs a').click(function() { + $('div.tab').hide(); + $('#tabs a').removeClass('selected'); + $(this).addClass('selected'); + $('#tab-' + $(this).attr('id')).show(); + return false; + }); + + console.log("ready() done"); +}); + diff --git a/bluechips/templates/mobile/base.mako b/bluechips/templates/mobile/base.mako new file mode 100644 index 0000000..fa2ea6d --- /dev/null +++ b/bluechips/templates/mobile/base.mako @@ -0,0 +1,31 @@ + + + + + ${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()}