Skip to content

Commit

Permalink
Pull upstream changes, add support for Django 1.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
cchurch committed Jan 6, 2014
2 parents 0fd369b + 7f0cd38 commit 4e1f8c4
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 13 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Changelog
=========

0.0.7-1
-----
#. Fixes to support Django 1.5.

0.0.7
-----
#. Pass context to object_tools tag. Thanks `slafs <https://github.com/slafs>`_

0.0.6
-----
#. Corrected 'str' object has no attribute 'has_perm' bug `#7 <https://github.com/praekelt/django-export/issues/7>`_.

0.0.5-2
-------
#. Additional fixes to remove dependency on 'ADMIN_MEDIA_PREFIX' in Django 1.4.
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Now when you navigate to the change list view of any model you'll find the *dele

.. image:: https://github.com/downloads/praekelt/django-object-tools/delete-example-final.png

Clicking on the *Delete all* tool fires of the view and proceeds with deleting objects as per usual.
Clicking on the *Delete all* tool fires off the view and proceeds with deleting objects as per usual.

**Note:** ``django-object-tools`` adds per tool permissions to the built-in set of default Django permissions. So in this example only superusers or users who have the the *Can delete <model>* permission will be able to see and use the tool. If you can't see or use a particular tool make sure the authenticated user has the required permissions to do so.

14 changes: 12 additions & 2 deletions object_tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def __init__(self, model):
self.model = model
self.modeladmin = site._registry.get(model)

if self.modeladmin:
self.modeladmin_changelist_view = self.modeladmin.changelist_view
self.modeladmin.changelist_view = self.changelist_view

def changelist_view(self, request, extra_context=None):
"""
Simple wrapper to pass request to admin/change_list.html
"""
return self.modeladmin_changelist_view(request, extra_context={'request': request})

def construct_form(self, request):
"""
Constructs form from POST method using self.form_class.
Expand Down Expand Up @@ -52,8 +62,8 @@ def media(self, form):
"""
Collects admin and form media.
"""
js = ['js/core.js', 'js/admin/RelatedObjectLookups.js',
'js/jquery.min.js', 'js/jquery.init.js']
js = ['admin/js/core.js', 'admin/js/admin/RelatedObjectLookups.js',
'admin/js/jquery.min.js', 'admin/js/jquery.init.js']

admin_media_prefix = getattr(settings, 'ADMIN_MEDIA_PREFIX', '') or \
(getattr(settings, 'STATIC_URL', '') + 'admin/')
Expand Down
2 changes: 1 addition & 1 deletion object_tools/templates/admin/change_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
{% if has_add_permission %}
<ul class="object-tools">
{% block object-tools-items %}
{% object_tools cl.model request.user %}
{% object_tools cl.model user %}
<li>
<a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">
{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% for object_tool in object_tools %}
<li><a href="{{ object_tool.reverse }}" title="{{ object_tool.help_text }}"class="historylink">{{ object_tool.label }}</a></li>
<li><a href="{{ object_tool.reverse }}{% if request %}?{{ request.GET.urlencode }}{% endif %}" title="{{ object_tool.help_text }}"class="historylink">{{ object_tool.label }}</a></li>
{% endfor %}
7 changes: 4 additions & 3 deletions object_tools/templates/object_tools/tool_base.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{% extends "admin/base_site.html" %}
{% load url from future %}
{% load i18n admin_modify %}

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

{% block extrahead %}{{ block.super }}
<script type="text/javascript" src="{% url admin:jsi18n %}"></script>
<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
{{ media }}
{% endblock %}

{% block breadcrumbs %}{% if not is_popup %}
<div class="breadcrumbs">
<a href="{% url admin:index %}">{% trans "Home" %}</a> &rsaquo;
<a href="{% url admin:app_list app_label %}">{{ app_label|capfirst|escape }}</a> &rsaquo;
<a href="{% url 'admin:index' %}">{% trans "Home" %}</a> &rsaquo;
<a href="{% url 'admin:app_list' app_label %}">{{ app_label|capfirst|escape }}</a> &rsaquo;
<a href="{{changelist_url }}">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
{% trans tool.label %}
</div>
Expand Down
14 changes: 10 additions & 4 deletions object_tools/templatetags/object_tools_inclusion_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
register = template.Library()


@register.inclusion_tag('object_tools/inclusion_tags/object_tools.html')
def object_tools(model, user, exclude=None):
@register.inclusion_tag('object_tools/inclusion_tags/object_tools.html', takes_context=True)
def object_tools(context, model, user, exclude=None):
if inspect.isclass(model):
model_class = model
else:
Expand All @@ -28,5 +28,11 @@ def object_tools(model, user, exclude=None):
for tool in object_tools:
if tool.has_permission(user):
allowed_tools.append(tool)

return {'object_tools': allowed_tools}

ret_dict = {'object_tools': allowed_tools}
if context.has_key('request'):
ret_dict.update({
'request': context['request']
})

return ret_dict
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='django-object-tools',
version='0.0.5-2',
version='0.0.7-1',
description='Django app enabling painless creation of additional admin object tools.',
long_description = open('README.rst', 'r').read() + open('AUTHORS.rst', 'r').read() + open('CHANGELOG.rst', 'r').read(),
author='Praekelt Foundation',
Expand Down

0 comments on commit 4e1f8c4

Please sign in to comment.