Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

sudo: false
dist: xenial
language: python
python:
- "2.7"
- "3.6"
- "3.7"
- "3.8"
addons:
postgresql: "9.5"
postgresql: "10"
env:
global:
- DJANGO_SETTINGS_MODULE=test_project.settings
Expand All @@ -29,8 +29,20 @@ matrix:
env: DJANGO=3.0
- python: "2.7"
env: DJANGO=3.0.7
- python: "3.7"
env: DJANGO=1.9
- python: "3.7"
env: DJANGO=1.10
- python: "3.7"
env: DJANGO=1.11
- python: "3.8"
env: DJANGO=1.9
- python: "3.8"
env: DJANGO=1.10
- python: "3.8"
env: DJANGO=1.11
install:
- pip install django==${DJANGO} Pillow psycopg2
- pip install django==${DJANGO} Pillow psycopg2-binary
- pip install .
before_script:
- psql -c 'create database test_jsonate;' -U postgres
Expand Down
3 changes: 0 additions & 3 deletions jsonate/django_ver.py

This file was deleted.

9 changes: 2 additions & 7 deletions jsonate/fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from past.builtins import basestring
try:
import json
except ImportError:
Expand All @@ -7,20 +6,16 @@
from django.db import models

from .utils import jsonate
from .django_ver import django_19
from .widgets import JsonateWidget
from .form_fields import JsonateFormField

class JsonateField(models.TextField):
if not django_19:
__metaclass__ = models.SubfieldBase

def _deserialize(self, value):
if value == "":
return None

try:
if isinstance(value, basestring):
if isinstance(value, str):
return json.loads(value)
except ValueError:
pass
Expand All @@ -37,7 +32,7 @@ def get_db_prep_value(self, value, connection, prepared=False):
if value == "":
return None

if not isinstance(value, basestring):
if not isinstance(value, str):
value = jsonate(value)

return value
Expand Down
28 changes: 5 additions & 23 deletions jsonate/json_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
except ImportError:
from django.utils import simplejson as json

from .django_ver import django_19
if django_19:
from django.db.models.query import ModelIterable
else:
from django.db.models.query import ValuesQuerySet

from django.db.models.query import ModelIterable
from django.db.models.query import QuerySet
from django.db.models import Model, Manager
from django.db.models.fields.related import ForeignKey
Expand Down Expand Up @@ -72,32 +67,19 @@ def map_object(obj):
raise CouldntSerialize
return to_json()


if not django_19:
# Must come before map_queryset because ValuesQuerySet is
# a subclass of Queryset and will cause an infinite loop :(
@register_typemap(ValuesQuerySet)
def map_values_queryset(obj):
return list(obj)

@register_typemap(QuerySet)
def map_queryset(obj):
# if the model wants to serialize itself, go with that...
if hasattr(obj.model, 'to_json') or hasattr(obj.model, 'toJSON'):
return list(obj)

# otherwise using values is faster
if django_19:
if obj._iterable_class == ModelIterable:

fields = jsonate_fields(obj.model)
obj = obj.values(*[field.name for field in fields])
if obj._iterable_class == ModelIterable:

return list(obj)

else:
fields = jsonate_fields(obj.model)
return obj.values(*[field.name for field in fields])
obj = obj.values(*[field.name for field in fields])

return list(obj)

# Managers are typically hidden fields, and must be specified via meta fields
@register_typemap(Manager)
Expand Down
5 changes: 2 additions & 3 deletions jsonate/widgets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from past.builtins import basestring
try:
import json
except ImportError:
Expand All @@ -12,6 +11,6 @@
class JsonateWidget(forms.Textarea):

def render(self, name, value, attrs=None, renderer=None):
if not isinstance(value, basestring):
if not isinstance(value, str):
value = jsonate(value, indent=2)
return super(JsonateWidget, self).render(name, value, attrs, renderer)
return super(JsonateWidget, self).render(name, value, attrs, renderer)
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
psycopg2-binary==2.8.4
django==3.0.4
pillow==7.0.0
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

setup(
name='jsonate',
version='0.5.1',
version='0.7.0',

author='James Robert',
author_email='jiaaro@gmail.com',

description=('Django library that can make ANYTHING into json'),
long_description=open('README.markdown').read(),
long_description_content_type="text/markdown",

license='MIT',
keywords='django json templatetags',

url='http://jsonate.com',

install_requires=[
"django>=1.7",
"future >= 0.16.0",
"django>=2.0",
],

packages=[
Expand Down
2 changes: 0 additions & 2 deletions test_project/manage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python
from __future__ import absolute_import

import os
import sys

Expand Down
2 changes: 0 additions & 2 deletions test_project/test_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2015-12-15 14:16
from __future__ import unicode_literals

import datetime
from decimal import Decimal
from django.conf import settings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import jsonate.fields

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import jsonate.fields
import test_app.models
Expand Down
2 changes: 0 additions & 2 deletions test_project/test_app/migrations/0004_auto_20180914_1341.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-09-14 13:41
from __future__ import unicode_literals

from django.db import migrations, models
import jsonate.fields
import test_app.models
Expand Down
2 changes: 0 additions & 2 deletions test_project/test_app/migrations/0005_auto_20180914_1343.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-09-14 13:43
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion

Expand Down
2 changes: 0 additions & 2 deletions test_project/test_app/migrations/0006_auto_20180914_1352.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-09-14 13:52
from __future__ import unicode_literals

from django.db import migrations


Expand Down
2 changes: 0 additions & 2 deletions test_project/test_app/migrations/0007_auto_20180914_1355.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-09-14 13:55
from __future__ import unicode_literals

from django.db import migrations, models


Expand Down
3 changes: 1 addition & 2 deletions test_project/test_app/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from builtins import object
from datetime import datetime, date
from decimal import Decimal

Expand Down Expand Up @@ -26,7 +25,7 @@ class MyModel(models.Model):
boolean_field = models.BooleanField(default=True)
null_field = models.NullBooleanField(default=None)

class Meta(object):
class Meta:
jsonate_exclude = ('sensitive_field1',)

class MyModelWithRelation(models.Model):
Expand Down
Loading