diff --git a/django_hstore/fields.py b/django_hstore/fields.py index fa0e9ad..d4fd146 100644 --- a/django_hstore/fields.py +++ b/django_hstore/fields.py @@ -1,17 +1,17 @@ -from __future__ import unicode_literals, absolute_import -import json +from __future__ import absolute_import, unicode_literals + import datetime -from pkg_resources import parse_version +import json +import django from django.db import models -from django.utils.translation import ugettext_lazy as _ from django.utils import six -from django import get_version +from django.utils.translation import ugettext_lazy as _ +from . import forms, utils from .descriptors import HStoreDescriptor, HStoreReferenceDescriptor, SerializedDictDescriptor from .dict import HStoreDict, HStoreReferenceDict from .virtual import create_hstore_virtual_field -from . import forms, utils class HStoreField(models.Field): @@ -72,7 +72,7 @@ def south_field_triple(self): # pragma no cover return name, args, kwargs -if parse_version(get_version()) >= parse_version('1.7'): +if django.VERSION >= (1, 7): from .lookups import (HStoreGreaterThan, HStoreGreaterThanOrEqual, HStoreLessThan, HStoreLessThanOrEqual, HStoreContains, HStoreIContains, HStoreIsNull) @@ -195,7 +195,7 @@ def _remove_hstore_virtual_fields(self): delattr(cls, field_name) delattr(cls, '_hstore_virtual_fields') # django >= 1.8 - if parse_version(get_version()[0:3]) >= parse_version('1.8'): + if django.VERSION >= (1, 8): # remove all hstore virtual fields from meta hstore_fields = [] # get all the existing hstore virtual fields @@ -210,7 +210,7 @@ def _remove_hstore_virtual_fields(self): # cls._meta.fields.__class__ == ImmutableList cls._meta.fields = cls._meta.fields.__class__(fields) # django <= 1.7 - # TODO: will removed when django 1.7 will be deprecated + # TODO: Remove this when django 1.7 is no longer supported. else: # remove all hstore virtual fields from meta for meta_fields in ['fields', 'local_fields', 'virtual_fields']: diff --git a/django_hstore/widgets.py b/django_hstore/widgets.py index 3b1e328..2c176aa 100644 --- a/django_hstore/widgets.py +++ b/django_hstore/widgets.py @@ -1,14 +1,13 @@ -from __future__ import unicode_literals, absolute_import -from pkg_resources import parse_version +from __future__ import absolute_import, unicode_literals -from django import forms, get_version -from django.contrib.admin.widgets import AdminTextareaWidget +import django +from django import forms +from django.conf import settings from django.contrib.admin.templatetags.admin_static import static +from django.contrib.admin.widgets import AdminTextareaWidget from django.template import Context from django.template.loader import get_template from django.utils.safestring import mark_safe -from django.conf import settings - __all__ = [ 'AdminHStoreWidget' @@ -45,7 +44,7 @@ def render(self, name, value, attrs=None): template_context = Context({ 'field_name': name, 'STATIC_URL': settings.STATIC_URL, - 'use_svg': parse_version(get_version()) >= parse_version('1.9'), # use svg icons if django >= 1.9 + 'use_svg': django.VERSION >= (1, 9), # use svg icons if django >= 1.9 }) # get template object template = get_template('hstore_%s_widget.html' % self.admin_style) diff --git a/tests/django_hstore_tests/tests/test_schema_mode.py b/tests/django_hstore_tests/tests/test_schema_mode.py index 4d2d383..ccbad43 100644 --- a/tests/django_hstore_tests/tests/test_schema_mode.py +++ b/tests/django_hstore_tests/tests/test_schema_mode.py @@ -1,25 +1,25 @@ # -*- coding: utf-8 -*- import os -import sys import shutil +import sys -if sys.version_info[0] >= 3: - from io import StringIO -else: - from StringIO import StringIO +from django_hstore_tests.models import NullSchemaDataBag, SchemaDataBag -from django import VERSION as DJANGO_VERSION -from django.db import models +import django +from django.contrib.auth.models import User from django.core.exceptions import ValidationError -from django.core.urlresolvers import reverse from django.core.management import call_command -from django.contrib.auth.models import User +from django.core.urlresolvers import reverse +from django.db import models from django.test import TestCase from django_hstore import hstore from django_hstore.virtual import create_hstore_virtual_field -from django_hstore_tests.models import SchemaDataBag, NullSchemaDataBag +if sys.version_info[0] >= 3: + from io import StringIO +else: + from StringIO import StringIO MIGRATION_PATH = '{0}/../{1}'.format(os.path.dirname(__file__), 'migrations') @@ -287,7 +287,7 @@ def test_str(self): d = SchemaDataBag() self.assertEqual(str(d.data), '{}') - if DJANGO_VERSION[:2] >= (1, 8): + if django.VERSION >= (1, 8): def test_reload_schema(self): # cache some stuff f = SchemaDataBag._meta.get_field('data') @@ -396,7 +396,7 @@ def test_none_handling(self): self.assertEqual(d.char, '') self.assertEqual(d.number, 0) - if DJANGO_VERSION[:2] >= (1, 7): + if django.VERSION >= (1, 7): def _test_migrations_issue_103(self): """ failing test for https://github.com/djangonauts/django-hstore/issues/103 """ # start capturing output @@ -454,6 +454,6 @@ def _test_migrations_issue_117(self): def test_migrations(self): self._test_migrations_issue_117() # changes in django 1.8 make this test obsolete - if DJANGO_VERSION[:2] == (1, 7): + if django.VERSION == (1, 7): self._test_migrations_issue_103() TestSchemaMode._delete_migrations()