Skip to content

Commit d40d339

Browse files
committed
Init version
0 parents  commit d40d339

26 files changed

+6773
-0
lines changed

.gitignore

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
5+
# C extensions
6+
*.so
7+
8+
# Distribution / packaging
9+
.Python
10+
env/
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
*.egg-info/
23+
.installed.cfg
24+
*.egg
25+
26+
# PyInstaller
27+
# Usually these files are written by a python script from a template
28+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
29+
*.manifest
30+
*.spec
31+
32+
# Installer logs
33+
pip-log.txt
34+
pip-delete-this-directory.txt
35+
36+
# Unit test / coverage reports
37+
htmlcov/
38+
.tox/
39+
.coverage
40+
.coverage.*
41+
.cache
42+
nosetests.xml
43+
coverage.xml
44+
*,cover
45+
46+
# Translations
47+
*.mo
48+
*.pot
49+
50+
# Django stuff:
51+
*.log
52+
53+
# Sphinx documentation
54+
docs/_build/
55+
56+
# PyBuilder
57+
target/
58+
59+
# Database
60+
*.sqlite3

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# JSONInput
2+
3+
JSONInput is an online structured JSON input widget appropriate for various JSONField's provided for Django.
4+
5+
Code of the online editor has been got from the http://jsoneditoronline.org/ but slightly changed to avoid some issues.
6+
7+
## Installation
8+
9+
TODO
10+
11+
## Use
12+
13+
TODO

django_jsoneditor/__init__.py

Whitespace-only changes.

django_jsoneditor/settings.py

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
"""
2+
Django settings for django_jsoneditor project.
3+
4+
Generated by 'django-admin startproject' using Django 1.8.3.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.8/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/1.8/ref/settings/
11+
"""
12+
13+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
14+
import os
15+
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = '1@5n@*f2ng(+il*9im)f$ie8lpc)c3an!3-3z2f9cwn*=6pzvc'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
30+
31+
32+
# Application definition
33+
34+
INSTALLED_APPS = (
35+
'testapp',
36+
37+
'jsoneditor',
38+
39+
'django.contrib.admin',
40+
'django.contrib.auth',
41+
'django.contrib.contenttypes',
42+
'django.contrib.sessions',
43+
'django.contrib.messages',
44+
'django.contrib.staticfiles',
45+
)
46+
47+
MIDDLEWARE_CLASSES = (
48+
'django.contrib.sessions.middleware.SessionMiddleware',
49+
'django.middleware.common.CommonMiddleware',
50+
'django.middleware.csrf.CsrfViewMiddleware',
51+
'django.contrib.auth.middleware.AuthenticationMiddleware',
52+
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
53+
'django.contrib.messages.middleware.MessageMiddleware',
54+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
55+
'django.middleware.security.SecurityMiddleware',
56+
)
57+
58+
ROOT_URLCONF = 'django_jsoneditor.urls'
59+
60+
TEMPLATES = [
61+
{
62+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
63+
'DIRS': [],
64+
'APP_DIRS': True,
65+
'OPTIONS': {
66+
'context_processors': [
67+
'django.template.context_processors.debug',
68+
'django.template.context_processors.request',
69+
'django.contrib.auth.context_processors.auth',
70+
'django.contrib.messages.context_processors.messages',
71+
],
72+
},
73+
},
74+
]
75+
76+
WSGI_APPLICATION = 'django_jsoneditor.wsgi.application'
77+
78+
79+
# Database
80+
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
81+
82+
DATABASES = {
83+
'default': {
84+
'ENGINE': 'django.db.backends.sqlite3',
85+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
86+
}
87+
}
88+
89+
90+
# Internationalization
91+
# https://docs.djangoproject.com/en/1.8/topics/i18n/
92+
93+
LANGUAGE_CODE = 'en-us'
94+
95+
TIME_ZONE = 'UTC'
96+
97+
USE_I18N = True
98+
99+
USE_L10N = True
100+
101+
USE_TZ = True
102+
103+
104+
# Static files (CSS, JavaScript, Images)
105+
# https://docs.djangoproject.com/en/1.8/howto/static-files/
106+
107+
STATIC_URL = '/static/'

django_jsoneditor/urls.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""django_jsoninput URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/1.8/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Add an import: from blog import urls as blog_urls
14+
2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
15+
"""
16+
from django.conf.urls import include, url
17+
from django.contrib import admin
18+
19+
urlpatterns = [
20+
url(r'^admin/', include(admin.site.urls)),
21+
]

django_jsoneditor/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for django_jsoninput project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_jsoneditor.settings")
15+
16+
application = get_wsgi_application()

jsoneditor/__init__.py

Whitespace-only changes.

jsoneditor/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

jsoneditor/fields/__init__.py

Whitespace-only changes.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from json_field import JSONField as _JSONField
2+
from json_field.forms import JSONFormField as _JSONFormField
3+
4+
from jsoneditor.forms import JSONEditor
5+
6+
class JSONFormField(_JSONFormField):
7+
widget = JSONEditor
8+
def __init__(self,*av,**kw):
9+
kw['widget'] = self.widget # force avoiding widget override
10+
super(JSONFormField,self).__init__(*av,**kw)
11+
12+
class JSONField(_JSONField):
13+
def formfield(self, **kwargs):
14+
defaults = {
15+
'form_class': kwargs.get('form_class', JSONFormField),
16+
}
17+
defaults.update(kwargs)
18+
return super(JSONField, self).formfield(**defaults)

jsoneditor/forms.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from django.forms.widgets import Textarea
2+
from django.forms.util import flatatt
3+
4+
from django.utils.safestring import mark_safe
5+
6+
from django.conf import settings
7+
8+
class JSONEditor(Textarea):
9+
class Media:
10+
js = ( getattr(settings,"JSON_EDITOR_JS",settings.STATIC_URL+'jsoneditor/jsoneditor.js'), )
11+
css= {'all': ( getattr(settings, "JSON_EDITOR_CSS",settings.STATIC_URL+'jsoneditor/jsoneditor.css'),)}
12+
13+
def render(self, name, value, attrs=None):
14+
input_attrs = {'hidden':True}
15+
input_attrs.update(attrs)
16+
r = super(JSONEditor,self).render(name, value, input_attrs)
17+
div_attrs = {}
18+
div_attrs.update(attrs)
19+
div_attrs.update({'id':(attrs['id']+'_jsoneditor')})
20+
final_attrs = self.build_attrs(div_attrs, name=name)
21+
r += '''
22+
<div %(attrs)s></div>
23+
<script type="text/javascript">
24+
django.jQuery(function() {
25+
if( typeof(jsoneditor) == "undefined" )
26+
jsoneditor = { JSONEditor:JSONEditor };
27+
var editor_%(editor_id)s = new jsoneditor.JSONEditor(django.jQuery('#%(id)s_jsoneditor')[0],{
28+
change:function() {
29+
django.jQuery('#%(id)s')[0].value = JSON.stringify(editor_%(editor_id)s.get());
30+
},
31+
},JSON.parse(django.jQuery('#%(id)s')[0].value));
32+
django.jQuery('#%(id)s').hide();
33+
});
34+
</script>
35+
''' % {
36+
'attrs':flatatt(final_attrs),
37+
'editor_id':attrs['id'].replace('-','_'),
38+
'id':attrs['id'],
39+
}
40+
return mark_safe(r)

jsoneditor/migrations/__init__.py

Whitespace-only changes.

jsoneditor/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.
Loading

0 commit comments

Comments
 (0)