This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

django-ajax-toolkit

Dependencies

  • msgpack-python>=0.2.4
  • django>=1.3

CI status (Travis)

Installation

Grab it from pypi with:

pip install django-ajax-toolkit

or:

easy_install django-ajax-toolkit

Returning data objects in views

JsonResponse

If you want to extend your views to work with ajax you may choose to return json data in your response. To make this easier you can use JsonResponse found in ajaxtoolkit.http:

from ajaxtoolkit.http import JsonResponse

class MyView(TemplateView):

    def get(self, request, *args, **kwargs):
        if request.is_ajax:
            context = self.get_context_data()
            return JsonResponse(context)
        # ...

This will set the correct mimetype (application/json) and serialise your context data into a json object.

MsgpackResponse

MsgpackResponse works in a similar way to JsonResponse, but uses msgpack to provide with binary serialisation. The usage is the same as with JsonResponse:

def get(self, request, *args, **kwargs):
    if request.is_ajax:
        context = self.get_context_data()
        return MsgpackResponse(context)
    # ...

Ajax Middleware

If you’re using Django’s messages framework, you can also add ajaxtoolkit.middleware.AjaxMiddleware in your middleware.

This will inject all messages generated in your request into your JsonResponse object:

from django.contrib import messages
from ajaxtoolkit.http import JsonResponse

class MyView(TemplateView):

    def get(self, request, *args, **kwargs):
        if request.is_ajax:
            context = self.get_context_data()

            messages.info(request, "This is very useful")
            messages.warning(request, "Be careful!")

            return JsonResponse(context)
        # ...

This would be rendered as the following:

{
    //...
    'django_messages': [
        {"extra_tags": "info",
         "message": "This is very useful",
         "level": 20},
        {"extra_tags": "warning",
         "message": "Be careful!",
         "level": 30}
    ]
}

Bypassing the message middleware

If you want to send an http response without attaching messages you can do that by setting the message_support attribute of the response object:

context = self.get_context_data()

response = JsonResponse(context)
response.message_support = False

return response

You can also choose to subclass the original response classes, eg.:

class MsgpackResponseWithoutMessages(MsgpackResponse):
    message_support = False

# ...

Contribute

Clone, create a virtualenv and run:

make install

This will install all dependencies. You can then run the tests with:

./runtests.py
Release History

Release History

0.3.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-ajax-toolkit-0.3.0.tar.gz (4.1 kB) Copy SHA256 Checksum SHA256 Source Oct 2, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting