On Jul 23, 2011, at 9:19 AM, Ross Peoples wrote:

> In my welcome app's db.py file, this is what I use to switch to the mobile 
> view:
> 
> if request.is_mobile and request.extension == 'html':
>     mobile_view = os.path.join(
>         request.controller, request.function + '.mobile.html'
>     )
>     
>     if os.path.exists(os.path.join(request.folder, 'views', mobile_view)):
>         response.view = mobile_view
> 
> So really, to use a different name for the mobile files, you would just 
> change the one line in the db.py. I didn't really know where to put this in 
> web2py's code, so I just put it in db.py for now. Do you think there is a 
> better way to do this?

I think it could be more general, perhaps. Some thoughts.

1. Might it be possible to use a views subdirectory, perhaps? So more like 
os.path.join('mobile', controller, function + whatever)?

2. is_mobile should perhaps have better resolution. It's already not too 
unusual to have separate iPhone and iPad pages, for example. So rather than 
yes/no, an indication of the kind of device? Not sure how it would make sense 
to do that; perhaps with a collection of properties. Apps that didn't care to 
discriminate could simply test for generic mobile, but apps that cared could 
look at the details.

3. Related to (2), the ability to choose whether a pad got the mobile or main 
view, or its own view.

Reply via email to