From 9914515735cb61b4cb9504efeb949c3aa134d5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Ehlert?= Date: Wed, 26 Oct 2011 16:43:23 +0200 Subject: [PATCH 01/10] make object_tools inclusion tag to take context and return context --- .../object_tools/inclusion_tags/object_tools.html | 2 +- .../templatetags/object_tools_inclusion_tags.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/object_tools/templates/object_tools/inclusion_tags/object_tools.html b/object_tools/templates/object_tools/inclusion_tags/object_tools.html index 8e5d545..530573e 100644 --- a/object_tools/templates/object_tools/inclusion_tags/object_tools.html +++ b/object_tools/templates/object_tools/inclusion_tags/object_tools.html @@ -1,3 +1,3 @@ {% for object_tool in object_tools %} -
  • {{ object_tool.label }}
  • +
  • {{ object_tool.label }}
  • {% endfor %} diff --git a/object_tools/templatetags/object_tools_inclusion_tags.py b/object_tools/templatetags/object_tools_inclusion_tags.py index 1cfef63..7800137 100644 --- a/object_tools/templatetags/object_tools_inclusion_tags.py +++ b/object_tools/templatetags/object_tools_inclusion_tags.py @@ -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: @@ -28,5 +28,9 @@ def object_tools(model, user, exclude=None): for tool in object_tools: if tool.has_permission(user): allowed_tools.append(tool) + + ret_dict = {'object_tools': allowed_tools } + if context.has_key('request'): + return template.RequestContext(context['request'], ret_dict) - return {'object_tools': allowed_tools} + return ret_dict From 62a4cc68162853396aa0c35ad9f2e8d8b4ca2e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Ehlert?= Date: Wed, 26 Oct 2011 17:56:14 +0300 Subject: [PATCH 02/10] better conditional href --- .../templates/object_tools/inclusion_tags/object_tools.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/object_tools/templates/object_tools/inclusion_tags/object_tools.html b/object_tools/templates/object_tools/inclusion_tags/object_tools.html index 530573e..fb98648 100644 --- a/object_tools/templates/object_tools/inclusion_tags/object_tools.html +++ b/object_tools/templates/object_tools/inclusion_tags/object_tools.html @@ -1,3 +1,3 @@ {% for object_tool in object_tools %} -
  • {{ object_tool.label }}
  • +
  • {{ object_tool.label }}
  • {% endfor %} From 08c541275823fe17756189e28d2623abd2f20a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Ehlert?= Date: Thu, 27 Oct 2011 00:07:06 +0300 Subject: [PATCH 03/10] Update object_tools/templates/object_tools/inclusion_tags/object_tools.html --- .../templates/object_tools/inclusion_tags/object_tools.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/object_tools/templates/object_tools/inclusion_tags/object_tools.html b/object_tools/templates/object_tools/inclusion_tags/object_tools.html index fb98648..616ad45 100644 --- a/object_tools/templates/object_tools/inclusion_tags/object_tools.html +++ b/object_tools/templates/object_tools/inclusion_tags/object_tools.html @@ -1,3 +1,3 @@ {% for object_tool in object_tools %} -
  • {{ object_tool.label }}
  • +
  • {{ object_tool.label }}
  • {% endfor %} From d280ccd65a922f94fa4fca0f086539fb25ca1e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Ehlert?= Date: Wed, 26 Oct 2011 23:56:25 +0200 Subject: [PATCH 04/10] back to first version --- .../templates/object_tools/inclusion_tags/object_tools.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/object_tools/templates/object_tools/inclusion_tags/object_tools.html b/object_tools/templates/object_tools/inclusion_tags/object_tools.html index 616ad45..530573e 100644 --- a/object_tools/templates/object_tools/inclusion_tags/object_tools.html +++ b/object_tools/templates/object_tools/inclusion_tags/object_tools.html @@ -1,3 +1,3 @@ {% for object_tool in object_tools %} -
  • {{ object_tool.label }}
  • +
  • {{ object_tool.label }}
  • {% endfor %} From 933c58360524eb440331a90f8685f115996c8005 Mon Sep 17 00:00:00 2001 From: Gary Wilson Jr Date: Tue, 17 Jul 2012 11:26:57 -0500 Subject: [PATCH 05/10] Typo fix in README. --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index a9a7921..f1b5f09 100644 --- a/README.rst +++ b/README.rst @@ -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 * 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. From d3941ced56e6ccc51ba77eec46c56060d00b0b76 Mon Sep 17 00:00:00 2001 From: Shaun Sephton Date: Mon, 5 Nov 2012 08:23:25 +0200 Subject: [PATCH 06/10] load admin media using static url --- object_tools/templates/object_tools/tool_base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/object_tools/templates/object_tools/tool_base.html b/object_tools/templates/object_tools/tool_base.html index 0024d37..7cbce66 100644 --- a/object_tools/templates/object_tools/tool_base.html +++ b/object_tools/templates/object_tools/tool_base.html @@ -1,7 +1,7 @@ {% extends "admin/base_site.html" %} {% load i18n admin_modify adminmedia %} -{% block extrastyle %}{{ block.super }}{% endblock %} +{% block extrastyle %}{{ block.super }}{% endblock %} {% block extrahead %}{{ block.super }} From 6d120134aabca0ab12ef8e8e180cd09f09246f38 Mon Sep 17 00:00:00 2001 From: Shaun Sephton Date: Mon, 5 Nov 2012 08:24:20 +0200 Subject: [PATCH 07/10] pass request to changelist_view context, correctly serve js using static url --- object_tools/options.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/object_tools/options.py b/object_tools/options.py index 90e9d3d..54fd1c3 100644 --- a/object_tools/options.py +++ b/object_tools/options.py @@ -23,6 +23,15 @@ def __init__(self, model): from django.contrib.admin import site 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): """ @@ -52,11 +61,12 @@ 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'] - media = forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) \ - for url in js]) + media = forms.Media( + js=['%s%s' % (settings.STATIC_URL, url) for url in js], + ) if form: for name, field in form.fields.iteritems(): From 2bc6e2a5adfdc282c00c5f1dab230874863b56f1 Mon Sep 17 00:00:00 2001 From: Shaun Sephton Date: Mon, 5 Nov 2012 08:26:30 +0200 Subject: [PATCH 08/10] 0.0.6 --- CHANGELOG.rst | 4 ++++ setup.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 68c5b0d..f8cbf74 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,10 @@ Changelog ========= +0.0.6 +----- +#. Corrected 'str' object has no attribute 'has_perm' bug `#7 `_. + 0.0.5 ----- #. Remove usage of 'ADMIN_STATIC_PREFIX' in templates for move to Django 1.4. diff --git a/setup.py b/setup.py index 2fcb0d4..74e3a4f 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='django-object-tools', - version='0.0.5', + version='0.0.6', 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', From 25d4dfdcadeb017eb186c9453ae0084cbdfa699a Mon Sep 17 00:00:00 2001 From: Shaun Sephton Date: Mon, 5 Nov 2012 08:34:21 +0200 Subject: [PATCH 09/10] simplify, user is available in context --- object_tools/options.py | 9 --------- object_tools/templates/admin/change_list.html | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/object_tools/options.py b/object_tools/options.py index 54fd1c3..f0d3f63 100644 --- a/object_tools/options.py +++ b/object_tools/options.py @@ -23,15 +23,6 @@ def __init__(self, model): from django.contrib.admin import site 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): """ diff --git a/object_tools/templates/admin/change_list.html b/object_tools/templates/admin/change_list.html index 3e5575f..a1c07a6 100644 --- a/object_tools/templates/admin/change_list.html +++ b/object_tools/templates/admin/change_list.html @@ -59,7 +59,7 @@ {% if has_add_permission %}