{ "info": { "author": "Gregor M\u00fcllegger", "author_email": "gregor@muellegger.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "=============\ndjango-mobile\n=============\n\n.. _introduction:\n\n**django-mobile** provides a simple way to detect mobile browsers and gives\nyou tools at your hand to render some different templates to deliver a mobile\nversion of your site to the user.\n\nThe idea is to keep your views exactly the same but to transparently\ninterchange the templates used to render a response. This is done in two\nsteps:\n\n1. A middleware determines the client's preference to view your site. E.g. if\n he wants to use the mobile flavour or the full desktop flavour.\n2. The template loader takes then care of choosing the correct templates based\n on the flavour detected in the middleware.\n\n\nInstallation\n============\n\n.. _installation:\n\n*Pre-Requirements:* ``django_mobile`` depends on django's session framework. So\nbefore you try to use ``django_mobile`` make sure that the sessions framework\nis enabled and working.\n\n1. Install ``django_mobile`` with your favourite python tool, e.g. with\n ``easy_install django_mobile`` or ``pip install django_mobile``.\n2. Add ``django_mobile`` to your ``INSTALLED_APPS`` setting in the\n ``settings.py``.\n3. Add ``django_mobile.middleware.MobileDetectionMiddleware`` to your\n ``MIDDLEWARE_CLASSES`` setting.\n4. Add ``django_mobile.middleware.SetFlavourMiddleware`` to your\n ``MIDDLEWARE_CLASSES`` setting. Make sure it's listed *after*\n ``MobileDetectionMiddleware`` and also after ``SessionMiddleware``.\n5. Add ``django_mobile.loader.Loader`` as first item to your\n ``TEMPLATE_LOADERS`` list in ``settings.py``.\n6. Add ``django_mobile.context_processors.flavour`` to your\n ``TEMPLATE_CONTEXT_PROCESSORS`` setting.\n\nNow you should be able to use **django-mobile** in its glory. Read below of how\nthings work and which settings can be tweaked to modify **django-mobile**'s\nbehaviour.\n\n\nUsage\n=====\n\n.. _flavours:\n\nThe concept of **django-mobile** is build around the ideas of different\n*flavours* for your site. For example the *mobile* version is described as\none possible *flavour*, the desktop version as another.\n\nThis makes it possible to provide many possible designs instead of just\ndifferentiating between a full desktop experience and one mobile version. You\ncan make multiple mobile flavours available e.g. one for mobile safari on the\niPhone and Android as well as one for Opera and an extra one for the internet\ntablets like the iPad.\n\n*Note:* By default **django-mobile** only distinguishes between *full* and\n*mobile* flavour.\n\nAfter the correct flavour is somehow chosen by the middlewares, it's\nassigned to the ``request.flavour`` attribute. You can use this in your views\nto provide separate logic.\n\nThis flavour is then use to transparently choose custom templates for this\nspecial flavour. The selected template will have the current flavour prefixed\nto the template name you actually want to render. This means when\n``render_to_response('index.html', ...)`` is called with the *mobile* flavour\nbeing active will actually return a response rendered with the\n``mobile/index.html`` template. However if this flavoured template is not\navailable it will gracefully fallback to the default ``index.html`` template.\n\nIn some cases its not the desired way to have a completely separate templates\nfor each flavour. You can also use the ``{{ flavour }}`` template variable to\nonly change small aspects of a single template. A short example::\n\n \n \n My site {% if flavour == \"mobile\" %}(mobile version){% endif %}\n \n \n ...\n \n \n\nThis will add ``(mobile version)`` to the title of your site if viewed with\nthe mobile flavour enabled.\n\n*Note:* The ``flavour`` template variable is only available if you have set up the\n``django_mobile.context_processors.flavour`` context processor and used\ndjango's ``RequestContext`` as context instance to render the template.\n\nChanging the current flavour\n----------------------------\n\nThe basic use case of **django-mobile** is obviously to serve a mobile version\nof your site to users. The selection of the correct flavour is usually already\ndone in the middlewares when your own views are called. In some cases you want\nto change the currently used flavour in your view or somewhere else. You can\ndo this by simply calling ``django_mobile.set_flavour(flavour[,\npermanent=True])``. The first argument is self explaining. But keep in mind\nthat you only can pass in a flavour that you is also in your ``FLAVOURS``\nsetting. Otherwise ``set_flavour`` will raise a ``ValueError``. The optional\n``permanent`` parameters defines if the change of the flavour is remember for\nfuture requests of the same client.\n\nYour users can set their desired flavour them self. They just need to specify\nthe ``flavour`` GET parameter on a request to your site. This will permanently\nchoose this flavour as their preference to view the site.\n\nYou can use this GET parameter to let the user select from your available\nflavours::\n\n \n\nNotes on caching\n----------------\n\n.. _caching:\n\nDjango is shipping with some convenience methods to easily cache your views.\nOne of them is ``django.views.decorators.cache.cache_page``. The problem with\ncaching a whole page in conjunction with **django-mobile** is, that django's\ncaching system is not aware of flavours. This means that if the first request\nto a page is served with a mobile flavour, the second request might also\nget a page rendered with the mobile flavour from the cache -- even if the\nsecond one was requested by a desktop browser.\n\n**django-mobile** is shipping with it's own implementation of ``cache_page``\nto resolve this issue. Please use ``django_mobile.cache.cache_page`` instead\nof django's own ``cache_page`` decorator.\n\nYou can also use django's caching middlewares\n``django.middleware.cache.UpdateCacheMiddleware`` and\n``FetchFromCacheMiddleware`` like you already do. But to make them aware of\nflavours, you need to add\n``django_mobile.cache.middleware.CacheFlavourMiddleware`` as second last item\nin the ``MIDDLEWARE_CLASSES`` settings, right before\n``FetchFromCacheMiddleware``.\n\n\nReference\n=========\n\n``django_mobile.get_flavour([request,] [default])``\n\n Get the currently active flavour. If no flavour can be determined it will\n return *default*. This can happen if ``set_flavour`` was not called before\n in the current request-response cycle. *default* defaults to the first\n item in the ``FLAVOURS`` setting.\n\n``django_mobile.set_flavour(flavour, [request,] [permanent])``\n\n Set the *flavour* to be used for *request*. This will raise ``ValueError``\n if *flavour* is not in the ``FLAVOURS`` setting. You can try to set the\n flavour permanently for *request* by passing ``permanent=True``. This may\n fail if you are out of a request-response cycle. *request* defaults to the\n currently active request.\n\n``django_mobile.context_processors.flavour``\n\n Context processor that adds the current flavour as *flavour* to the\n context.\n\n``django_mobile.context_processors.is_mobile``\n\n This context processor will add a *is_mobile* variable to the context\n which is ``True`` if the current flavour equals the\n ``DEFAULT_MOBILE_FLAVOUR`` setting.\n\n``django_mobile.middleware.SetFlavourMiddleware``\n\n Takes care of loading the stored flavour from the user's session if set.\n Also sets the current request to a thread-local variable. This is needed\n to provide ``get_flavour()`` functionality without having access to the\n request object.\n\n``django_mobile.middleware.MobileDetectionMiddleware``\n\n Detects if a mobile browser tries to access the site and sets the flavour\n to ``DEFAULT_MOBILE_FLAVOUR`` settings value in case.\n\n``django_mobile.cache.cache_page``\n\n Same as django's ``cache_page`` decorator but applies ``vary_on_flavour``\n before the view is decorated with\n ``django.views.decorators.cache.cache_page``.\n\n``django_mobile.cache.vary_on_flavour``\n\n A decorator created from the ``CacheFlavourMiddleware`` middleware.\n\n``django_mobile.cache.middleware.CacheFlavourMiddleware``\n\n Adds ``X-Flavour`` header to ``request.META`` in ``process_request`` and\n adds this header to ``response['Vary']`` in ``process_response``.\n\n\nCustomization\n=============\n\n.. _customization:\n\nThere are some points available that let you customize the behaviour of\n**django-mobile**. Here are some possibilities listed:\n\n``MobileDetectionMiddleware``\n-----------------------------\n\nThe built-in middleware to detect if the user is using a mobile browser served\nwell in production but is far from perfect and also implemented in a very\nsimplistic way. You can safely remove this middleware from your settings and\nadd your own version instead. Just make sure that it calls\n``django_mobile.set_flavour`` at some point to set the correct flavour for\nyou.\n\nSettings\n--------\n\n.. _settings:\n\nHere is a list of settings that are used by **django-mobile** and can be\nchanged in your own ``settings.py``:\n\nFLAVOURS\n^^^^^^^^\n\nA list of available flavours for your site.\n\n**Default:** ``('full', 'mobile')``\n\nDEFAULT_MOBILE_FLAVOUR\n^^^^^^^^^^^^^^^^^^^^^^\n\nThe flavour which is chosen if the built-in ``MobileDetectionMiddleware``\ndetects a mobile browser.\n\n**Default:** ``mobile``\n\nFLAVOURS_TEMPLATE_PREFIX\n^^^^^^^^^^^^^^^^^^^^^^^^\n\nThis string will be prefixed to the template names when searching for\nflavoured templates. This is useful if you have many flavours and want to\nstore them in a common subdirectory. Example::\n\n from django.template.loader import render_to_string\n from django_mobile import set_flavour\n\n set_flavour('mobile')\n render_to_string('index.html') # will render 'mobile/index.html'\n\n # now add this to settings.py\n FLAVOURS_TEMPLATE_PREFIX = 'flavours/'\n\n # and try again\n\n set_flavour('mobile')\n render_to_string('index.html') # will render 'flavours/mobile/index.html'\n\n**Default:** ``''`` (empty string)\n\nFLAVOURS_TEMPLATE_LOADERS\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\n**django-mobile**'s template loader can load templates prefixed with the\ncurrent flavour. Specify with this setting which loaders are used to load\nflavoured templates.\n\n**Default:** same as ``TEMPLATE_LOADERS`` setting but without\n``'django_mobile.loader.Loader'``.\n\nFLAVOURS_GET_PARAMETER\n^^^^^^^^^^^^^^^^^^^^^^\n\nUsers can change the flavour they want to look at with a HTTP GET parameter.\nThis determines the name of this parameter. Set it to ``None`` to disable.\n\n**Default:** ``'flavour'``\n\nFLAVOURS_SESSION_KEY\n^^^^^^^^^^^^^^^^^^^^\n\nThe user's preference set with the GET parameter is stored in the user's\nsession. This setting determines which session key is used to hold this\ninformation.\n\n**Default:** ``'flavour'``\n\n\nChanglog\n========\n\n0.2.4\n-----\n* Added platform recognizing.\n\n\n0.2.3\n-----\n* STATIC_URL_MOBILE variable is added to context \n\n\n0.2.2\n-----\n\n* FIX: Opera Mobile on Android was categorized as mobile browser. Thanks to\n dgerzo for the report.\n* Sniffing for iPad so that it doesn't get recognized as small mobile device.\n Thanks to Ryan Showalter for the patch.\n\n0.2.1\n-----\n\n* Fixed packing issues that didn't include the django_mobile.cache package.\n Thanks to *Scott Turnbull* for the report.\n\n0.2.0\n-----\n\n* Restructured project layout to remove settings.py and manage.py from\n top-level directory. This resolves module-name conflicts when installing\n with pip's -e option. Thanks to *bendavis78* for the report.\n\n* Added a ``cache_page`` decorator that emulates django's ``cache_page`` but\n takes flavours into account. The caching system would otherwise cache the\n flavour that is currently active when a cache miss occurs. Thanks to\n *itmustbejj* for the report.\n\n* Added a ``CacheFlavourMiddleware`` that makes django's caching middlewares\n aware of flavours. We use interally the ``Vary`` response header and the\n ``X-Flavour`` request header.\n\n0.1.4\n-----\n\n* Fixed issue in template loader that only implemented\n ``load_template_source`` but no ``load_template``. Thanks to tylanpince,\n rwilcox and Fr\u00e9d\u00e9ric Roland for the report.\n\n0.1.3\n-----\n\n* Fixed issue with ``runserver`` command that didn't handled all request\n independed from each other. Thanks to bclermont and Fr\u00e9d\u00e9ric Roland for the\n report.\n\n0.1.2\n-----\n\n* Fixed unreferenced variable error in ``SetFlavourMiddleware``.\n\n0.1.1\n-----\n\n* Fixed ``is_usable`` attribute for ``django_mobile.loader.Loader``. Thanks Michela Ledwidge for the report.\n\n0.1.0\n-----\n\n* Initial release.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/gregmuellegger/django-mobile", "keywords": null, "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "django-mobile-withstatic", "package_url": "https://pypi.org/project/django-mobile-withstatic/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-mobile-withstatic/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/gregmuellegger/django-mobile" }, "release_url": "https://pypi.org/project/django-mobile-withstatic/0.2.4/", "requires_dist": null, "requires_python": null, "summary": "Detect mobile browsers and serve different template flavours to them.", "version": "0.2.4" }, "last_serial": 790095, "releases": { "0.2.3": [ { "comment_text": "", "digests": { "md5": "a6c328296157166e03b9448289abcece", "sha256": "9a5208e2feea38349190c49177e277fe63d3f6c00c7ce46cecb61c0975664e65" }, "downloads": -1, "filename": "django-mobile-withstatic-0.2.3.tar.gz", "has_sig": false, "md5_digest": "a6c328296157166e03b9448289abcece", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11855, "upload_time": "2012-08-27T09:36:12", "url": "https://files.pythonhosted.org/packages/70/8b/a78f9837a7e59cad48f4f2066e9b5496e4f7c460b88d03506737c4912b94/django-mobile-withstatic-0.2.3.tar.gz" } ], "0.2.4": [ { "comment_text": "", "digests": { "md5": "ccc0997e43df056894235ddfe09cbe4c", "sha256": "7b356348ed923b6d1c56fd2f2d57a537645a8e81a72e12753797dd368e203104" }, "downloads": -1, "filename": "django-mobile-withstatic-0.2.4.tar.gz", "has_sig": false, "md5_digest": "ccc0997e43df056894235ddfe09cbe4c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12116, "upload_time": "2012-09-27T16:17:44", "url": "https://files.pythonhosted.org/packages/24/77/eecb9c34f503d921a9ed2634cbada7c8fa2fcbe87c2c0d5218d7f0d9b44b/django-mobile-withstatic-0.2.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ccc0997e43df056894235ddfe09cbe4c", "sha256": "7b356348ed923b6d1c56fd2f2d57a537645a8e81a72e12753797dd368e203104" }, "downloads": -1, "filename": "django-mobile-withstatic-0.2.4.tar.gz", "has_sig": false, "md5_digest": "ccc0997e43df056894235ddfe09cbe4c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12116, "upload_time": "2012-09-27T16:17:44", "url": "https://files.pythonhosted.org/packages/24/77/eecb9c34f503d921a9ed2634cbada7c8fa2fcbe87c2c0d5218d7f0d9b44b/django-mobile-withstatic-0.2.4.tar.gz" } ] }