Skip to content

Commit

Permalink
Merge 9c207e5 into e1395c6
Browse files Browse the repository at this point in the history
  • Loading branch information
treyhunner committed Apr 9, 2013
2 parents e1395c6 + 9c207e5 commit 1cdabc9
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 63 deletions.
14 changes: 9 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ python:
- "2.7"

env:
- DJANGO=Django==1.2.7 SOUTH=1
- DJANGO=Django==1.3.7 SOUTH=1
- DJANGO=Django==1.4.5 SOUTH=1
- DJANGO=Django==1.4.5 SOUTH=1
- DJANGO=Django==1.5 SOUTH=1
- DJANGO=Django==1.5.1 SOUTH=1
- DJANGO=https://github.com/django/django/tarball/master SOUTH=1
- DJANGO=Django==1.4.5 SOUTH=0
- DJANGO=Django==1.5.1 SOUTH=0

install:
- pip install $DJANGO --use-mirrors
Expand All @@ -20,4 +17,11 @@ install:

script: coverage run -a --branch --include="model_utils/*" --omit="model_utils/tests/*" setup.py test

matrix:
include:
- python: 3.3
env: DJANGO=Django==1.5.1 SOUTH=0
- python: 3.3
env: DJANGO=https://github.com/django/django/tarball/master SOUTH=0

after_success: coveralls
5 changes: 4 additions & 1 deletion model_utils/choices.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import unicode_literals


