Skip to content

Commit

Permalink
rename things around
Browse files Browse the repository at this point in the history
I'll probably have to do this again, but gotta start somewhere.
  • Loading branch information
crccheck committed Oct 20, 2012
1 parent 01afb91 commit ebb3db3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion django_object_actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.0.1"


from .utils import DjObjectTools as DjangoObjectActions
from .utils import DjangoObjectActions
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
which is "good enough".
{% endcomment %}
{% block object-tools %}{{ block.super }}
{% for tool, help in djtools %}
{% for tool, help in objectactions %}
<li class="djtool-item"><a href='tools/{{ tool }}/' title="{{ help }}">
{# White space deliberately inserted #}
{{ tool|capfirst }}
Expand Down
20 changes: 10 additions & 10 deletions django_object_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.views.generic.detail import SingleObjectMixin


class DjObjectTools(object):
class DjangoObjectActions(object):
"""
mixin to add object-tools just like you would add admin actions.
Expand All @@ -15,26 +15,26 @@ class DjObjectTools(object):
def toolfunc(self, request, obj)
They are exposed by putting them in a djobjecttools attribute in your
They are exposed by putting them in a `objectactions` attribute in your
modeladmin like:
class MyModelAdmin(DjObjectTools, admin.ModelAdmin):
class MyModelAdmin(DjangoObjectActions, admin.ModelAdmin):
def toolfunc(self, request, obj):
pass
toolfunc.short_description = "does nothing"
djobjecttools = ('toolfunc',)
objectactions = ('toolfunc',)
Why this functionality isn't baked into contrib.admin is beyond me.
TODO: get `form` and `change` so you can write tools that can also save
TODO: handle getting returned an HttpResponse
"""
change_form_template = "djobjecttools/change_form.html"
change_form_template = "django_object_actions/change_form.html"

def get_tool_urls(self):
tools = {}
for tool in self.djobjecttools:
for tool in self.objectactions:
tools[tool] = getattr(self, tool)
my_urls = patterns('',
(r'^(?P<pk>\d+)/tools/(?P<tool>\w+)/$', self.admin_site.admin_view(
Expand All @@ -43,14 +43,14 @@ def get_tool_urls(self):
return my_urls

def get_urls(self):
urls = super(DjObjectTools, self).get_urls()
urls = super(DjangoObjectActions, self).get_urls()
return self.get_tool_urls() + urls

def render_change_form(self, request, context, **kwargs):
context['djtools'] = [(x,
context['objectactions'] = [(x,
getattr(getattr(self, x), 'short_description', ''))
for x in self.djobjecttools]
return super(DjObjectTools, self).render_change_form(request,
for x in self.objectactions]
return super(DjangoObjectActions, self).render_change_form(request,
context, **kwargs)


Expand Down

0 comments on commit ebb3db3

Please sign in to comment.