Skip to content

Commit cd9b5c6

Browse files
committed
fix some deprecation warnings
1 parent c3ed8d3 commit cd9b5c6

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

select_url_field/fields.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import re
2-
import os.path
32

43
from django import forms
54
from django.core.exceptions import ValidationError
65
from django.core.validators import URLValidator
76
from django.db import models
8-
from django.db import IntegrityError
9-
from django.template.defaultfilters import filesizeformat
107
from django.utils.translation import ugettext_lazy as _
118
from django.utils.encoding import smart_unicode
12-
from django.utils import importlib
9+
try:
10+
from importlib import import_module
11+
except ImportError:
12+
# Django < 1.9 and Python < 2.7
13+
from django.utils.importlib import import_module
1314

1415
from select_url_field.choice_with_other import ChoiceWithOtherField
1516

@@ -18,7 +19,7 @@ class SelectURLField(models.CharField):
1819

1920
def __init__(self, verbose_name=None, name=None, **kwargs):
2021
kwargs['max_length'] = kwargs.get('max_length', 200)
21-
# handle choices option:
22+
# Handle choices option:
2223
# from custom_site.url_choices import get_url_choices
2324
# link = SelectURLField(blank=True, choices=get_url_choices)
2425
self._has_choices = False
@@ -35,8 +36,8 @@ def formfield(self, **kwargs):
3536
'form_class': SelectURLFormField,
3637
}
3738
defaults.update(kwargs)
38-
## when choices given, use them.
39-
## when not, use global settings.
39+
# When choices given, use them.
40+
# When not, use global settings
4041
if self._has_choices:
4142
if callable(self._url_choices):
4243
choices = self._url_choices()
@@ -46,7 +47,7 @@ def formfield(self, **kwargs):
4647
from django.conf import settings
4748
mod_path, func_name = settings.URL_CHOICES_FUNC.rsplit('.', 1)
4849
mod = importlib.import_module(mod_path)
49-
choices_func = getattr(mod, func_name)
50+
choices_func = getattr(mod, func_name)
5051
choices = choices_func()
5152
required = not self.blank
5253
return ChoiceWithOtherField(choices=choices, required=required)
@@ -59,11 +60,10 @@ def to_python(self, value):
5960
if domain:
6061
domain_pattern = r'^(?:http|ftp)s?://' + domain
6162
domain_regex = re.compile(domain_pattern, re.IGNORECASE)
62-
#match = domain_regex.search(value)
6363
value = domain_regex.sub('', value)
6464
return super(SelectURLField, self).to_python(value)
6565

66-
#We need IxxyURLField so this is backwards compatible
66+
# We need IxxyURLField so this is backwards compatible
6767
IxxyURLField = SelectURLField
6868

6969
class SelectURLValidator(object):
@@ -75,10 +75,10 @@ def __init__(self):
7575

7676
def __call__(self, value):
7777
try:
78-
#OK if it's a valid url
78+
# OK if it's a valid url
7979
self.url_validator(value)
8080
except ValidationError, e:
81-
#Not a valid url, see it's a path
81+
# Not a valid url, see it's a path
8282
if not self.regex.search(smart_unicode(value)):
8383
raise e
8484

@@ -91,7 +91,9 @@ def __init__(self, max_length=None, min_length=None, *args, **kwargs):
9191
super(SelectURLFormField, self).__init__(max_length, min_length, *args, **kwargs)
9292
self.validators.append(SelectURLValidator())
9393

94-
95-
from south.modelsinspector import add_introspection_rules
96-
add_introspection_rules([], ["^select_url_field\.fields\.IxxyURLField"])
97-
add_introspection_rules([], ["^select_url_field\.fields\.SelectURLField"])
94+
try:
95+
from south.modelsinspector import add_introspection_rules
96+
add_introspection_rules([], ["^select_url_field\.fields\.IxxyURLField"])
97+
add_introspection_rules([], ["^select_url_field\.fields\.SelectURLField"])
98+
except ImportError:
99+
pass

0 commit comments

Comments
 (0)