11import copy
22import decimal
33
4- from cms .constants import SLUG_REGEXP
5- from cms .plugin_base import CMSPluginBase
6- from cms .utils .conf import get_cms_setting
74from django .apps import apps
85from django .contrib .admin .helpers import AdminForm
96from django .db .models import ObjectDoesNotExist
1512from django .utils .safestring import mark_safe
1613from django .utils .translation import gettext_lazy as _
1714
15+ from cms .constants import SLUG_REGEXP
16+ from cms .plugin_base import CMSPluginBase
17+ from cms .utils .conf import get_cms_setting
18+
1819from djangocms_frontend import settings
1920from djangocms_frontend .settings import FRAMEWORK_PLUGIN_INFO
2021
@@ -33,6 +34,7 @@ def get_related_object(scope, field_name):
3334
3435class get_related :
3536 """Descriptor lazily getting related objects from the config dict."""
37+
3638 def __init__ (self , key ):
3739 self .key = key
3840
@@ -74,12 +76,12 @@ def insert_fields(fieldsets, new_fields, block=None, position=-1, blockname=None
7476 modify [1 ]["fields" ] = (
7577 list (fields [: position + 1 ] if position != - 1 else fields )
7678 + list (new_fields )
77- + list (fields [position + 1 :] if position != - 1 else [])
79+ + list (fields [position + 1 :] if position != - 1 else [])
7880 )
7981 fs = (
8082 list (fieldsets [:block ] if block != - 1 else fieldsets )
8183 + [modify ]
82- + list (fieldsets [block + 1 :] if block != - 1 else [])
84+ + list (fieldsets [block + 1 :] if block != - 1 else [])
8385 )
8486 return fs
8587
@@ -165,6 +167,7 @@ class FrontendEditableAdminMixin:
165167 in the frontend by double-clicking on fields rendered with the ``render_model`` template
166168 tag.
167169 """
170+
168171 frontend_editable_fields = []
169172
170173 def get_urls (self ): # pragma: no cover
@@ -177,7 +180,7 @@ def pat(regex, fn):
177180 return re_path (regex , self .admin_site .admin_view (fn ), name = f"{ info } _{ fn .__name__ } " )
178181
179182 url_patterns = [
180- pat (r' edit-field/(%s)/([a-z\-]+)/$' % SLUG_REGEXP , self .edit_field ),
183+ pat (r" edit-field/(%s)/([a-z\-]+)/$" % SLUG_REGEXP , self .edit_field ),
181184 ]
182185 return url_patterns + super ().get_urls ()
183186
@@ -203,58 +206,53 @@ def edit_field(self, request, object_id, language):
203206 raw_fields = request .GET .get ("edit_fields" )
204207 fields = [field for field in raw_fields .split ("," ) if field in self .frontend_editable_fields ]
205208 if not fields :
206- context = {
207- 'opts' : opts ,
208- 'message' : _ ("Field %s not found" ) % raw_fields
209- }
210- return render (request , 'admin/cms/page/plugin/error_form.html' , context )
209+ context = {"opts" : opts , "message" : _ ("Field %s not found" ) % raw_fields }
210+ return render (request , "admin/cms/page/plugin/error_form.html" , context )
211211 if not request .user .has_perm (f"{ self .model ._meta .app_label } .change_{ self .model ._meta .model_name } " ):
212- context = {
213- 'opts' : opts ,
214- 'message' : _ ("You do not have permission to edit this item" )
215- }
216- return render (request , 'admin/cms/page/plugin/error_form.html' , context )
212+ context = {"opts" : opts , "message" : _ ("You do not have permission to edit this item" )}
213+ return render (request , "admin/cms/page/plugin/error_form.html" , context )
217214 # Dynamically creates the form class with only `field_name` field
218215 # enabled
219216 form_class = self .get_form (request , obj , fields = fields )
220- if not cancel_clicked and request .method == ' POST' :
217+ if not cancel_clicked and request .method == " POST" :
221218 form = form_class (instance = obj , data = request .POST )
222219 if form .is_valid ():
223220 new_object = form .save (commit = False )
224221 self .save_model (request , new_object , form , change = True )
225222 saved_successfully = True
226223 else :
227224 form = form_class (instance = obj )
228- admin_form = AdminForm (form , fieldsets = [(None , {'fields' : fields })], prepopulated_fields = {},
229- model_admin = self )
225+ admin_form = AdminForm (form , fieldsets = [(None , {"fields" : fields })], prepopulated_fields = {}, model_admin = self )
230226 media = self .media + admin_form .media
231227 context = {
232- ' CMS_MEDIA_URL' : get_cms_setting (' MEDIA_URL' ),
233- ' title' : opts .verbose_name ,
234- ' plugin' : None ,
235- ' plugin_id' : None ,
236- ' adminform' : admin_form ,
237- ' add' : False ,
238- ' is_popup' : True ,
239- ' media' : media ,
240- ' opts' : opts ,
241- ' change' : True ,
242- ' save_as' : False ,
243- ' has_add_permission' : False ,
244- ' window_close_timeout' : 10 ,
228+ " CMS_MEDIA_URL" : get_cms_setting (" MEDIA_URL" ),
229+ " title" : opts .verbose_name ,
230+ " plugin" : None ,
231+ " plugin_id" : None ,
232+ " adminform" : admin_form ,
233+ " add" : False ,
234+ " is_popup" : True ,
235+ " media" : media ,
236+ " opts" : opts ,
237+ " change" : True ,
238+ " save_as" : False ,
239+ " has_add_permission" : False ,
240+ " window_close_timeout" : 10 ,
245241 }
246242 if cancel_clicked :
247243 # cancel button was clicked
248- context .update ({
249- 'cancel' : True ,
250- })
251- return render (request , 'admin/cms/page/plugin/confirm_form.html' , context )
252- if not cancel_clicked and request .method == 'POST' and saved_successfully :
244+ context .update (
245+ {
246+ "cancel" : True ,
247+ }
248+ )
249+ return render (request , "admin/cms/page/plugin/confirm_form.html" , context )
250+ if not cancel_clicked and request .method == "POST" and saved_successfully :
253251 if isinstance (self , CMSPluginBase ):
254- if hasattr (obj .placeholder , ' mark_as_dirty' ):
252+ if hasattr (obj .placeholder , " mark_as_dirty" ):
255253 # Only relevant for v3: mark the placeholder as dirty so user can publish changes
256254 obj .placeholder .mark_as_dirty (obj .language , clear_cache = False )
257255 # Update the structure board by populating the data bridge
258256 return self .render_close_frame (request , obj )
259- return render (request , ' admin/cms/page/plugin/confirm_form.html' , context )
260- return render (request , ' admin/cms/page/plugin/change_form.html' , context )
257+ return render (request , " admin/cms/page/plugin/confirm_form.html" , context )
258+ return render (request , " admin/cms/page/plugin/change_form.html" , context )
0 commit comments