Skip to main content

django-smartagent is the fastest and most complete user agent parser

Project description

======
Django-SmartAgent
======
Description
------

:Author:
James Pacileo

:Version:
0.1.0

:Description:
django-smartagent is an attempt to provide Django developers with a lightning fast and complete browser detection utility.

:Requirements:
Django 1.2+

Installation
------------

To install the app add ``smartagent`` to ``INSTALLED_APPS``

::

INSTALLED_APPS = (
...
'smartagent',
...
)

Add the middleware

::

MIDDLEWARE_CLASSES = (
...
'smartagent.middleware.UserAgentDetectorMiddleware',
)

**The middleware** is used to attach the browser characteristics to the request object, which will be accessible through **request.browser_info**

User-Agent data file
----------------------------

Django-SmartAgent comes pre-packaged with a data file containing browser info **agents_basic.pkl**. The datafile is built using various resources on the net and generated to be made compatible with the library.

You can grab the latest datafile from github https://github.com/jamespacileo/django-smartagent/downloads.

Once you grab the latest data file, place it under your project folder. To inform Django-SmartAgent of the file location you need to edit settings.py by adding:

::

SMART_AGENT_SETTINGS = {
'AGENT_DATASET_LOCATION': '/path/to/agent_data_set.pkl',
}

Utilities for mobile sites
--------------------------

As it is popular for sites to have a mobile version, there are a few utility methods within the project.

A **render_to** decorator (based on django-annoying's render_to) renders a page using a desktop or mobile version of a site, depending if the user-agent is a mobile device or not.

::

@render_to(template='desktop_template.html', mobile_template='mobile_template.html')
def page(request):

articles = Articles.objects.all()[:30]
return {
'articles': articles,
}

which is the equivalent of:

::

def page(request):

articles = Articles.objects.all()[:30]
if request.browser_info.get('ismobiledevice') and not request.session.get('force_desktop_version'):
return render_to_response('mobile_tempalte.html', {'articles':articles, },
context_instance=RequestContext(request))
return render_to_response('desktop_tempalte.html', {'articles':articles, },
context_instance=RequestContext(request))


Two utility URLs exist which are used to force/unforce the desktop vesion of the site. This is due to users not always wanting to view the mobile version of the site.

- **smartagent/force_desktop_version/** forces the desktop version for mobile sites

- **smartagent/unforce_desktop_version** unforces the desktop version, forcing mobile devices to view the mobile version

::

urlpatterns = patterns('',
...
(r'^smartagent/', include('smartagent.urls')))

Settings
--------

A settings variable can be added to your project settings.

The structure is the following:

::

SMART_AGENT_SETTINGS = {
'AGENT_DATASET_LOCATION': 'agents.pk',
}

Usage
-----

django-smartagent adds the ``browser_info`` dictionary to the ``request`` object containing features associated with the user's browser.

+-----------------------+----------------------------------------------+
+ Fields exposed within ``browser_data`` +
+=======================+==============================================+
+ FIELD NAME + FIELD DESCRIPTION +
+-----------------------+----------------------------------------------+
+ cdf + If Channel Definition Format is supported +
+-----------------------+----------------------------------------------+
+ activexcontrols + If activexcontrols are supported +
+-----------------------+----------------------------------------------+
+ cookies + If cookies are supported +
+-----------------------+----------------------------------------------+
+ supportscss + If CSS is supported +
+-----------------------+----------------------------------------------+
+ cssversion + Max CSS version supported +
+-----------------------+----------------------------------------------+
+ majorver + Major version +
+-----------------------+----------------------------------------------+
+ tables + If tables are supported +
+-----------------------+----------------------------------------------+
+ iframes + If iframes are supported +
+-----------------------+----------------------------------------------+
+ vbscript + If browser supports Visaul Basic scripting +
+-----------------------+----------------------------------------------+
+ platform + Host platform of the user's browser +
+-----------------------+----------------------------------------------+
+ version + Host OS version +
+-----------------------+----------------------------------------------+
+ javaapplets + If browser supports Java Applets +
+-----------------------+----------------------------------------------+
+ backgroundsounds + If browser supports background sounds +
+-----------------------+----------------------------------------------+
+ win64 + If the host OS is 64bit +
+-----------------------+----------------------------------------------+
+ javascript + If browser supports Javascript +
+-----------------------+----------------------------------------------+
+ beta + If browser is a beta distribution +
+-----------------------+----------------------------------------------+
+ alpha + If browser is an alpha distribution +
+-----------------------+----------------------------------------------+
+ minorver + Minor version +
+-----------------------+----------------------------------------------+
+ issyndicationreader + If user agent is a syndacation reader +
+-----------------------+----------------------------------------------+
+ win32 + If the host OS is 32bit +
+-----------------------+----------------------------------------------+
+ ismobiledevice + If host machine is a mobile device +
+-----------------------+----------------------------------------------+
+ crawler + If user agent is a web crawler +
+-----------------------+----------------------------------------------+
+ win16 + If the host OS is 16bit +
+-----------------------+----------------------------------------------+
+ browser + Browser's name +
+-----------------------+----------------------------------------------+

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-smartagent-0.1.0.zip (206.4 kB view details)

Uploaded Source

Built Distribution

django-smartagent-0.1.0.win32.exe (602.0 kB view details)

Uploaded Source

File details

Details for the file django-smartagent-0.1.0.zip.

File metadata

File hashes

Hashes for django-smartagent-0.1.0.zip
Algorithm Hash digest
SHA256 37a93b5cdcab20067e486eca3d02c2b70a40acb50ffc31d155c39787a4ff83da
MD5 59cb652a933609ce32999a00b3f411bc
BLAKE2b-256 8dee6735eb2a4a7527b4d34406c4ff221ddbf9c06498db29827fa69f3411dfea

See more details on using hashes here.

Provenance

File details

Details for the file django-smartagent-0.1.0.win32.exe.

File metadata

File hashes

Hashes for django-smartagent-0.1.0.win32.exe
Algorithm Hash digest
SHA256 364ada9c63278eeba01678724be6145ecf275588a78269385e97cc71b4ea1172
MD5 cdb97e2d7f900a9ac0e0817e6b3cfda6
BLAKE2b-256 416517f44f79a088db9845d981d9526e4580689a35a32b08986754dcc5ab2c4d

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page