12
12
from django .forms import CheckboxInput
13
13
from django .forms .formsets import (
14
14
INITIAL_FORM_COUNT ,
15
- ManagementForm ,
16
15
MAX_NUM_FORM_COUNT ,
17
16
TOTAL_FORM_COUNT ,
17
+ ManagementForm ,
18
18
)
19
19
from django .forms .models import BaseModelFormSet
20
20
from django .http import HttpResponse , HttpResponseRedirect
21
21
from django .utils .encoding import force_str
22
22
from django .utils .html import format_html
23
23
from django .utils .safestring import mark_safe
24
- from django .utils .translation import gettext_lazy as _ , ngettext
24
+ from django .utils .translation import gettext_lazy as _
25
+ from django .utils .translation import ngettext
25
26
26
27
from concurrency import core , forms
27
28
from concurrency .api import get_revision_of_object
@@ -44,9 +45,7 @@ def action_checkbox(self, obj):
44
45
if self .check_concurrent_action :
45
46
attrs = {
46
47
"class" : "action-select" ,
47
- "aria-label" : format_html (
48
- _ ("Select this object for an action - {}" ), obj
49
- ),
48
+ "aria-label" : format_html (_ ("Select this object for an action - {}" ), obj ),
50
49
}
51
50
checkbox = CheckboxInput (attrs , lambda value : False )
52
51
pk = force_str ("%s,%s" % (obj .pk , get_revision_of_object (obj )))
@@ -57,9 +56,7 @@ def action_checkbox(self, obj):
57
56
else : # pragma: no cover
58
57
return super ().action_checkbox (obj )
59
58
60
- action_checkbox .short_description = mark_safe (
61
- '<input type="checkbox" id="action-toggle" />'
62
- )
59
+ action_checkbox .short_description = mark_safe ('<input type="checkbox" id="action-toggle" />' )
63
60
action_checkbox .allow_tags = True
64
61
65
62
def get_confirmation_template (self ):
@@ -114,9 +111,7 @@ def response_action(self, request, queryset): # noqa
114
111
revision_field = self .model ._concurrencymeta .field
115
112
116
113
if self .check_concurrent_action :
117
- self .delete_selected_confirmation_template = (
118
- self .get_confirmation_template ()
119
- )
114
+ self .delete_selected_confirmation_template = self .get_confirmation_template ()
120
115
121
116
# If select_across we have to avoid the use of concurrency
122
117
if selected is not ALL :
@@ -166,9 +161,7 @@ def __init__(self, *args, **kwargs):
166
161
def _get_concurrency_fields (self ):
167
162
v = []
168
163
for pk , version in self ._versions :
169
- v .append (
170
- f'<input type="hidden" name="{ concurrency_param_name } _{ pk } " value="{ version } ">'
171
- )
164
+ v .append (f'<input type="hidden" name="{ concurrency_param_name } _{ pk } " value="{ version } ">' )
172
165
return mark_safe ("" .join (v ))
173
166
174
167
def render (self , template_name = None , context = None , renderer = None ):
@@ -183,26 +176,18 @@ def __str__(self):
183
176
184
177
__html__ = __str__
185
178
186
- def _html_output (
187
- self , normal_row , error_row , row_ender , help_text_html , errors_on_separate_row
188
- ):
189
- ret = super ()._html_output (
190
- normal_row , error_row , row_ender , help_text_html , errors_on_separate_row
191
- )
179
+ def _html_output (self , normal_row , error_row , row_ender , help_text_html , errors_on_separate_row ):
180
+ ret = super ()._html_output (normal_row , error_row , row_ender , help_text_html , errors_on_separate_row )
192
181
return mark_safe ("{0}{1}" .format (ret , self ._get_concurrency_fields ()))
193
182
194
183
195
184
class ConcurrentBaseModelFormSet (BaseModelFormSet ):
196
185
def _management_form (self ):
197
186
"""Returns the ManagementForm instance for this FormSet."""
198
187
if self .is_bound :
199
- form = ConcurrentManagementForm (
200
- self .data , auto_id = self .auto_id , prefix = self .prefix
201
- )
188
+ form = ConcurrentManagementForm (self .data , auto_id = self .auto_id , prefix = self .prefix )
202
189
if not form .is_valid ():
203
- raise ValidationError (
204
- "ManagementForm data is missing or has been tampered with"
205
- )
190
+ raise ValidationError ("ManagementForm data is missing or has been tampered with" )
206
191
else :
207
192
form = ConcurrentManagementForm (
208
193
auto_id = self .auto_id ,
@@ -212,10 +197,7 @@ def _management_form(self):
212
197
INITIAL_FORM_COUNT : self .initial_form_count (),
213
198
MAX_NUM_FORM_COUNT : self .max_num ,
214
199
},
215
- versions = [
216
- (form .instance .pk , get_revision_of_object (form .instance ))
217
- for form in self .initial_forms
218
- ],
200
+ versions = [(form .instance .pk , get_revision_of_object (form .instance )) for form in self .initial_forms ],
219
201
)
220
202
return form
221
203
@@ -308,9 +290,7 @@ def message_user(self, request, message, *args, **kwargs):
308
290
return super ().message_user (request , message , * args , ** kwargs )
309
291
310
292
311
- class ConcurrentModelAdmin (
312
- ConcurrencyActionMixin , ConcurrencyListEditableMixin , admin .ModelAdmin
313
- ):
293
+ class ConcurrentModelAdmin (ConcurrencyActionMixin , ConcurrencyListEditableMixin , admin .ModelAdmin ):
314
294
form = ConcurrentForm
315
295
formfield_overrides = {forms .VersionField : {"widget" : VersionWidget }}
316
296
@@ -322,9 +302,7 @@ def check(self, **kwargs):
322
302
errors .append (
323
303
Error (
324
304
"Missed version field in {} fields definition" .format (self ),
325
- hint = "Please add '{}' to the 'fields' attribute" .format (
326
- version_field .name
327
- ),
305
+ hint = "Please add '{}' to the 'fields' attribute" .format (version_field .name ),
328
306
obj = None ,
329
307
id = "concurrency.A001" ,
330
308
)
@@ -337,9 +315,7 @@ def check(self, **kwargs):
337
315
errors .append (
338
316
Error (
339
317
"Missed version field in {} fieldsets definition" .format (self ),
340
- hint = "Please add '{}' to the 'fieldsets' attribute" .format (
341
- version_field .name
342
- ),
318
+ hint = "Please add '{}' to the 'fieldsets' attribute" .format (version_field .name ),
343
319
obj = None ,
344
320
id = "concurrency.A002" ,
345
321
)
0 commit comments