Skip to content

Commit

Permalink
get_command_instance: Support BaseCommand
Browse files Browse the repository at this point in the history
Allow use with normal un-enhanced commands,
albeit without any support for args.

Related to daadu#5
  • Loading branch information
jayvdb committed Aug 7, 2020
1 parent f2d5c7f commit c97e058
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion admintool_command/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from django import forms

from .command import AdminCommand

def get_full_class_name(app_name, command):
return "%s.management.commands.%s.Command" % (app_name, command)

Expand All @@ -11,7 +15,16 @@ def get_command_instance(app_name, command):
_module = import_module(".".join(module_name))
_class = getattr(_module, class_name)

return _class()
instance = _class()
if isinstance(instance, AdminCommand):
return instance

setattr(instance, "name", command)
setattr(instance, "Form", forms.Form)
setattr(instance, "template", "admintool_command/command.html")
setattr(instance, "init_context", lambda *args, **kwargs: {})
setattr(instance, "get_command_arguments", lambda *args, **kwargs: ([], {}))
return instance


def colourstrip(data):
Expand Down

0 comments on commit c97e058

Please sign in to comment.