Skip to content

Commit f3f44a8

Browse files
authored
Merge pull request #28 from DjangoAdminHackers/prerelease-improvements
Pre-release improvements
2 parents f756c05 + 90cd571 commit f3f44a8

File tree

7 files changed

+39
-65
lines changed

7 files changed

+39
-65
lines changed

django_admin_row_actions/admin.py

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
11
from django import VERSION
22
from django import forms
3-
from django.conf.urls import url
3+
from django.urls import re_path
44
from django.utils.safestring import mark_safe
5-
from django.utils.translation import ugettext_lazy as _
6-
7-
from six import string_types
5+
from django.utils.translation import gettext_lazy as _
86

97
from .components import Dropdown
108
from .views import ModelToolsView
119

1210

13-
def patterns(prefix, *args):
14-
if VERSION < (1, 9):
15-
from django.conf.urls import patterns as django_patterns
16-
return django_patterns(prefix, *args)
17-
elif prefix != '':
18-
raise Exception("You need to update your URLConf to be a list of URL "
19-
"objects")
20-
else:
21-
return list(args)
22-
23-
24-
class AdminRowActionsMixin(object):
11+
class AdminRowActionsMixin:
2512

2613
"""ModelAdmin mixin to add row actions just like adding admin actions"""
2714

@@ -30,14 +17,14 @@ class AdminRowActionsMixin(object):
3017

