Login

iPhoneMiddleware

Author:
henriklied
Posted:
September 30, 2008
Language:
Python
Version:
1.0
Tags:
middleware user-agent iphone
Score:
4 (after 4 ratings)

Adds an additional template dir to settings.TEMPLATE_DIRS if the request's HTTP_USER_AGENT string has the word iPhone in it. Allows you to easily create iPhone templates.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
from django.conf import settings

# Change this to reflect your settings.py file
from site_settings import settings as local_settings

class iPhoneMiddleware(object):
    """
    iPhone Middleware. Dynamically adds the iPhone template dirs if
    iPhone user agent is present
    """
    
    def __init__(self):
        self.iphone_templates = ('/home/video/sources/video/templates/iphone_templates',)
    
    def process_request(self, request):
        if request.META['HTTP_USER_AGENT'].find('iPhone') != -1:
            settings.TEMPLATE_DIRS = self.iphone_templates + local_settings.TEMPLATE_DIRS
        else:
            settings.TEMPLATE_DIRS = local_settings.TEMPLATE_DIRS
        return

More like this

  1. Serialize a model instance by chriswedgwood 1 week, 2 days ago
  2. Automatically setup raw_id_fields ForeignKey & OneToOneField by agusmakmun 9 months, 1 week ago
  3. Crispy Form by sourabhsinha396 10 months ago
  4. ReadOnlySelect by mkoistinen 10 months, 2 weeks ago
  5. Verify events sent to your webhook endpoints by santos22 11 months, 2 weeks ago

Comments

Please login first before commenting.