Skip to content

Commit

Permalink
Remove dodgy get_version calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jarekwg committed Jul 6, 2016
1 parent aeaab80 commit 561ff00
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
18 changes: 9 additions & 9 deletions django_hstore/fields.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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']:
Expand Down
13 changes: 6 additions & 7 deletions django_hstore/widgets.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 13 additions & 13 deletions tests/django_hstore_tests/tests/test_schema_mode.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 561ff00

Please sign in to comment.