Package: django-intercooler-helpers
Author:Keryn KnightVersion:0.2.0ReleaseStatusstable (0.2.0)masterSectionsWhat it doesInstallation and usageInstallationConfigurationUsageSupported Django versionsRunning the testsRunning the demoContributingRoadmapThe licenseChange history for django-intercooler_helpersWhat it doesintercooler_helpersis a small reusable app forDjangowhich provides a
few improvements for working withIntercooler.js.It providea a middleware which extracts relevantIntercooler.jsdata from the
querystring, and attaches it to the request as a separateQueryDict(ie: it
behaves likerequest.POSTorrequest.GET)It also provides a small middleware for changing request method based on either the
query string (_method=PUT) or a request header(X-HTTP-Method-Override:PUT)Between them, they should capture all the incomingIntercooler.jsdata on
which the server may act.Installation and usageThis application depends ondjango-intercoolerjswhich provides a copy ofIntercooler.jsbundled up for use with the standardDjangostaticfiles
application.InstallationYou can grab0.2.0fromPyPIlike so:pip install django-intercooler-helpers==0.2.0Or you can grab it fromGitHublike this:pip install -e git+https://github.com/kezabelle/django-intercooler-helpers.git#egg=django-intercooler-helpersConfigurationYou need to addintercooler_helpers.middleware.IntercoolerDatato yourMIDDLEWARE_CLASSES(orMIDDLEWAREon Django1.10+).You may optionally want to addintercooler_helpers.middleware.HttpMethodOverrideas well, if you don’t already have a method by which to fake the HTTP Method change.
If you’re using<metaname="intercoolerjs:use-actual-http-method"content="true"/>then you don’t needHttpMethodOverrideat all.UsageA brief overview of the public API provided so far:IntercoolerDataFor fully correct detection ofIntercooler.jsrequests, you can callrequest.is_intercooler().
Behind the scenes, it usesrequest.maybe_intercooler()to
detect whetheric-requestwas present, indicating itmayhave been a
validIntercooler.jsrequest, and also checksrequest.is_ajax()To parse the Intercooler-related data out of the query-string, you can userequest.intercooler_data(not a method!) which is aQueryDictand should
behave exactly likerequest.GET- It pulls all of theic-*keys out
ofrequest.GETand puts them in a separate data structure, leaving
yourrequest.GETcleaned of extraenous data.request.intercooler_datais alazydata structure, likerequest.user,
so will not modifyrequest.GETuntil access is attempted.The following properties exist, mapping back to the keys mentioned in theIntercooler.js Reference documentrequest.intercooler_data.current_urlreturns theic-current-urlorNonerequest.intercooler_data.elementreturns anamedtuplecontainingic-element-nameorNoneic-element-idorNonerequest.intercooler_data.idtheic-idwhich made the request. an ever-incrementing integer.request.intercooler_data.requesta boolean indicating that it was anIntercooler.jsrequest. Should always
be true ifrequest.is_intercooler()said so.request.intercooler_data.target_idic-target-idorNonerequest.intercooler_data.triggerreturns anamedtuplecontainingic-trigger-nameorNoneic-trigger-idorNonerequest.intercooler_data.prompt_valueIf noic-prompt-namewas given and a prompt was used, this will contain
the user’s response. Appears to be undocumented?HttpMethodOverriderequest.changed_methodis a boolean indicating that the request was
toggled from being aPOSTto something else (one ofGET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS…
though why you’d want toPOSTand have it act as aGETis beyond me.
But that’s your choice)request.original_methodif either_method=XorX-HTTP-Method-Override:Xcaused the request to change method, then this
will contain the original request. It should always bePOSTrequest.methodwill reflect the desired HTTP method, rather than the one
originally used (POST)Supported Django versionsThe tests are run against Django 1.8 through 1.10, and Python 2.7, 3.3, 3.4 and 3.5.Running the testsIf you have a cloned copy, you can do:python setup.py testIf you have tox, you can just do:toxRunning the demoI’ve not yet built the demo, but eventually you’ll be able to do something like
the following. It assumes you’re using something likevirtualenvandvirtualenvwrapperbut you can probably figure it out otherwise:mktmpenv --python=`which python3`
pip install -e git+https://github.com/kezabelle/django-intercooler-helpers.git#egg=django-intercooler-helpersThen probably:cd src/django-intercooler-helpers
python demo_project.py runserverContributingPlease do!The project is hosted onGitHubin thekezabelle/django-intercooler-helpersrepository.Bug reports and feature requests can be filed on the repository’sissue tracker.If something can be discussed in 140 character chunks, there’s alsomy Twitter account.RoadmapTODO.The licenseIt’sFreeBSD. There’s should be aLICENSEfile in the root of the repository, and in any archives.Copyright (c) 2017, Keryn Knight
All rights reserved.Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.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.THIS 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.Change history for django-intercooler_helpers0.2.0Initial release.