Skip to content

Commit

Permalink
Ensure not having drf-gis in INSTALLED_APPS works anyway
Browse files Browse the repository at this point in the history
Addressing issue #68
  • Loading branch information
nemesifier committed Aug 25, 2015
1 parent 9b44696 commit db0fc5e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
21 changes: 17 additions & 4 deletions rest_framework_gis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,26 @@ def get_version():

default_app_config = 'rest_framework_gis.apps.AppConfig'

# retain support for django 1.5 and 1.6
# maintain support for django 1.5 and 1.6
# TODO: remove in version 1.0
try:
import django
import os
import django

if os.environ.get('DJANGO_SETTINGS_MODULE') and django.get_version() < '1.7':
if os.environ.get('DJANGO_SETTINGS_MODULE'):
from django.conf import settings
from .apps import AppConfig
AppConfig().ready()

if 'rest_framework_gis' not in settings.INSTALLED_APPS:
import warnings
warnings.simplefilter('always', DeprecationWarning)
warnings.warn('\nGeoModelSerializer is deprecated, '
'add "rest_framework_gis" to settings.INSTALLED_APPS and use '
'"rest_framework.ModelSerializer" instead',
DeprecationWarning)

if django.get_version() < '1.7' or 'rest_framework_gis' not in settings.INSTALLED_APPS:
import rest_framework_gis
AppConfig('rest_framework_gis', rest_framework_gis).ready()
except ImportError:
pass
3 changes: 2 additions & 1 deletion rest_framework_gis/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
except ImportError: # pragma: nocover
# django <= 1.6
class BaseConfig(object):
pass
def __init__(self, *args):
pass


class AppConfig(BaseConfig):
Expand Down
12 changes: 0 additions & 12 deletions rest_framework_gis/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ class GeoModelSerializer(ModelSerializer):
"""
Deprecated, will be removed in django-rest-framework-gis 1.0
"""
def __init__(self, *args, **kwargs): # pragma: no cover
# TODO: remove in 1.0
from .apps import AppConfig
import warnings
import rest_framework_gis
AppConfig('rest_framework_gis', rest_framework_gis).ready()
warnings.simplefilter('always', DeprecationWarning)
warnings.warn('\nGeoModelSerializer is deprecated, '
'add "rest_framework_gis" to settings.INSTALLED_APPS and use '
'"rest_framework.ModelSerializer" instead',
DeprecationWarning)
super(GeoModelSerializer, self).__init__(*args, **kwargs)


class GeoFeatureModelListSerializer(ListSerializer):
Expand Down

0 comments on commit db0fc5e

Please sign in to comment.