forked from sbussetti/django-admincommand
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
58 lines (43 loc) · 1.6 KB
/
models.py
File metadata and controls
58 lines (43 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from django import forms
from sneak.models import SneakModel
from admincommand.utils import generate_instance_name, generate_human_name
class AdminCommand(SneakModel):
"""Subclass this class to create an admin command
class name should match the name of the command to be executed
using the reverse algorithm used to construct instance names following
the PEP8. For instance for a management command named
``fixing_management_policy`` the admin command class should be named
``FixingManagementPolicy``.
"""
# :attribute asynchronous: True if the command should be executed
# asynchronously
asynchronous = False
objects = None
class form(forms.Form):
pass
def __init__(self, *args, **kwargs):
super(AdminCommand, self).__init__(*args, **kwargs)
def get_help(self):
if hasattr(self, 'help'):
return self.help
return self.command().help
def command(self):
"""Getter of the management command import core"""
import core
command = core.get_command(self.command_name())
return command
@classmethod
def command_name(cls):
return generate_instance_name(cls.__name__)
def name(self):
return generate_human_name(type(self).__name__)
def url_name(self):
return type(self).__name__.lower()
@classmethod
def permission_codename(cls):
return 'can_run_command_%s' % cls.command_name()
@classmethod
def all(cls):
import core
for runnable_command in core.get_admin_commands().values():
yield runnable_command