{ "info": { "author": "Keryn Knight", "author_email": "django-contextaware-processors@kerynknight.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Framework :: Django", "Framework :: Django :: 1.10", "Framework :: Django :: 1.8", "Framework :: Django :: 1.9", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5" ], "description": "django-contextaware-processors\n==============================\n\n:author: Keryn Knight\n:version: 0.1.1\n\n.. |travis_stable| image:: https://travis-ci.org/kezabelle/django-contextaware-processors.svg?branch=0.1.1\n :target: https://travis-ci.org/kezabelle/django-contextaware-processors\n\n.. |travis_master| image:: https://travis-ci.org/kezabelle/django-contextaware-processors.svg?branch=master\n :target: https://travis-ci.org/kezabelle/django-contextaware-processors\n\n============== ======\nRelease Status\n============== ======\nstable (0.1.1) |travis_stable|\nmaster |travis_master|\n============== ======\n\n.. contents:: Sections\n :depth: 3\n\nWhat it does\n------------\n\nEver used `Django`_ and wished you could have a `context processor`_ which\nreceived the existing context, along with the request, so that it could do\ndifferent things depending on the values the view provided? This does that, as\nlong as you're using `TemplateResponse`_ objects and not ``render()`` or\n``render_to_response()``.\n\nInstallation\n------------\n\nYou can use `pip`_ to install the ``0.1.1`` version from `PyPI`_::\n\n pip install django-contextaware-processors==0.1.1\n\nOr you can grab it from `GitHub`_ like this::\n\n pip install -e git+https://github.com/kezabelle/django-contextaware-processors.git#egg=django-contextaware-processors\n\nUsage\n-----\n\nAdd a new ``CONTEXTAWARE_PROCESSORS`` setting to your project configuration. It\nshould be an iterable of strings representing the dotted paths to your\nprocessors, just the same as the `Django`_ context processors are configured::\n\n CONTEXTAWARE_PROCESSORS = ('path.to.my_processor', 'another_processor.lives.here')\n\nProcessors are executed in the order in which they are declared, and update the\noriginal context data. The new context is given to subsequent processors, such\nthat the last processor above (``another_processor.lives.here``) will see any\nchanges made by ``path.to.my_processor``.\n\nUsing the middleware\n^^^^^^^^^^^^^^^^^^^^\n\nIn most cases, if you're using ``TemplateResponse`` objects (or any `Class\nBased View`_ which uses them for you), you want to use the provided\nmiddleware::\n\n MIDDLEWARE_CLASSES = (\n # ...\n 'contextaware_processors.middleware.ContextawareProcessors',\n # ...\n )\n\nAs this makes use of ``process_response(request, response)`` you probably want\nit somewhere near the bottom, so that it modifies the context on the way out\nas soon as possible. The middleware will automatically apply any processors\ndefined in ``CONTEXTAWARE_PROCESSORS``\n\nUsing the TemplateResponse subclass\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nFor custom situations, there is\n``context_processors.response.ContextawareTemplateResponse`` class which\nexposes an ``add_context_callback(callback_function)`` which can be used to\napply view-specific context modifiers, though why you'd need to is not\nimmeidiately obvious to me ;)\nIf the ``ContextawareProcessors`` middleware notices a ``ContextawareTemplateResponse`` it\nwill add those defined in ``CONTEXTAWARE_PROCESSORS`` *after* any previously\nregistered custom modifiers.\n\n\nWriting a context-aware processor\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThe API contract for a processor is the same as a normal context processor, but\nwith the addition of a ``context`` parameter, sent as a *named-kwarg*.\n\nA normal context processor looks like::\n\n def my_processor(request):\n return {'MY_VALUE': 1}\n\nWhile a context-aware processor looks like::\n\n def my_processor(request, context):\n if 'MY_KEY' in context:\n return {'MY_VALUE': 2}\n return {'MY_VALUE': None}\n\nReturn values\n\"\"\"\"\"\"\"\"\"\"\"\"\"\n\nA context-aware processor must return one of 3 things:\n- A ``dictionary`` to ``.update(...)`` the existing context with,\n- ``NotImplemented`` may be used to mark it as irrelevant for the request\n- For convienience, ``None`` may also be used to skip updating the context.\n\nSupported Django versions\n-------------------------\n\nThe tests are run against `Django`_ 1.8 through 1.10, and Python 2.7, 3.3, 3.4 and 3.5.\n\nRunning the tests\n^^^^^^^^^^^^^^^^^\n\nIf you have a cloned copy, you can do::\n\n python setup.py test\n\nIf you have tox, you can just do::\n\n tox\n\nContributing\n------------\n\nPlease do!\n\nThe project is hosted on `GitHub`_ in the `kezabelle/django-contextaware-processors`_\nrepository.\n\nBug reports and feature requests can be filed on the repository's `issue tracker`_.\n\nIf something can be discussed in 140 character chunks, there's also `my Twitter account`_.\n\nThe license\n-----------\n\nIt's `FreeBSD`_. There's should be a ``LICENSE`` file in the root of the repository, and in any archives.\n\n.. _FreeBSD: http://en.wikipedia.org/wiki/BSD_licenses#2-clause_license_.28.22Simplified_BSD_License.22_or_.22FreeBSD_License.22.29\n.. _Django: https://www.djangoproject.com/\n.. _Class Based View: https://docs.djangoproject.com/en/stable/topics/class-based-views/\n.. _context processor: https://docs.djangoproject.com/en/stable/topics/templates/#context-processors\n.. _TemplateResponse: https://docs.djangoproject.com/en/stable/ref/template-response/\n.. _GitHub: https://www.github.com/\n.. _kezabelle/django-contextaware-processors: https://www.github.com/kezabelle/django-contextaware-processors/\n.. _issue tracker: https://www.github.com/kezabelle/django-contextaware-processors/issues/\n.. _my Twitter account: https://www.twitter.com/kezabelle/\n.. _pip: https://pip.pypa.io/en/stable/\n.. _PyPI: https://pypi.python.org/pypi\n\n\n----\n\nCopyright (c) 2017, Keryn Knight\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n\n----\n\nChange history for django-contextaware-processors\n-------------------------------------------------\n0.1.1\n^^^^^^\n* Initial release", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://www.github.com/kezabelle/django-contextaware-processors/", "keywords": "django contextaware_processors template context", "license": "BSD License", "maintainer": "", "maintainer_email": "", "name": "django-contextaware-processors", "package_url": "https://pypi.org/project/django-contextaware-processors/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-contextaware-processors/", "project_urls": { "Homepage": "https://www.github.com/kezabelle/django-contextaware-processors/" }, "release_url": "https://pypi.org/project/django-contextaware-processors/0.1.1/", "requires_dist": [ "Django (>=1.8)" ], "requires_python": "", "summary": "Before a Django TemplateResponse is rendered, modify the context data in-place with context-processor like functionality", "version": "0.1.1" }, "last_serial": 2700689, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "0902c5fa1c2a490001b80e96359f8fa7", "sha256": "cd2d87da65455721e4414f7a5c1a42ea4abf68c5468b4b7098cfa045df966bf7" }, "downloads": -1, "filename": "django_contextaware_processors-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "0902c5fa1c2a490001b80e96359f8fa7", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 14479, "upload_time": "2017-03-12T16:15:59", "url": "https://files.pythonhosted.org/packages/f7/65/75d0fe07724e971d73d20d38ebd430a07da98faa02dd00ba943a29fa85b0/django_contextaware_processors-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fdd160ab7535a55127ca19439ffec3bd", "sha256": "8e505ce7825cedb5b85ee3faeae5caa2b8ffc288ab93b508d69e768fc9f98b13" }, "downloads": -1, "filename": "django-contextaware-processors-0.1.1.tar.gz", "has_sig": false, "md5_digest": "fdd160ab7535a55127ca19439ffec3bd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10808, "upload_time": "2017-03-12T16:16:01", "url": "https://files.pythonhosted.org/packages/87/0f/a25d361ca978b761a50c8823b5cb2aca1b7f3f5affe411be888e677f4381/django-contextaware-processors-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0902c5fa1c2a490001b80e96359f8fa7", "sha256": "cd2d87da65455721e4414f7a5c1a42ea4abf68c5468b4b7098cfa045df966bf7" }, "downloads": -1, "filename": "django_contextaware_processors-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "0902c5fa1c2a490001b80e96359f8fa7", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 14479, "upload_time": "2017-03-12T16:15:59", "url": "https://files.pythonhosted.org/packages/f7/65/75d0fe07724e971d73d20d38ebd430a07da98faa02dd00ba943a29fa85b0/django_contextaware_processors-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fdd160ab7535a55127ca19439ffec3bd", "sha256": "8e505ce7825cedb5b85ee3faeae5caa2b8ffc288ab93b508d69e768fc9f98b13" }, "downloads": -1, "filename": "django-contextaware-processors-0.1.1.tar.gz", "has_sig": false, "md5_digest": "fdd160ab7535a55127ca19439ffec3bd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10808, "upload_time": "2017-03-12T16:16:01", "url": "https://files.pythonhosted.org/packages/87/0f/a25d361ca978b761a50c8823b5cb2aca1b7f3f5affe411be888e677f4381/django-contextaware-processors-0.1.1.tar.gz" } ] }