diff --git a/djmoney_rates/backends.py b/djmoney_rates/backends.py index 3e11e17..b317216 100644 --- a/djmoney_rates/backends.py +++ b/djmoney_rates/backends.py @@ -6,7 +6,11 @@ from django.core.exceptions import ImproperlyConfigured from django.utils import six -from .compat import urlopen +try: + from urllib2 import urlopen +except ImportError: + from urllib.request import urlopen + from .exceptions import RateBackendError from .models import RateSource, Rate from .settings import money_rates_settings diff --git a/djmoney_rates/compat.py b/djmoney_rates/compat.py deleted file mode 100644 index 1ad8fe0..0000000 --- a/djmoney_rates/compat.py +++ /dev/null @@ -1,9 +0,0 @@ -try: - from urllib2 import urlopen -except ImportError: - from urllib.request import urlopen - -try: - from urllib2 import URLError -except ImportError: - from urllib.error import URLError diff --git a/djmoney_rates/management/commands/update_rates.py b/djmoney_rates/management/commands/update_rates.py index 47d41b8..c69d58d 100644 --- a/djmoney_rates/management/commands/update_rates.py +++ b/djmoney_rates/management/commands/update_rates.py @@ -6,15 +6,17 @@ class Command(BaseCommand): - args = '' help = 'Update rates for configured source' + def add_arguments(self, parser): + parser.add_argument('backend_path') + def handle(self, *args, **options): - if args: + if 'backend_path' in options and options['backend_path']: try: - backend_class = import_from_string(args[0], "") + backend_class = import_from_string(options['backend_path'], "") except ImportError: - raise CommandError("Cannot find custom backend %s. Is it correct" % args[0]) + raise CommandError("Cannot find custom backend %s. Is it correct" % options['backend_path']) else: backend_class = money_rates_settings.DEFAULT_BACKEND diff --git a/djmoney_rates/settings.py b/djmoney_rates/settings.py index e046cf9..d3e55f5 100644 --- a/djmoney_rates/settings.py +++ b/djmoney_rates/settings.py @@ -16,7 +16,12 @@ """ from django.conf import settings -from django.utils import importlib, six + +try: + from django.utils import importlib, six +except ImportError: + import importlib + import six USER_SETTINGS = getattr(settings, 'DJANGO_MONEY_RATES', None) @@ -105,4 +110,5 @@ def validate_setting(self, attr, val): if not val and attr in self.mandatory: raise AttributeError("django-money-rates setting: '%s' is mandatory" % attr) + money_rates_settings = MoneyRatesSettings(USER_SETTINGS, DEFAULTS, IMPORT_STRINGS, MANDATORY) diff --git a/tox.ini b/tox.ini index 831b740..cfbb302 100644 --- a/tox.ini +++ b/tox.ini @@ -27,7 +27,8 @@ commands = commands=python runtests.py deps = django18: Django==1.8.16 - -rrequirements/testing.txt + virtualenv<14 + -rrequirements-test.txt [testenv:flake8] deps =