summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorluxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f <luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f>2010-06-19 18:22:28 +0000
committerluxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f <luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f>2010-06-19 18:22:28 +0000
commit689ea1ee3568621bf51e69112b024c4db042077a (patch)
tree8ffed65b489137db373e91c004f5ef49f08d8eb9 /lib
parent09c2fe82662331998a94ba3b5c1738d184d61b1a (diff)
added mobile middleware and templates
Diffstat (limited to 'lib')
-rw-r--r--lib/mobile_middleware/__init__.py0
-rw-r--r--lib/mobile_middleware/mobile_detect.py31
2 files changed, 31 insertions, 0 deletions
diff --git a/lib/mobile_middleware/__init__.py b/lib/mobile_middleware/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/lib/mobile_middleware/__init__.py
diff --git a/lib/mobile_middleware/mobile_detect.py b/lib/mobile_middleware/mobile_detect.py
new file mode 100644
index 0000000..6f5b998
--- /dev/null
+++ b/lib/mobile_middleware/mobile_detect.py
@@ -0,0 +1,31 @@
+from django.http import HttpResponseRedirect
+import re
+mobile_url = 'http://m.luxagraf.net/'
+agents_list = [
+ 'Nokia','bMOT','^LGE?b','SonyEricsson',
+ 'Ericsson','BlackBerry','DoCoMo','Symbian',
+ 'Windows CE','NetFront','Klondike','PalmOS',
+ 'PalmSource','portalmm','S[CG]H-','bSAGEM',
+ 'SEC-','jBrowser-WAP','Mitsu','Panasonic-',
+ 'SAMSUNG-','Samsung-','Sendo','SHARP-',
+ 'Vodaphone','BenQ','iPAQ','AvantGo',
+ 'Go.Web','Sanyo-','AUDIOVOX','PG-',
+ 'CDM[-d]','^KDDI-','^SIE-','TSM[-d]',
+ '^KWC-','WAP','^KGT [NC]','iPhone',
+]
+def is_mobile(user_agent):
+ for agent in agents_list:
+ if re.search(agent, user_agent):
+ return True
+ return False
+
+class MobileRedirect(object):
+ def process_request(self, request):
+ if not request.session.get('checked_ua', False):
+ if is_mobile(request.META['HTTP_USER_AGENT']):
+ request.session['checked_ua'] = True
+ return HttpResponseRedirect(mobile_url)
+ else:
+ # Make sure it doesn't try this again
+ request.session['checked_ua'] = True
+ return None \ No newline at end of file