11from django import VERSION
22from django import forms
3- from django .conf . urls import url
3+ from django .urls import re_path
44from 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
97from .components import Dropdown
108from .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 ]))
0 commit comments