Skip to content

Commit

Permalink
Horrible hacks to use the native JSONField when available. Bump versi…
Browse files Browse the repository at this point in the history
…on to 1.1.0
  • Loading branch information
eranrund committed Jul 18, 2016
1 parent dcdb9ba commit 2982414
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 13 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Version 1.1.0 (UNRELEASED)
Version 1.1.0 (UNRELEASED) - HAS BREAKING CHANGES
===========================================================
* Switched to testing with PostgreSQL
* Switch to using native JSONField on Django>=1.9. If you
are upgrading an existing installation you will need to
execute the following SQL command manually:
`ALTER TABLE "papertrail_entry" ALTER COLUMN "data" TYPE jsonb USING "data"::jsonb;`
This is because there is no easy way to change the
underlying field AND dropping the dependency on django-jsonfield
at the same time. Sorry :(


Version 1.0.5 (2016-06-22)
Expand Down
2 changes: 1 addition & 1 deletion papertrail/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.0.5'
__version__ = '1.1.0'
default_app_config = 'papertrail.apps.PapertrailConfig'
9 changes: 9 additions & 0 deletions papertrail/fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Attempt to use the built-in PostgreSQL json field, but if that is not
# available try the 3rd party jsonfield one.
try:
from django.contrib.postgres.fields import JSONField as BaseJSONField
except:
from jsonfield.fields import JSONField as BaseJSONField

class JSONField(BaseJSONField):
pass
4 changes: 2 additions & 2 deletions papertrail/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import jsonfield.fields
import papertrail.fields
from django.db import migrations, models


Expand All @@ -19,7 +19,7 @@ class Migration(migrations.Migration):
('timestamp', models.DateTimeField(db_index=True)),
('type', models.CharField(max_length=50, db_index=True)),
('message', models.CharField(max_length=512)),
('data', jsonfield.fields.JSONField(null=True)),
('data', papertrail.fields.JSONField(null=True)),
('external_key', models.CharField(max_length=255, null=True, db_index=True)),
],
options={
Expand Down
4 changes: 2 additions & 2 deletions papertrail/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import logging

import jsonfield.fields
from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models, transaction
from django.utils import timezone

from papertrail import signals
from papertrail.fields import JSONField

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -202,7 +202,7 @@ class Entry(models.Model, ModelWithRelatedObjectsMixin):
timestamp = models.DateTimeField(db_index=True)
type = models.CharField(max_length=50, db_index=True)
message = models.CharField(max_length=512)
data = jsonfield.fields.JSONField(null=True)
data = JSONField(null=True)

# Field for storing a custom 'key' for looking up specific events from
# external sources. This can be used to quickly and precisely look up
Expand Down
1 change: 0 additions & 1 deletion papertrail/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
django-jsonfield>=0.8.11
django-apptemplates>=1.0
six
13 changes: 12 additions & 1 deletion papertrail/tests.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import unittest
from django import VERSION as django_version
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.contrib.contenttypes.models import ContentType
from django.dispatch import receiver
from django.test import TestCase
from django.utils import timezone

from papertrail import log, signals
from papertrail.models import Entry, related_to_q, replace_object_in_papertrail

Expand Down Expand Up @@ -158,3 +159,13 @@ def test_objects_represented(self):
Entry.objects.filter(type='test-entry').objects_not_represented(all_users, 'user').get(),
user3
)

@unittest.skipIf(django_version < (1, 9), 'no native JSONField')
def test_json_field_filtering(self):
log('test', 'test', data={
'field': 'value',
})

self.assertTrue(
Entry.objects.filter(data__field='value').exists()
)
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

setup(
name='django-papertrail',
version='1.0.5',
version='1.1.0',
packages=['papertrail'],
install_requires=[
'Django>=1.7',
'django-jsonfield>=0.8.11',
'six',
'django-apptemplates',
],
Expand Down
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ basepython =
commands = make test
deps =
psycopg2
django14: Django>=1.4,<1.5
django15: Django>=1.5,<1.6
django16: Django>=1.6,<1.7
django-jsonfield
django17: Django>=1.7,<1.8
django18: Django>=1.8,<1.9
django19: Django>=1.9,<1.10
Expand Down

0 comments on commit 2982414

Please sign in to comment.