1212from django .forms import CheckboxInput
1313from django .forms .formsets import (
1414 INITIAL_FORM_COUNT ,
15- ManagementForm ,
1615 MAX_NUM_FORM_COUNT ,
1716 TOTAL_FORM_COUNT ,
17+ ManagementForm ,
1818)
1919from django .forms .models import BaseModelFormSet
2020from django .http import HttpResponse , HttpResponseRedirect
2121from django .utils .encoding import force_str
2222from django .utils .html import format_html
2323from 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
2526
2627from concurrency import core , forms
2728from concurrency .api import get_revision_of_object
@@ -44,9 +45,7 @@ def action_checkbox(self, obj):
4445 if self .check_concurrent_action :
4546 attrs = {
4647 "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 ),
5049 }
5150 checkbox = CheckboxInput (attrs , lambda value : False )
5251 pk = force_str ("%s,%s" % (obj .pk , get_revision_of_object (obj )))
@@ -57,9 +56,7 @@ def action_checkbox(self, obj):
5756 else : # pragma: no cover
5857 return super ().action_checkbox (obj )
5958
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" />' )
6360 action_checkbox .allow_tags = True
6461
6562 def get_confirmation_template (self ):
@@ -114,9 +111,7 @@ def response_action(self, request, queryset): # noqa
114111 revision_field = self .model ._concurrencymeta .field
115112
116113 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 ()
120115
121116 # If select_across we have to avoid the use of concurrency
122117 if selected is not ALL :
@@ -166,9 +161,7 @@ def __init__(self, *args, **kwargs):
166161 def _get_concurrency_fields (self ):
167162 v = []
168163 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 } ">' )
172165 return mark_safe ("" .join (v ))
173166
174167 def render (self , template_name = None , context = None , renderer = None ):
@@ -183,26 +176,18 @@ def __str__(self):
183176
184177 __html__ = __str__
185178
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 )
192181 return mark_safe ("{0}{1}" .format (ret , self ._get_concurrency_fields ()))
193182
194183
195184class ConcurrentBaseModelFormSet (BaseModelFormSet ):
196185 def _management_form (self ):
197186 """Returns the ManagementForm instance for this FormSet."""
198187 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 )
202189 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" )
206191 else :
207192 form = ConcurrentManagementForm (
208193 auto_id = self .auto_id ,
@@ -212,10 +197,7 @@ def _management_form(self):
212197 INITIAL_FORM_COUNT : self .initial_form_count (),
213198 MAX_NUM_FORM_COUNT : self .max_num ,
214199 },
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 ],
219201 )
220202 return form
221203
@@ -308,9 +290,7 @@ def message_user(self, request, message, *args, **kwargs):
308290 return super ().message_user (request , message , * args , ** kwargs )
309291
310292
311- class ConcurrentModelAdmin (
312- ConcurrencyActionMixin , ConcurrencyListEditableMixin , admin .ModelAdmin
313- ):
293+ class ConcurrentModelAdmin (ConcurrencyActionMixin , ConcurrencyListEditableMixin , admin .ModelAdmin ):
314294 form = ConcurrentForm
315295 formfield_overrides = {forms .VersionField : {"widget" : VersionWidget }}
316296
@@ -322,9 +302,7 @@ def check(self, **kwargs):
322302 errors .append (
323303 Error (
324304 "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 ),
328306 obj = None ,
329307 id = "concurrency.A001" ,
330308 )
@@ -337,9 +315,7 @@ def check(self, **kwargs):
337315 errors .append (
338316 Error (
339317 "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 ),
343319 obj = None ,
344320 id = "concurrency.A002" ,
345321 )
0 commit comments