Skip to content

Commit 0a27184

Browse files
committed
add some more docs here in there as I try and remember what I wrote
1 parent 4fb1e8a commit 0a27184

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

django_object_actions/utils.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,18 @@ def to_dict(tool_name):
5959
##################
6060

6161
def get_object_actions(self, request, context, **kwargs):
62+
"""Override this to customize what actions get sent."""
6263
return self.objectactions
6364

6465
def get_djoa_button_attrs(self, tool):
66+
"""
67+
Get the HTML attributes associated with a tool.
68+
69+
There are some standard attributes (class and title) that the template
70+
will always want. Any number of additional attributes can be specified
71+
and passed on. This is kinda awkward and due for a refactor for
72+
readability.
73+
"""
6574
attrs = getattr(tool, 'attrs', {})
6675
# href is not allowed to be set. should an exception be raised instead?
6776
if 'href' in attrs:
@@ -101,7 +110,7 @@ def get(self, request, **kwargs):
101110
try:
102111
ret = self.tools[kwargs['tool']](request, obj)
103112
except KeyError:
104-
raise Http404
113+
raise Http404(u'Tool does not exist')
105114
if isinstance(ret, HttpResponse):
106115
return ret
107116
back = request.path.rsplit('/', 3)[0] + '/'
@@ -117,7 +126,13 @@ def message_user(self, request, message):
117126

118127

119128
class QuerySetIsh(QuerySet):
120-
"""Takes an instance and mimics it coming from a QuerySet."""
129+
"""
130+
Takes an instance and mimics it coming from a QuerySet.
131+
132+
This is a hack to support the `takes_instance_or_queryset` decorator so
133+
that you can re-use functions written for standard Django admin actions and
134+
use them for Object Tools too.
135+
"""
121136
def __init__(self, instance=None, *args, **kwargs):
122137
try:
123138
model = instance._meta.model
@@ -141,7 +156,7 @@ def get(self, *args, **kwargs):
141156

142157

143158
def takes_instance_or_queryset(func):
144-
"""Decorator that makes standard actions compatible."""
159+
"""Decorator that makes standard Django admin actions compatible."""
145160
@wraps(func)
146161
def decorated_function(self, request, queryset):
147162
# func follows the prototype documented at:

0 commit comments

Comments
 (0)