Skip to content

Commit

Permalink
Merge pull request #28 from adepue/master
Browse files Browse the repository at this point in the history
Add 1.9 support
  • Loading branch information
Adam DePue committed Dec 3, 2015
2 parents 7453753 + a335611 commit a7f338d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 23 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ python:
- "2.7"
sudo: false
env:
- DJANGO_VERSION_CEILING=1.7 DJANGO_DB_ENGINE=sqlite
- DJANGO_VERSION_CEILING=1.7 DJANGO_DB_ENGINE=postgres DJANGO_DB_NAME=testdb DJANGO_DB_USER=postgres
- DJANGO_VERSION_CEILING=1.7 DJANGO_DB_ENGINE=mysql DJANGO_DB_NAME=testdb DJANGO_DB_USER=travis
- DJANGO_VERSION_CEILING=1.8 DJANGO_DB_ENGINE=sqlite
- DJANGO_VERSION_CEILING=1.8 DJANGO_DB_ENGINE=postgres DJANGO_DB_NAME=testdb DJANGO_DB_USER=postgres
- DJANGO_VERSION_CEILING=1.8 DJANGO_DB_ENGINE=mysql DJANGO_DB_NAME=testdb DJANGO_DB_USER=travis
- DJANGO_VERSION_CEILING=1.9 DJANGO_DB_ENGINE=sqlite
- DJANGO_VERSION_CEILING=1.9 DJANGO_DB_ENGINE=postgres DJANGO_DB_NAME=testdb DJANGO_DB_USER=postgres
- DJANGO_VERSION_CEILING=1.9 DJANGO_DB_ENGINE=mysql DJANGO_DB_NAME=testdb DJANGO_DB_USER=travis
Expand Down
2 changes: 1 addition & 1 deletion pylint.rc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load-plugins=pylint_django
[MESSAGES CONTROL]
# Errors only.
enable=E
disable=W,C,R,I,maybe-no-member
disable=W,C,R,I,maybe-no-member,super-on-old-class

[REPORTS]
# Don't display the complete report.
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@


install_requires = (
'Django>=1.6,<1.9',
'django-model-utils>=2.0,<2.4',
'Django>=1.8,<1.10',
'django-model-utils>=2.4,<3.0',
)


Expand Down Expand Up @@ -73,7 +73,7 @@ def run_tests(self):

setup(
name='django-livefield',
version='2.2.1',
version='2.3.0',
description='Convenient soft-deletion support for Django models',
long_description=(
open('README.rst').read() + '\n\n' +
Expand Down
7 changes: 4 additions & 3 deletions src/livefield/fields.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.db import models


# FIXME: Once pylint-django supports 1.7, remove this bypass.
class LiveField(models.NullBooleanField): # pylint: disable=no-member
class LiveField(models.NullBooleanField):
"""Support uniqueness constraints and soft-deletion.
Similar to a BooleanField, but stores False as NULL. This lets us use
Expand All @@ -12,7 +11,6 @@ class LiveField(models.NullBooleanField): # pylint: disable=no-member
"""
description = u'Soft-deletion status'
__metaclass__ = models.SubfieldBase

def __init__(self, *args, **kwargs):
super(LiveField, self).__init__(default=True, null=True)
Expand All @@ -23,6 +21,9 @@ def get_prep_value(self, value):
return super(LiveField, self).get_prep_value(True)
return None

def from_db_value(self, value, expression, connection, context):
return bool(value)

def to_python(self, value):
# Somewhat misleading name, since this type coercion also occurs when
# assigning a value to the field in Python.
Expand Down
13 changes: 8 additions & 5 deletions src/livefield/gis/managers.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from model_utils.managers import PassThroughManager
from django.db import models

from .querysets import LiveGeoQuerySet


class LiveGeoManager(PassThroughManager):
LiveGeoManagerBase = models.Manager.from_queryset(LiveGeoQuerySet)


class LiveGeoManager(LiveGeoManagerBase):
# To also use this manager for FK lookups, see
# https://docs.djangoproject.com/en/1.6/topics/db/managers/#manager-types.

def __init__(self, queryset_cls=LiveGeoQuerySet, include_soft_deleted=False, *args, **kwargs):
def __init__(self, include_soft_deleted=False, *args, **kwargs):
self.include_soft_deleted = include_soft_deleted
super(LiveGeoManager, self).__init__(queryset_cls=queryset_cls, *args, **kwargs)
super(LiveGeoManager, self).__init__(*args, **kwargs) # pylint: disable=super-on-old-class

def get_queryset(self):
qs = super(LiveGeoManager, self).get_queryset()
qs = super(LiveGeoManager, self).get_queryset() # pylint: disable=super-on-old-class
if not self.include_soft_deleted:
return qs.live()
return qs
13 changes: 8 additions & 5 deletions src/livefield/managers.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from model_utils.managers import PassThroughManager
from django.db import models

from .querysets import LiveQuerySet


class LiveManager(PassThroughManager):
LiveManagerBase = models.Manager.from_queryset(LiveQuerySet)


class LiveManager(LiveManagerBase):
# To also use this manager for FK lookups, see
# https://docs.djangoproject.com/en/1.6/topics/db/managers/#manager-types.

def __init__(self, queryset_cls=LiveQuerySet, include_soft_deleted=False, *args, **kwargs):
def __init__(self, include_soft_deleted=False, *args, **kwargs):
self.include_soft_deleted = include_soft_deleted
super(LiveManager, self).__init__(queryset_cls=queryset_cls, *args, **kwargs)
super(LiveManager, self).__init__(*args, **kwargs) # pylint: disable=super-on-old-class

def get_queryset(self):
qs = super(LiveManager, self).get_queryset()
qs = super(LiveManager, self).get_queryset() # pylint: disable=super-on-old-class
if not self.include_soft_deleted:
return qs.live()
return qs
4 changes: 4 additions & 0 deletions tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ def test_truthy_values_dont_delete(self):
for name, val in enumerate(['truthy', 11, long(6), True, (1, 3)]):
obj = Person(name=name)
obj.live = val
obj.save()
obj.refresh_from_db()
# Use 'is' to make sure that we're returning bools.
self.assertTrue(obj.live is True)

def test_falsy_values_delete(self):
for name, val in enumerate(['', 0, False, {}, None]):
obj = Person(name=name)
obj.live = val
obj.save()
obj = Person.all_objects.get(id=obj.id)
# Again, use 'is' to make sure that we're returning bools.
self.assertTrue(obj.live is False)

Expand Down

0 comments on commit a7f338d

Please sign in to comment.