<commit_before># django-mobler

User-Agent-based mobile device detection for Django

* **Author**: [<NAME>](http://www.dmpayton.com)
* **Version**: 0.1
* **License**: MIT

## Todo: a better readme...

browscap.ini: http://browsers.garykeith.com/stream.asp?BrowsCapINI

***Credits:***
[django-browsecap](https://github.com/ella/django-browsecap) served as the original inspiration and code basis for django-mobler.<commit_msg>We have a (better) README\!<commit_after># django-mobler

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

* **Author**: [<NAME>](http://www.dmpayton.com)
* **Version**: 0.1
* **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.

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

**Usage:**

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

## 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 you mobile homepage)  
***Default:** True*

## Credit

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!
{'fraction_non_alphanumeric': 0.12710154673839946, 'fraction_numerical': 0.007397444519166106, 'mean_word_length': 4.499075785582255, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3331566', 'n_tokens_mistral': 973, 'n_tokens_neox': 929, 'n_words': 339}