def isMobile(self): """ """ ua = get_user_agent(self.request) if ua and detect_mobile_browser(ua): return True return False
def need_xhtml(request): """ Determine whether HTML'ish request should be served as XHTML. 1. The HTTP_ACCEPT header is set correctly 2. Note: This should be done for bots only. See reasons in Developer Manual, XHTML section. """ environ = get_environ(request) header = environ.get("HTTP_ACCEPT", None) if not header: return False if not "application/xhtml+xml" in header: return False ua = get_user_agent(request) if ua: ua = ua.lower() for bot in bots_know_about_mobile_xhtml: if bot in ua: return True return False
def isMobileBrowser(self): ua = get_user_agent(self.request) if ua: return detect_mobile_browser(ua) else: # User agent missing from HTTP request return False
def get_poi_type(request): ua = get_user_agent(request) if ua: ua = ua.lower() if "nokia" in ua: return "landmark" elif "iphone" in ua: return "href"
def is_android(request): """ Is the device which makde HTTP request Blackberry like @param request: HTTP request object (WSGI/Zope/Django) """ user_agent = get_user_agent(request) return "android" in user_agent.lower()
def is_apple_device(request): """ @return: True if the HTTP request was made by iPod/iPhone/iPad """ user_agent = get_user_agent(request) return ("iPhone" in user_agent) or ("iPod" in user_agent) or ("iPad" in user_agent)
def is_low_end_phone(request): """ @return True: If the user is visiting the site using a crappy mobile phone browser. Low end phones have problem with: - Complex HTML syntax - Several images on the same page - Advanced CSS styles - Animations - Transparent backgrounds and alpha channel - 24-bit PNGs High end phones: * Firefox (Gecko based) browseres * Webkit based browsers Low end phones: * All other Before using the techniques above please filter them away for the crappy phones. This concerns at least Nokia Series 40 phones. Note that Opera Mini browser works smoothly on low end phones too... """ # We assume all powerful mobile browsers are WebKit based user_agent = get_user_agent(request) if not user_agent: # Unit testing... return False user_agent = user_agent.lower() if "gecko" in user_agent: # Show high end version for desktop browser users return False if "maemo" in user_agent: # Show high end version for desktop browser users return False if "opera" in user_agent: # Opera mini does its job well return False if "fennec" in user_agent or "maemo" in user_agent: return True return not "webkit" in user_agent
def on_mobile(self): """ Return True if the site is being browsed on a mobile phone. """ ua = get_user_agent(self.request) if ua: if detect_mobile_browser(ua): return True else: return False return False
def addLogEntry(self): """ """ date = datetime.now() timestamp = str(date) user_agent = get_user_agent(self.request) page = self.request["ACTUAL_URL"] print >> self.buffer, "%s|%s|%s" % (timestamp, page, user_agent) print "Redirect log %s|%s|%s" % (timestamp, page, user_agent)
def isMobileBrowser(self): ua = get_user_agent(self.request) if ua: is_mobile = detect_mobile_browser(ua) if is_mobile: exclude = getattr(self.mobile_properties, "exclude_user_agents", "") if exclude and re.search(exclude, ua, flags=re.I): return False return is_mobile else: # User agent missing from HTTP request return False
def is_text_view(self): """Check if text view (base for desktop is drag, mobile only has text) is selected. :returns: returns True or False, depending on text view being selected :rtype: boolean """ # Get HTTP_USER_AGENT from HTTP request object ua = get_user_agent(self.request) if ua and detect_mobile_browser(ua): # Redirect the visitor from a web site to a mobile site return True return self.request.form.get("view_type", "drag") == "text"
def is_javascript_supported(request): """ Does phone have meaningful Javascript support @param request: HTTP request object (WSGI/Zope/Django) """ user_agent = get_user_agent(request) if user_agent is None: return False if "opera" in user_agent: # Opera mini javascript support is # not good enough to be useable as it is thin client return False return is_high_end_phone(request)
def is_handheld(self): # Get HTTP_USER_AGENT from HTTP request object class FakeRequest: def __init__(self, request): self.other = request ua = get_user_agent(FakeRequest(self.request)) if ua: # Apply reg if detect_mobile_browser(ua): # Redirect the visitor from a web site to a mobile site return True else: # A regular web site visitor return False else: # User agent header is missing from HTTP request return False
from mobile.sniffer.detect import detect_mobile_browser from mobile.sniffer.utilities import get_user_agent # Get HTTP_USER_AGENT from HTTP request object ua = get_user_agent(self.request) if ua: # Apply reg if detect_mobile_browser(ua): # Redirect the visitor from a web site to a mobile site pass else: # A regular web site visitor pass else: # User agent header is missing from HTTP request return False