# django-mobler

django-mobler is a User-Agent-based mobile device detection app for Django.

* **Author**: [Derek Payton](http://www.dmpayton.com)
* **Version**: 1.0.0
* **License**: MIT

This app depends on a browscap.ini file from the [Browser Capabilities Project](http://browsers.garykeith.com/), and must be periodically updated with the latest definitions. The current version may be found [here](http://browsers.garykeith.com/stream.asp?BrowsCapINI), and can be set with the `BROWSCAP_PATH` setting, described below.

## Usage

Mobler requires only a couple changes to your settings.py in order to function:

* Add `mobler` to `INSTALLED_APPS`.
* Add `mobler.middleware.MobileDetectionMiddleware` to `MIDDLEWARE_CLASSES` (preferably near the top).
* Set `MOBILE_DOMAIN` to the full domain of your mobile site.

Requests to your site from a mobile device will now be redirected to the same URL path and query string on your mobile site.

## Override

To override the redirect, visit any page on the full site with `?mobler-override=1`. This will set a cookie and prevent the redirect from taking place on subsequent page views.

If your mobile site is built in Django, mobler includes a helper template tag to generate the override URL for the same page on the full site.

**Usage:**

    {% load mobler_tags %}
    <a href="http://www.exmaple.com{% full_site_override request %}">Full Site</a>

If you are on `http://m.example.com/foo/bar/?fizz=buzz`, the tag will return `/foo/bar/?fizz=buzz&mobler-override=1`.

## Settings

**BROWSCAP\_PATH**  
File path to a custom browsecap.ini  
***Default:** /path/to/mobler/browsecap.ini*

**MOBILE\_DOMAIN**  
URL of your mobile site, e.g., http://m.example.com  
***Required***

**MOBLER\_CACHE\_KEY**  
Cache key used for parsed browscap.ini data  
***Default:** mobler-cache*

**MOBLER\_CACHE\_TIMEOUT**  
Length of time to cache the parsed browscap.ini data  
***Default:** 60\*60\*2 (2 hours)*

**MOBLER\_COOKIE\_NAME**  
Name of the override cookie and GET parameter  
***Default:** mobler-override*

**MOBLER\_COOKIE\_AGE**  
How long the override cookie should live  
***Default:** 60\*60\*24\*31 (31 days)*

**MOBLER\_PRESERVE\_URL**  
Whether or not to preserve the URL when redirecting to the mobile site (if False, users will be redirected to your mobile homepage)  
***Default:** True*

## Special Thanks

django-mobler is based on [django-browsecap](https://github.com/ella/django-browsecap), and some of the code is based on it. Thank you for the inspiration!
