Skip to content

Commit 98576d6

Browse files
committed
Fix issues with django 1.10 and 1.11
1 parent 026141a commit 98576d6

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

djclick/adapter.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,33 @@
55

66
import click
77

8-
from django import get_version
8+
from django import get_version, VERSION as DJANGO_VERSION
99
from django.core.management import CommandError
1010

1111

12-
class ParserAdapter(object):
12+
class OptionParseAdapter(object):
1313
def parse_args(self, args):
1414
return (self, None)
1515

1616

17+
class ArgumentParserDefaults(object):
18+
def __init__(self, args):
19+
self._args = args
20+
21+
def _get_kwargs(self):
22+
return {
23+
'args': self._args,
24+
}
25+
26+
27+
class ArgumentParserAdapter(object):
28+
def __init__(self):
29+
self._actions = []
30+
31+
def parse_args(self, args):
32+
return ArgumentParserDefaults(args)
33+
34+
1735
class DjangoCommandMixin(object):
1836
use_argparse = False
1937
option_list = []
@@ -38,7 +56,10 @@ def create_parser(self, progname, subcommand):
3856
"""
3957
Called when run through `call_command`.
4058
"""
41-
return ParserAdapter()
59+
if DJANGO_VERSION >= (1, 10):
60+
return ArgumentParserAdapter()
61+
else:
62+
return OptionParseAdapter()
4263

4364
def print_help(self, prog_name, subcommand):
4465
self.main(['--help'], standalone_mode=False)

djclick/test/test_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_django_color(capsys):
184184

185185
def test_django_help(manage):
186186
# The -h/--help switches cause the program to exit. Invoking the command
187-
# through execute_from_command_line would cause the test suit to exit as
187+
# through execute_from_command_line would cause the test suite to exit as
188188
# well... this means that we have to call it in a subprocess.
189189
helps = [
190190
manage('helpcmd', '-h'),

0 commit comments

Comments
 (0)