[web2py] Re: Mobile detector

2011-09-13 Thread Massimo Di Pierro
Shouldn't this be from gluon.contrib.user_agent_parser import mobilize @mobilize ... On Sep 13, 3:22 am, Martin Weissenboeck wrote: > Hi, > > I have tried to test the user_agent_parser. At the top of default.py there > is > > from gluon.contrib import user_agent_parser > > @mobilize > def m():

Re: [web2py] Re: Mobile detector

2011-09-13 Thread Martin Weissenboeck
You are right - as always :-) Now it works. I have only copied the (wrong) example from this thead. 2011/9/13 Massimo Di Pierro > Shouldn't this be > > from gluon.contrib.user_agent_parser import mobilize > @mobilize > ... > > On Sep 13, 3:22 am, Martin Weissenboeck wrote: > > Hi, > > > > I h

Re: [web2py] Re: Mobile detector

2011-09-13 Thread Angelo Compagnucci
Hi Martin, You are right, but the previous trunk version it worked. Massimo, could you enlighten us? Thanks! 2011/9/13 Martin Weissenboeck : > Hi, > > I have tried to test the user_agent_parser. At the top of default.py there > is > > from gluon.contrib import user_agent_parser > > @mobilize >

Re: [web2py] Re: Mobile detector

2011-09-13 Thread Martin Weissenboeck
Hi, I have tried to test the user_agent_parser. At the top of default.py there is from gluon.contrib import user_agent_parser @mobilize def m(): ua = request.user_agent() if ua.is_mobile(): return dict(a='MOBILE') else: return dict(a='FIX') And I got: Traceback (mo

[web2py] Re: Mobile detector

2011-08-31 Thread Ross Peoples
Sorry guys, the hurricane did a number on the east coast and I haven't been able to keep up with the conversations. Good work yet again Angelo! I like the @mobilize decorator.

[web2py] Re: Mobile detector

2011-08-30 Thread Massimo Di Pierro
index.mobile.html is in trunk On Aug 30, 8:19 am, Angelo Compagnucci wrote: > I think that the extension should match the content, it's more clear. > > For a json object I'm expecting a .json, an xml should have an xml > extension and so on. So for the mobile view I think the best is to > have a

Re: [web2py] Re: Mobile detector

2011-08-30 Thread Angelo Compagnucci
I think that the extension should match the content, it's more clear. For a json object I'm expecting a .json, an xml should have an xml extension and so on. So for the mobile view I think the best is to have a .mobi extension, but this is IMHO. Also using the .mobile.html could be viable, becaus

[web2py] Re: Mobile detector

2011-08-30 Thread Massimo Di Pierro
Unless there is a strong objection I will modify the code in trunk to use index.mobile.html view = '.'.join(view.split().insert(-1,'mobile')) On Aug 30, 2:13 am, Bruno Rocha wrote: > On Tue, Aug 30, 2011 at 2:05 AM, Anthony wrote: > > Good point. Couldn't you also do something like index.mobi.h

Re: [web2py] Re: Mobile detector

2011-08-30 Thread Bruno Rocha
On Tue, Aug 30, 2011 at 2:05 AM, Anthony wrote: > Good point. Couldn't you also do something like index.mobi.html or > index.html.mobi? I don't think these view names would necessarily have to > be exposed as URLs -- they just need to be used server side to render the > page appropriately. It i

Re: [web2py] Re: Mobile detector

2011-08-29 Thread Anthony
Good point. Couldn't you also do something like index.mobi.html or index.html.mobi? I don't think these view names would necessarily have to be exposed as URLs -- they just need to be used server side to render the page appropriately. Anthony On Tuesday, August 30, 2011 12:01:53 AM UTC-4, roch

Re: [web2py] Re: Mobile detector

2011-08-29 Thread Bruno Rocha
I commented in Anthony notes, but I will replicate it here. --- I created my own mechanism for mobile detection, which I am using for a long time. So there is one thing I decided. It is better to prefix instead of suffix. so I named my views as mobile.index.html instead of index.mobi. why? ju

Re: [web2py] Re: Mobile detector

2011-08-29 Thread Angelo Compagnucci
Hi Maritn, In trunk you can now do: #only at the top of you controller from gluon.contrib import user_agent_parser @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

Re: [web2py] Re: Mobile detector

2011-08-29 Thread Martin Weissenboeck
Hi Angelo, it works now, thanks! Any ideas about the second question? There have been a lot of proposals how to change every view from .html to .m.html if is_mobile is true. Now I am a little bit confused: what would be the best code following if ua.is_mobile...? 2011/8/29 Angelo Compagnuc

Re: [web2py] Re: Mobile detector

2011-08-29 Thread Angelo Compagnucci
Hi Martin, In trunk the correct syntax should be: from gluon.contrib import user_agent_parser ua = user_agent_parser.detect(request.env.http_user_agent) if ua.is_mobile: ... Or better: ua = request.user_agent() if ua.is_mobile: ... The mothod user_agent() search in session if the user_agent wa

Re: [web2py] Re: Mobile detector

2011-08-29 Thread Martin Weissenboeck
I tried: def mobile(): from gluon.contrib import user_agent_parser ua = user_agent_parser.detect(request.env.http_user_agent) if ua.dist.is_mobile: and i got: AttributeError: 'NoneType' object has no attribute 'is_mobile' Browsers: Opera 11.50, Safari 3.1.2 (1) What is wrong? (2

[web2py] Re: Mobile detector

2011-08-28 Thread Massimo Di Pierro
I have no objection.What do others think? On Aug 28, 10:53 am, Angelo Compagnucci wrote: > 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): >    

Re: [web2py] Re: Mobile detector

2011-08-28 Thread Angelo Compagnucci
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_

[web2py] Re: Mobile detector

2011-08-27 Thread Massimo Di Pierro
This is in trunk as of last night. On Aug 26, 12:13 pm, Ross Peoples wrote: > I submitted this to Massimo for inclusion. Now we wait :)

