Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_command_instance: Support BaseCommand #6

Merged
merged 2 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions admintool_command/templates/admintool_command/command.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% endblock %}

{% block extrastyle %}{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% static " admin/css/forms.css" %}">
<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}">
{% endblock %}

{% block coltype %}colM{% endblock %}
Expand Down Expand Up @@ -45,4 +45,4 @@
</form>
</div>

{% endblock %}
{% endblock %}
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