3118
@property
3219
def media(self):
33-
return super(AdminRowActionsMixin, self).media + forms.Media(
20+
return super().media + forms.Media(
3421
css={'all': ["css/jquery.dropdown.min.css"]},
3522
js=["js/jquery.dropdown.min.js"],
3623
)
3724

3825
def get_list_display(self, request):
3926
self._request = request
40-
list_display = super(AdminRowActionsMixin, self).get_list_display(request)
27+
list_display = super().get_list_display(request)
4128
if '_row_actions' not in list_display:
4229
list_display += ('_row_actions',)
4330
return list_display
@@ -53,14 +40,14 @@ def to_dict(tool_name):
5340
items = []
5441

5542
row_actions = self.get_row_actions(obj)
56-
url_prefix = '{}/'.format(obj.pk if includePk else '')
43+
url_prefix = f'{obj.pk if includePk else ""}/'
5744

5845
for tool in row_actions:
59-
if isinstance(tool, string_types): # Just a str naming a callable
46+
if isinstance(tool, str): # Just a str naming a callable
6047
tool_dict = to_dict(tool)
6148
items.append({
6249
'label': tool_dict['label'],
63-
'url': '{}rowactions/{}/'.format(url_prefix, tool),
50+
'url': f'{url_prefix}rowactions/{tool}/',
6451
'method': tool_dict.get('POST', 'GET')
6552
})
6653

@@ -69,9 +56,9 @@ def to_dict(tool_name):
6956
if 'action' in tool: # If 'action' is specified then use our generic url in preference to 'url' value
7057
if isinstance(tool['action'], tuple):
7158
self._named_row_actions[tool['action'][0]] = tool['action'][1]
72-
tool['url'] = '{}rowactions/{}/'.format(url_prefix, tool['action'][0])
59+
tool['url'] = f'{url_prefix}rowactions/{tool["action"][0]}/'
7360
else:
74-
tool['url'] = '{}rowactions/{}/'.format(url_prefix, tool['action'])
61+
tool['url'] = f'{url_prefix}rowactions/{tool["action"]}/'
7562
items.append(tool)
7663

7764
return items
@@ -99,12 +86,11 @@ def get_tool_urls(self):
9986

10087
"""Gets the url patterns that route each tool to a special view"""
10188

102-
my_urls = patterns(
103-
'',
104-
url(r'^(?P<pk>[0-9a-f-]+)/rowactions/(?P<tool>\w+)/$',
89+
my_urls = [
90+
re_path(r'^(?P<pk>[0-9a-f-]+)/rowactions/(?P<tool>\w+)/$',
10591
self.admin_site.admin_view(ModelToolsView.as_view(model=self.model))
10692
)
107-
)
93+
]
10894
return my_urls
10995

11096
###################################
@@ -115,7 +101,7 @@ def get_urls(self):
115101

116102
"""Prepends `get_urls` with our own patterns"""
117103

118-
urls = super(AdminRowActionsMixin, self).get_urls()
104+
urls = super().get_urls()
119105
return self.get_tool_urls() + urls
120106

121107
##################
@@ -130,7 +116,7 @@ def get_change_actions(self, request, object_id, form_url):
130116
# If we're also using django_object_actions
131117
# then try to reuse row actions as object actions
132118

133-
change_actions = super(AdminRowActionsMixin, self).get_change_actions(request, object_id, form_url)
119+
change_actions = super().get_change_actions(request, object_id, form_url)
134120

135121
# Make this reuse opt-in
136122
if getattr(self, 'reuse_row_actions_as_object_actions', False):
@@ -140,10 +126,10 @@ def get_change_actions(self, request, object_id, form_url):
140126

141127
for row_action in row_actions:
142128
# Object actions only supports strings as action indentifiers
143-
if isinstance(row_action, string_types):
129+
if isinstance(row_action, str):
144130
change_actions.append(row_action)
145131
elif isinstance(row_action, dict):
146-
if isinstance(row_action['action'], string_types):
132+
if isinstance(row_action['action'], str):
147133
change_actions.append(row_action['action'])
148134
elif isinstance(row_action['action'], tuple):
149135
change_actions.append(str(row_action['action'][1]))

django_admin_row_actions/components.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from django.template.loader import render_to_string
33

44

5-
class BaseComponent(object):
5+
class BaseComponent:
66

77
template = None
88
instances = []
@@ -15,7 +15,7 @@ def __init__(self, **kwargs):
1515

1616
@classmethod
1717
def get_unique_id(cls):
18-
return "{}-{}".format(cls.__name__.lower(), len(cls.instances))
18+
return f'{cls.__name__.lower()}-{len(cls.instances)}'
1919

2020
def render(self):
2121
return render_to_string(
@@ -24,13 +24,9 @@ def render(self):
2424
request=self.request
2525
)
2626

27-
def __unicode__(self):
27+
def __str__(self):
2828
return self.render()
2929

3030

3131
class Dropdown(BaseComponent):
32-
3332
template = 'django_admin_row_actions/dropdown.html'
34-
35-
def __init__(self, **kwargs):
36-
super(Dropdown, self).__init__(**kwargs)

django_admin_row_actions/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, instance=None, *args, **kwargs):
2020
# we may be able to throw away all this logic
2121
model = instance._meta.concrete_model
2222
self._doa_instance = instance
23-
super(QuerySetIsh, self).__init__(model, *args, **kwargs)
23+
super().__init__(model, *args, **kwargs)
2424
self._result_cache = [instance]
2525

2626
def _clone(self, *args, **kwargs):

django_admin_row_actions/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get(self, request, **kwargs):
4141
if isinstance(ret, HttpResponse):
4242
response = ret
4343
else:
44-
back = request.META['HTTP_REFERER']
44+
back = request.headers['referer']
4545
response = HttpResponseRedirect(back)
4646

4747
return response

pyproject.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[build-system]
2+
requires = ["poetry-core"]
3+
build-backend = "poetry.core.masonry.api"
4+
5+
[tool.poetry]
6+
name = "django-admin-row-actions"
7+
description = "Add action buttons to individual rows in the Django Admin"
8+
readme = "README.md"
9+
version = "0.10.0"
10+
authors = [
11+
"Andy Baker <[email protected]>",
12+
]
13+
packages = [
14+
{ include = "django_admin_row_actions" },
15+
]
16+
homepage = "https://pypi.org/project/django-admin-row-actions/"
17+
repository = "https://github.com/DjangoAdminHackers/django-admin-row-actions"

setup.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)