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-prettyjson

[![PyPi Version](https://badge.fury.io/py/django-prettyjson.png)](https://badge.fury.io/py/django-prettyjson) [![Build Status](https://travis-ci.org/kevinmickey/django-prettyjson.svg?branch=master)](https://travis-ci.org/kevinmickey/django-prettyjson)

Enables pretty JSON viewer in Django forms, admin, or templates. The viewer is adapted from [jQuery JSONView](https://github.com/yesmeck/jquery-jsonview) It is compatible with almost anything: JSON stored in a string, a jsonfield (using django.contrib.postgres or [django-jsonfield](https://github.com/bradjasper/django-jsonfield/)) or any python object that can be serialized to JSON (using [standardjson](https://github.com/audreyr/standardjson))

## Demo

See http://kevinmickey.github.io/django-prettyjson

## Installation

At the command line:

```sh
pip install django-prettyjson
```

## Configuration

Add `'prettyjson'` to `INSTALLED_APPS` in `settings.py`:

```python
INSTALLED_APPS = (
...,
'prettyjson',
)
```

## Usage

In a form or admin of a model, enable a pretty JSON viewer for a particular field:

```python
from prettyjson import PrettyJSONWidget

class JsonForm(forms.ModelForm):
class Meta:
model = Test
fields = '__all__'
widgets = {
'myjsonfield': PrettyJSONWidget(),
}

class JsonAdmin(admin.ModelAdmin):
form = JsonForm
```

Enable pretty JSON viewer for every JSONField of a model:

```python
from django.contrib.postgres.fields import JSONField

class JsonAdmin(admin.ModelAdmin):
formfield_overrides = {
JSONField: {'widget': PrettyJSONWidget }
}
```

In templates, you can also enable a pretty JSON viewer. Use the `prettyjson` template tag with a string JSON or with objects (dicts, QuerySets, etc.) that can be serialized to a JSON. Note that the template tag must be loaded using `{% load prettyjson %}`. It also has CSS and JS that must be included using `{% prettyjson_setup %}`.

```htmldjango
{% extends "base.html" %}

{% load prettyjson %}

{% block header %}
{{ block.super }}
{% prettyjson_setup %}
{% endblock %}

{% block content %}
{% prettyjson myqueryset %}
{% prettyjson mydict %}
{% prettyjson '{"hey": "guy","anumber": 243,"anobject": {"whoa": "nuts","anarray": [1,2,"thr<h1>ee"], "more":"stuff"},"awesome": true,"bogus": false,"meaning": null, "japanese":"明日がある。", "link": "http://jsonview.com", "notLink": "http://jsonview.com is great"}' %}
{% prettyjson '{}' %}
{% endblock %}
```

The setup includes jQuery, loaded as django.jQuery to avoid namespace conflict. If your page already includes jQuery, use `{% prettyjson_setup jquery=False %}` to avoid loading jQuery a second time.

## Running Tests

In development.

```sh
source <yourvirtualenv>/bin/activate
(myenv) $ pip install -r requirements-test.txt
(myenv) $ python runtests.py
```

## Credits

Dependencies, parts of code, and/or sources of inspiration:

* [jQuery JSONView](https://github.com/yesmeck/jquery-jsonview)
* [standardjson](https://github.com/audreyr/standardjson)

Tools used in developing, testing, and/or rendering this package:

* [Cookiecutter](https://github.com/audreyr/cookiecutter)
* [cookiecutter-djangopackage] (https://github.com/pydanny/cookiecutter-djangopackage)




History
-------

0.1.0 (2016-05-28)
++++++++++++++++++

* First release.

0.2.0 (2016-05-29)
++++++++++++++++++

* Switched to using standardjson for encoding objects
* Added setup option for those with jquery already loaded

0.2.1 (2016-07-01)
++++++++++++++++++

* Fixed manifest

0.2.2 (2016-12-07)
++++++++++++++++++

* Added dependencies to setup.py
Release History

Release History

0.2.2

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.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.0

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.0

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_prettyjson-0.2.2-py2.py3-none-any.whl (10.6 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Dec 7, 2016
django-prettyjson-0.2.2.tar.gz (9.9 kB) Copy SHA256 Checksum SHA256 Source Dec 7, 2016

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