Exemplo n.º 1
0
 def process_request(self, request):
     _init_flavour(request)
     if settings.FLAVOURS_GET_PARAMETER in request.GET:
         flavour = request.GET[settings.FLAVOURS_GET_PARAMETER]
         if flavour in settings.FLAVOURS:
             set_flavour(flavour, request, permanent=True)
     elif flavour_storage.get(request) != None:
         #if it's been set, we need it in the request now, 
         #not after the view has been processed
         set_flavour(flavour_storage.get(request), request)
Exemplo n.º 2
0
    def process_request(self, request):
        """
        Check if the flavour has been overridden by ?flavour
        We don't need this check if it has
        """
        if flavour_storage.get(request) == None:
            is_mobile = False
            if request.META.has_key('HTTP_USER_AGENT'):
                user_agent = request.META['HTTP_USER_AGENT']
                # Test common mobile values.
                if self.user_agents_test_search_regex.search(user_agent) and \
                    not self.user_agents_exception_search_regex.search(user_agent):
                    is_mobile = True
                else:
                    # Nokia like test for WAP browsers.
                    # http://www.developershome.com/wap/xhtmlmp/xhtml_mp_tutorial.asp?page=mimeTypesFileExtension
                    if request.META.has_key('HTTP_ACCEPT'):
                        http_accept = request.META['HTTP_ACCEPT']
                        if self.http_accept_regex.search(http_accept):
                            is_mobile = True
                if not is_mobile:
                    # Now we test the user_agent from a big list.
                    if self.user_agents_test_match_regex.match(user_agent):
                        is_mobile = True

            if is_mobile:
                set_flavour(settings.DEFAULT_MOBILE_FLAVOUR, request, permanent=True)
            else:
                set_flavour(settings.FLAVOURS[0], request, permanent=True)
Exemplo n.º 3
0
    def process_request(self, request):
        saved_flavour = flavour_storage.get(request)

        if saved_flavour is None:
            if UADetector(request).is_user_agent_mobile():
                    set_flavour(settings.DEFAULT_MOBILE_FLAVOUR, request)
            else:
                set_flavour(settings.FLAVOURS[0], request)
        else:
            set_flavour(saved_flavour, request)