HI Ross, Massimo,

I wrote a small decorator to use the newly added is_mobile flag:

class mobilize(object):
    def __init__(self, func):
        self.func = func
    def __call__(self):
        from gluon import current
        if current.session._user_agent:
            if current.session._user_agent.is_mobile:
                current.response.view = \
                    current.response.view.split(".")[0] + ".mobi"
        return self.func()

It should be included at the bottom of user_agent_parser.py.

With this you can have automatically selected the view.html or the
view.mobi depending on your browser is mobile or not, an example could
be:

@mobilize
def index():
    """
    example action using the mobilizer decorator it is
    rendered by views/default/index.html or
    views/default/index.mobi depending if your browser
    is mobile or not
    """
    return dict(message=response.view)

Could this be added in trunk?

2011/8/27 Massimo Di Pierro <massimo.dipie...@gmail.com>:
> This is in trunk as of last night.
>
> On Aug 26, 12:13 pm, Ross Peoples <ross.peop...@gmail.com> wrote:
>> I submitted this to Massimo for inclusion. Now we wait :)

Reply via email to