class Choices(object):
"""
A class to encapsulate handy functionality for lists of choices
Expand Down Expand Up @@ -72,4 +75,4 @@ def __getitem__(self, index):

def __repr__(self):
return '%s(%s)' % (self.__class__.__name__,
', '.join(("%s" % str(i) for i in self._full)))
', '.join(("%s" % repr(i) for i in self._full)))
6 changes: 4 additions & 2 deletions model_utils/fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import unicode_literals
from datetime import datetime

from django.db import models
from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible


try:
Expand Down Expand Up @@ -128,6 +130,7 @@ def get_excerpt(content):

return '\n'.join(default_excerpt)

@python_2_unicode_compatible
class SplitText(object):
def __init__(self, instance, field_name, excerpt_field_name):
# instead of storing actual values store a reference to the instance
Expand All @@ -153,8 +156,7 @@ def _get_has_more(self):
return self.excerpt.strip() != self.content.strip()
has_more = property(_get_has_more)

# allows display via templates without .content necessary
def __unicode__(self):
def __str__(self):
return self.content

class SplitDescriptor(object):
Expand Down
3 changes: 2 additions & 1 deletion model_utils/managers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
import django
from django.db import models
from django.db.models.fields.related import OneToOneField
Expand Down Expand Up @@ -38,7 +39,7 @@ def _clone(self, klass=None, setup=False, **kwargs):

def annotate(self, *args, **kwargs):
qset = super(InheritanceQuerySet, self).annotate(*args, **kwargs)
qset._annotated = [a.default_alias for a in args] + kwargs.keys()
qset._annotated = [a.default_alias for a in args] + list(kwargs.keys())
return qset


Expand Down
1 change: 1 addition & 0 deletions model_utils/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from datetime import datetime

from django.db import models
Expand Down
54 changes: 27 additions & 27 deletions model_utils/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import with_statement
from __future__ import unicode_literals, with_statement
import pickle

from datetime import datetime, timedelta

import django
from django.db import models
from django.db.models.fields import FieldDoesNotExist
from django.utils.six import text_type
from django.core.exceptions import ImproperlyConfigured, FieldError
from django.test import TestCase

Expand Down Expand Up @@ -47,8 +48,8 @@ def test_middle_of_line(self):


class SplitFieldTests(TestCase):
full_text = u'summary\n\n<!-- split -->\n\nmore'
excerpt = u'summary\n'
full_text = 'summary\n\n<!-- split -->\n\nmore'
excerpt = 'summary\n'


def setUp(self):
Expand All @@ -57,7 +58,7 @@ def setUp(self):


def test_unicode_content(self):
self.assertEquals(unicode(self.post.body), self.full_text)
self.assertEquals(text_type(self.post.body), self.full_text)


def test_excerpt(self):
Expand Down Expand Up @@ -85,17 +86,17 @@ def test_load_back(self):


def test_assign_to_body(self):
new_text = u'different\n\n<!-- split -->\n\nother'
new_text = 'different\n\n<!-- split -->\n\nother'
self.post.body = new_text
self.post.save()
self.assertEquals(unicode(self.post.body), new_text)
self.assertEquals(text_type(self.post.body), new_text)


def test_assign_to_content(self):
new_text = u'different\n\n<!-- split -->\n\nother'
new_text = 'different\n\n<!-- split -->\n\nother'
self.post.body.content = new_text
self.post.save()
self.assertEquals(unicode(self.post.body), new_text)
self.assertEquals(text_type(self.post.body), new_text)


def test_assign_to_excerpt(self):
Expand All @@ -118,7 +119,7 @@ def test_none(self):
def test_assign_splittext(self):
a = Article(title='Some Title')
a.body = self.post.body
self.assertEquals(a.body.excerpt, u'summary\n')
self.assertEquals(a.body.excerpt, 'summary\n')


def test_value_to_string(self):
Expand Down Expand Up @@ -198,10 +199,10 @@ def test_len(self):


def test_repr(self):
self.assertEquals(repr(self.STATUS),
"Choices("
"('DRAFT', 'DRAFT', 'DRAFT'), "
"('PUBLISHED', 'PUBLISHED', 'PUBLISHED'))")
self.assertEquals(repr(self.STATUS), "Choices" + repr((
('DRAFT', 'DRAFT', 'DRAFT'),
('PUBLISHED', 'PUBLISHED', 'PUBLISHED'),
)))


def test_wrong_length_tuple(self):
Expand Down Expand Up @@ -243,11 +244,11 @@ def test_len(self):


def test_repr(self):
self.assertEquals(repr(self.STATUS),
"Choices("
"('DRAFT', 'DRAFT', 'is draft'), "
"('PUBLISHED', 'PUBLISHED', 'is published'), "
"('DELETED', 'DELETED', 'DELETED'))")
self.assertEquals(repr(self.STATUS), "Choices" + repr((
('DRAFT', 'DRAFT', 'is draft'),
('PUBLISHED', 'PUBLISHED', 'is published'),
('DELETED', 'DELETED', 'DELETED'),
)))



Expand Down Expand Up @@ -279,12 +280,11 @@ def test_len(self):


def test_repr(self):
self.assertEquals(repr(self.STATUS),
"Choices("
"(0, 'DRAFT', 'is draft'), "
"(1, 'PUBLISHED', 'is published'), "
"(2, 'DELETED', 'is deleted'))")

self.assertEquals(repr(self.STATUS), "Choices" + repr((
(0, 'DRAFT', 'is draft'),
(1, 'PUBLISHED', 'is published'),
(2, 'DELETED', 'is deleted'),
)))


class InheritanceManagerTests(TestCase):
Expand Down Expand Up @@ -644,15 +644,15 @@ class ModelTrackerTestCase(TestCase):

def assertHasChanged(self, **kwargs):
tracker = kwargs.pop('tracker', self.tracker)
for field, value in kwargs.iteritems():
for field, value in kwargs.items():
if value is None:
self.assertRaises(FieldError, tracker.has_changed, field)
else:
self.assertEqual(tracker.has_changed(field), value)

def assertPrevious(self, **kwargs):
tracker = kwargs.pop('tracker', self.tracker)
for field, value in kwargs.iteritems():
for field, value in kwargs.items():
self.assertEqual(tracker.previous(field), value)

def assertChanged(self, **kwargs):
Expand All @@ -664,7 +664,7 @@ def assertCurrent(self, **kwargs):
self.assertEqual(tracker.current(), kwargs)

def update_instance(self, **kwargs):
for field, value in kwargs.iteritems():
for field, value in kwargs.items():
setattr(self.instance, field, value)
self.instance.save()

Expand Down
3 changes: 2 additions & 1 deletion model_utils/tracker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from django.db import models
from django.core.exceptions import FieldError

Expand Down Expand Up @@ -74,6 +75,6 @@ def changed(self):
"""Returns dict of fields that changed since save (with old values)"""
if not self.instance.pk:
return {}
saved = self.saved_data.iteritems()
saved = self.saved_data.items()
current = self.current()
return dict((k, v) for k, v in saved if v != current[k])
36 changes: 10 additions & 26 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist=py26-1.2,py26-1.3,py26-1.4,py26,py26-trunk,py27-1.2,py27-1.3,py27-1.4,py27,py27-trunk,py27-nosouth
envlist=py26-1.4,py26,py26-trunk,py27-1.4,py27,py27-trunk,py27-nosouth,py33-1.5-nosouth,py33-trunk-nosouth

[testenv]
deps=
Expand All @@ -8,20 +8,6 @@ deps=
coverage==3.6
commands=coverage run -a --branch setup.py test

[testenv:py26-1.2]
basepython=python2.6
deps=
django==1.2.7
South==0.7.6
coverage==3.6

[testenv:py26-1.3]
basepython=python2.6
deps=
django==1.3.7
South==0.7.6
coverage==3.6

[testenv:py26-1.4]
basepython=python2.6
deps=
Expand All @@ -36,32 +22,30 @@ deps=
South==0.7.6
coverage==3.6

[testenv:py27-1.2]
[testenv:py27-1.4]
basepython=python2.7
deps=
django==1.2.7
django==1.4.5
South==0.7.6
coverage==3.6

[testenv:py27-1.3]
[testenv:py27-trunk]
basepython=python2.7
deps=
django==1.3.7
https://github.com/django/django/tarball/master
South==0.7.6
coverage==3.6

[testenv:py27-1.4]
basepython=python2.7
[testenv:py33-1.5-nosouth]
basepython=python3.3
deps=
django==1.4.5
South==0.7.6
django==1.5.0
coverage==3.6

[testenv:py27-trunk]
basepython=python2.7
[testenv:py33-trunk-nosouth]
basepython=python3.3
deps=
https://github.com/django/django/tarball/master
South==0.7.6
coverage==3.6


Expand Down

0 comments on commit 1cdabc9

Please sign in to comment.