From 8015493234dc2f9832e6f9f75709d3ff39d409a4 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 17 Jul 2019 12:21:27 +0100 Subject: [PATCH 1/8] Remove example tests Remove the example tests directory created by Django's startproject, to avoid the illusion that the project is tested. --- django_admin_row_actions/tests/__init__.py | 1 - django_admin_row_actions/tests/tests.py | 16 ---------------- 2 files changed, 17 deletions(-) delete mode 100644 django_admin_row_actions/tests/__init__.py delete mode 100644 django_admin_row_actions/tests/tests.py diff --git a/django_admin_row_actions/tests/__init__.py b/django_admin_row_actions/tests/__init__.py deleted file mode 100644 index 33a7eba..0000000 --- a/django_admin_row_actions/tests/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__author__ = 'andybaker' diff --git a/django_admin_row_actions/tests/tests.py b/django_admin_row_actions/tests/tests.py deleted file mode 100644 index 501deb7..0000000 --- a/django_admin_row_actions/tests/tests.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -This file demonstrates writing tests using the unittest module. These will pass -when you run "manage.py test". - -Replace this with more appropriate tests for your application. -""" - -from django.test import TestCase - - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.assertEqual(1 + 1, 2) From 467c190c8f9450b443bf06bfdbe8da23bb411c90 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 17 Jul 2019 12:20:50 +0100 Subject: [PATCH 2/8] Improve media method Avoid mutating the contents of the lists from the instance returned from `super()`, and instead use addition, [the recommended method of combining Media classes](https://docs.djangoproject.com/en/2.2/topics/forms/media/#combining-media-objects). --- django_admin_row_actions/admin.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/django_admin_row_actions/admin.py b/django_admin_row_actions/admin.py index 46b7a9a..fef5636 100644 --- a/django_admin_row_actions/admin.py +++ b/django_admin_row_actions/admin.py @@ -30,19 +30,11 @@ class AdminRowActionsMixin(object): @property def media(self): - css = super(AdminRowActionsMixin, self).media._css - css['all'] = css.get('all', []) - css['all'].extend(["css/jquery.dropdown.min.css"]) - - js = super(AdminRowActionsMixin, self).media._js - js.extend(["js/jquery.dropdown.min.js",]) - - media = forms.Media( - css=css, js=js + return super(AdminRowActionsMixin, self).media + forms.Media( + css={'all': ["css/jquery.dropdown.min.css"]}, + js=["js/jquery.dropdown.min.js"], ) - return media - def get_list_display(self, request): self._request = request list_display = super(AdminRowActionsMixin, self).get_list_display(request) From cabb1c90b2215f14b5666a9f2bd3487a3962fe47 Mon Sep 17 00:00:00 2001 From: blag Date: Fri, 22 Sep 2023 09:50:59 -0700 Subject: [PATCH 3/8] Update to Python 3 syntax --- django_admin_row_actions/admin.py | 24 ++++++++++++------------ django_admin_row_actions/components.py | 10 +++------- django_admin_row_actions/utils.py | 2 +- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/django_admin_row_actions/admin.py b/django_admin_row_actions/admin.py index 8560252..e78bf3b 100644 --- a/django_admin_row_actions/admin.py +++ b/django_admin_row_actions/admin.py @@ -10,7 +10,7 @@ from .views import ModelToolsView -class AdminRowActionsMixin(object): +class AdminRowActionsMixin: """ModelAdmin mixin to add row actions just like adding admin actions""" @@ -19,14 +19,14 @@ class AdminRowActionsMixin(object): @property def media(self): - return super(AdminRowActionsMixin, self).media + forms.Media( + return super().media + forms.Media( css={'all': ["css/jquery.dropdown.min.css"]}, js=["js/jquery.dropdown.min.js"], ) def get_list_display(self, request): self._request = request - list_display = super(AdminRowActionsMixin, self).get_list_display(request) + list_display = super().get_list_display(request) if '_row_actions' not in list_display: list_display += ('_row_actions',) return list_display @@ -42,14 +42,14 @@ def to_dict(tool_name): items = [] row_actions = self.get_row_actions(obj) - url_prefix = '{}/'.format(obj.pk if includePk else '') + url_prefix = "{obj.pk if includePk else ''}/" for tool in row_actions: - if isinstance(tool, string_types): # Just a str naming a callable + if isinstance(tool, str): # Just a str naming a callable tool_dict = to_dict(tool) items.append({ 'label': tool_dict['label'], - 'url': '{}rowactions/{}/'.format(url_prefix, tool), + 'url': f"{url_prefix}rowactions/{tool}/", 'method': tool_dict.get('POST', 'GET') }) @@ -58,9 +58,9 @@ def to_dict(tool_name): if 'action' in tool: # If 'action' is specified then use our generic url in preference to 'url' value if isinstance(tool['action'], tuple): self._named_row_actions[tool['action'][0]] = tool['action'][1] - tool['url'] = '{}rowactions/{}/'.format(url_prefix, tool['action'][0]) + tool['url'] = f"{url_prefix}rowactions/{tool['action'][0]}/" else: - tool['url'] = '{}rowactions/{}/'.format(url_prefix, tool['action']) + tool['url'] = f"{url_prefix}rowactions/{tool['action']}/" items.append(tool) return items @@ -103,7 +103,7 @@ def get_urls(self): """Prepends `get_urls` with our own patterns""" - urls = super(AdminRowActionsMixin, self).get_urls() + urls = super().get_urls() return self.get_tool_urls() + urls ################## @@ -118,7 +118,7 @@ def get_change_actions(self, request, object_id, form_url): # If we're also using django_object_actions # then try to reuse row actions as object actions - change_actions = super(AdminRowActionsMixin, self).get_change_actions(request, object_id, form_url) + change_actions = super().get_change_actions(request, object_id, form_url) # Make this reuse opt-in if getattr(self, 'reuse_row_actions_as_object_actions', False): @@ -128,10 +128,10 @@ def get_change_actions(self, request, object_id, form_url): for row_action in row_actions: # Object actions only supports strings as action indentifiers - if isinstance(row_action, string_types): + if isinstance(row_action, str): change_actions.append(row_action) elif isinstance(row_action, dict): - if isinstance(row_action['action'], string_types): + if isinstance(row_action['action'], str): change_actions.append(row_action['action']) elif isinstance(row_action['action'], tuple): change_actions.append(str(row_action['action'][1])) diff --git a/django_admin_row_actions/components.py b/django_admin_row_actions/components.py index 3beb556..4496aed 100644 --- a/django_admin_row_actions/components.py +++ b/django_admin_row_actions/components.py @@ -2,7 +2,7 @@ from django.template.loader import render_to_string -class BaseComponent(object): +class BaseComponent: template = None instances = [] @@ -15,7 +15,7 @@ def __init__(self, **kwargs): @classmethod def get_unique_id(cls): - return "{}-{}".format(cls.__name__.lower(), len(cls.instances)) + return f"{cls.__name__.lower()}-{len(cls.instances)}" def render(self): return render_to_string( @@ -24,13 +24,9 @@ def render(self): request=self.request ) - def __unicode__(self): + def __str__(self): return self.render() class Dropdown(BaseComponent): - template = 'django_admin_row_actions/dropdown.html' - - def __init__(self, **kwargs): - super(Dropdown, self).__init__(**kwargs) diff --git a/django_admin_row_actions/utils.py b/django_admin_row_actions/utils.py index 12c6c63..552b336 100644 --- a/django_admin_row_actions/utils.py +++ b/django_admin_row_actions/utils.py @@ -20,7 +20,7 @@ def __init__(self, instance=None, *args, **kwargs): # we may be able to throw away all this logic model = instance._meta.concrete_model self._doa_instance = instance - super(QuerySetIsh, self).__init__(model, *args, **kwargs) + super().__init__(model, *args, **kwargs) self._result_cache = [instance] def _clone(self, *args, **kwargs): From b58e39b175afe9d09dac3ab802af1f13efc1ff66 Mon Sep 17 00:00:00 2001 From: blag Date: Fri, 22 Sep 2023 09:51:48 -0700 Subject: [PATCH 4/8] Upgrade to Django 4.2 --- django_admin_row_actions/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_admin_row_actions/views.py b/django_admin_row_actions/views.py index 2e307b4..c0628a8 100644 --- a/django_admin_row_actions/views.py +++ b/django_admin_row_actions/views.py @@ -41,7 +41,7 @@ def get(self, request, **kwargs): if isinstance(ret, HttpResponse): response = ret else: - back = request.META['HTTP_REFERER'] + back = request.headers['referer'] response = HttpResponseRedirect(back) return response From 3e964f8de4c77994e9d39116ca5c586705522b69 Mon Sep 17 00:00:00 2001 From: blag Date: Fri, 22 Sep 2023 09:52:33 -0700 Subject: [PATCH 5/8] Update version to 0.10.0 --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 0bce719..50c5d3d 100644 --- a/setup.py +++ b/setup.py @@ -3,8 +3,8 @@ setup( name='django-admin-row-actions', - version='0.0.6', - description='django admin row actions', + version='0.10.0', + description='Add action buttons to individual rows in the Django Admin', author='Andy Baker', author_email='andy@andybak.net', url='https://github.com/DjangoAdminHackers/django-admin-row-actions', From 36f57b80ce162a46a5791f0217919095f88fa273 Mon Sep 17 00:00:00 2001 From: blag Date: Fri, 22 Sep 2023 16:00:50 -0700 Subject: [PATCH 6/8] Don't need six anymore --- django_admin_row_actions/admin.py | 2 -- setup.py | 3 --- 2 files changed, 5 deletions(-) diff --git a/django_admin_row_actions/admin.py b/django_admin_row_actions/admin.py index e78bf3b..5106b8d 100644 --- a/django_admin_row_actions/admin.py +++ b/django_admin_row_actions/admin.py @@ -4,8 +4,6 @@ from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ -from six import string_types - from .components import Dropdown from .views import ModelToolsView diff --git a/setup.py b/setup.py index 50c5d3d..e6f85a5 100644 --- a/setup.py +++ b/setup.py @@ -9,9 +9,6 @@ author_email='andy@andybak.net', url='https://github.com/DjangoAdminHackers/django-admin-row-actions', packages=find_packages(), - install_requires=[ - 'six', - ], package_data={ 'django_admin_row_actions': [ 'static/css/*.css', From 7a7d464b7ed486811f602fc6335735d808b9279b Mon Sep 17 00:00:00 2001 From: blag Date: Sat, 23 Sep 2023 00:28:09 -0700 Subject: [PATCH 7/8] Convert to pyproject.toml --- pyproject.toml | 17 +++++++++++++++++ setup.cfg | 2 -- setup.py | 20 -------------------- 3 files changed, 17 insertions(+), 22 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4f12a8c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + +[tool.poetry] +name = "django-admin-row-actions" +description = "Add action buttons to individual rows in the Django Admin" +readme = "README.md" +version = "0.10.0" +authors = [ + "Andy Baker ", +] +packages = [ + { include = "django_admin_row_actions" }, +] +homepage = "https://pypi.org/project/django-admin-row-actions/" +repository = "https://github.com/DjangoAdminHackers/django-admin-row-actions" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index b88034e..0000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[metadata] -description-file = README.md diff --git a/setup.py b/setup.py deleted file mode 100644 index e6f85a5..0000000 --- a/setup.py +++ /dev/null @@ -1,20 +0,0 @@ -from setuptools import find_packages -from setuptools import setup - -setup( - name='django-admin-row-actions', - version='0.10.0', - description='Add action buttons to individual rows in the Django Admin', - author='Andy Baker', - author_email='andy@andybak.net', - url='https://github.com/DjangoAdminHackers/django-admin-row-actions', - packages=find_packages(), - package_data={ - 'django_admin_row_actions': [ - 'static/css/*.css', - 'static/js/*.js', - 'templates/django_admin_row_actions/*.html', - ] - }, - include_package_data=True, -) From 90cd571e14e08f567e7f3382262bf6eae39f457d Mon Sep 17 00:00:00 2001 From: blag Date: Thu, 5 Oct 2023 15:27:07 -0700 Subject: [PATCH 8/8] Make quote usage more consistent --- django_admin_row_actions/admin.py | 8 ++++---- django_admin_row_actions/components.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/django_admin_row_actions/admin.py b/django_admin_row_actions/admin.py index 5106b8d..069032e 100644 --- a/django_admin_row_actions/admin.py +++ b/django_admin_row_actions/admin.py @@ -40,14 +40,14 @@ def to_dict(tool_name): items = [] row_actions = self.get_row_actions(obj) - url_prefix = "{obj.pk if includePk else ''}/" + url_prefix = f'{obj.pk if includePk else ""}/' for tool in row_actions: if isinstance(tool, str): # Just a str naming a callable tool_dict = to_dict(tool) items.append({ 'label': tool_dict['label'], - 'url': f"{url_prefix}rowactions/{tool}/", + 'url': f'{url_prefix}rowactions/{tool}/', 'method': tool_dict.get('POST', 'GET') }) @@ -56,9 +56,9 @@ def to_dict(tool_name): if 'action' in tool: # If 'action' is specified then use our generic url in preference to 'url' value if isinstance(tool['action'], tuple): self._named_row_actions[tool['action'][0]] = tool['action'][1] - tool['url'] = f"{url_prefix}rowactions/{tool['action'][0]}/" + tool['url'] = f'{url_prefix}rowactions/{tool["action"][0]}/' else: - tool['url'] = f"{url_prefix}rowactions/{tool['action']}/" + tool['url'] = f'{url_prefix}rowactions/{tool["action"]}/' items.append(tool) return items diff --git a/django_admin_row_actions/components.py b/django_admin_row_actions/components.py index 4496aed..2e11b7c 100644 --- a/django_admin_row_actions/components.py +++ b/django_admin_row_actions/components.py @@ -15,7 +15,7 @@ def __init__(self, **kwargs): @classmethod def get_unique_id(cls): - return f"{cls.__name__.lower()}-{len(cls.instances)}" + return f'{cls.__name__.lower()}-{len(cls.instances)}' def render(self): return render_to_string(