Re: [web2py] Re: Mobile detector

2011-08-26 Thread Ross Peoples
I submitted this to Massimo for inclusion. Now we wait :)

Re: [web2py] Re: Mobile detector

2011-08-26 Thread Angelo Compagnucci
Hi Ross, I have explained myself too convoluted! You are right on is_mobile and polymorphism, I read too approximatively the code. You are right also on attch always the is_mobile True/False to the result object, is more simple to test for true false than that if exists or not. I hope it will b

Re: [web2py] Re: Mobile detector

2011-08-24 Thread Ross Peoples
Well, the reason is_mobile is in the base object is for polymorphism to work. If we later did do a WindowsMobile(Dist): class, we can easily set is_mobile = True in it, since Dist is a subclass of the DetectorBase. I just left is_mobile attached to the response even if it's not mobile because it

Re: [web2py] Re: Mobile detector

2011-08-24 Thread Angelo Compagnucci
This works like a charm! def detect(self, agent, result): if agent and self.checkWords(agent): result[self.info_type] = Storage(name=self.name) version = self.getVersion(agent) if version: result[self.info_type].version = version

Re: [web2py] Re: Mobile detector

2011-08-24 Thread Angelo Compagnucci
Hi Ross, I thought deeply on the implication on using the dist object. There are many points in favour: 1) Only dist object could be mobile ones from the code, Android - Iphone - Ipad are all dist objects. 2) If you want to detect Windows Mobile in a near future, you'll create a new dist object r

Re: [web2py] Re: Mobile detector

2011-08-24 Thread Ross Peoples
Forgot to attach, sorry """ Extract client information from http user agent The module does not try to detect all capabilities of browser in current form (it can easily be extended though). Aim is * fast * very easy to extend * reliable enough for practical purposes * and assist p

Re: [web2py] Re: Mobile detector

2011-08-24 Thread Ross Peoples
Nice work on that Angelo, I did have to change a few things, since 'dist' will not always exist (like when a non-Linux desktop machine visits). So this is what I did: When any 'dist' or 'os' returns is_mobile=True, then the result will have is_mobile at the root. So you can test for mobile like

Re: [web2py] Re: Mobile detector

2011-08-23 Thread Angelo Compagnucci
Hi Ross, I produced a patch that adds the is_mobile boolean flag to a dist if the useragent belongs to a mobile device. Ptch is made on the last dev revision pulled from mercurial. It's actually a simple patch that modifies no more than ten lines of code, hope this helps! Now you could make: fro

Re: [web2py] Re: Mobile detector

2011-08-23 Thread Anthony
Also, note that you can access user_agent_parser.py by calling request.user_agent(). The nice thing about the latter is that it will store the result in the session (as session._user_agent), so it only needs to parse the user agent once per session. Anthony On Tuesday, August 23, 2011 1:30:36

Re: [web2py] Re: Mobile detector

2011-08-23 Thread Angelo Compagnucci
Hi Ross, Thank you for the info, it's really a good suggestion. I'll try to add a variable like is_mobile, becase all informations about browser and versions are already present in your code. I think however that the Bruno's approach is really awesome. It's really simple using the decorator, and

Re: [web2py] Re: Mobile detector

2011-08-23 Thread Ross Peoples
We could always modify the simple_detect() method to include a third item in the returned tuple that is a string (i.e. 'desktop', ,'mobile', etc) based on the outcome of the detect. That shouldn't be too difficult to do if you want to give it a try.

Re: [web2py] Re: Mobile detector

2011-08-23 Thread Angelo Compagnucci
Hi Ross, I'm looking into your user_agent_parser.py but I cannot find something like the mobile detector. I'll explain better. With user_agent_parser.py you can look for browser version and os version, but there isn't an easy way to dectect if a browser is mobile or not, or I'm missing something?

[web2py] Re: Mobile detector

2011-08-18 Thread Ross Peoples
We already have a user_agent_parser.py in contrib. Isn't that the same thing? Usage: import contrib.user_agent_parser user_agent_parser.simple_detect(request.env.http_user_agent) By the way, didn't you add something to the Google Issues page for the proposal saying you were getting an error fr