File: widgets.py

package info (click to toggle)
python-django-jsonfield 0.9.12-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 160 kB
  • sloc: python: 476; makefile: 3
file content (18 lines) | stat: -rw-r--r-- 465 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import json 

from django import forms
from django.conf import settings

from .utils import default

class JSONWidget(forms.Textarea):
    def render(self, name, value, attrs=None):
        if value is None:
            value = ""
        if not isinstance(value, basestring):
            value = json.dumps(value, indent=2, default=default)
        return super(JSONWidget, self).render(name, value, attrs)


class JSONSelectWidget(forms.SelectMultiple):
    pass