diff --git a/django_admin_row_actions/admin.py b/django_admin_row_actions/admin.py index cffbe6b..069032e 100644 --- a/django_admin_row_actions/admin.py +++ b/django_admin_row_actions/admin.py @@ -4,13 +4,11 @@ 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 -class AdminRowActionsMixin(object): +class AdminRowActionsMixin: """ModelAdmin mixin to add row actions just like adding admin actions""" @@ -19,22 +17,14 @@ 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().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) + list_display = super().get_list_display(request) if '_row_actions' not in list_display: list_display += ('_row_actions',) return list_display @@ -50,14 +40,14 @@ def to_dict(tool_name): items = [] row_actions = self.get_row_actions(obj) - url_prefix = '{}/'.format(obj.pk if includePk else '') + url_prefix = f'{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') }) @@ -66,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'] = '{}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 @@ -111,7 +101,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 ################## @@ -126,7 +116,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): @@ -136,10 +126,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..2e11b7c 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/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) 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): 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 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 0bce719..0000000 --- a/setup.py +++ /dev/null @@ -1,23 +0,0 @@ -from setuptools import find_packages -from setuptools import setup - -setup( - name='django-admin-row-actions', - version='0.0.6', - description='django admin row actions', - author='Andy Baker', - 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', - 'static/js/*.js', - 'templates/django_admin_row_actions/*.html', - ] - }, - include_package_data=True, -)