|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 | 3 | import os
|
| 4 | +import re |
4 | 5 | import warnings
|
5 | 6 | from datetime import date
|
6 |
| -from functools import cache |
| 7 | +from functools import cache, cached_property |
7 | 8 |
|
8 | 9 | from django.core.exceptions import ObjectDoesNotExist
|
9 | 10 | from django.db import connection, connections, models, router
|
@@ -202,21 +203,23 @@ def __repr__(self):
|
202 | 203 | return display
|
203 | 204 |
|
204 | 205 | def get_plugin_name(self):
|
205 |
| - from cms.plugin_pool import plugin_pool |
206 |
| - |
207 |
| - return plugin_pool.get_plugin(self.plugin_type).name |
| 206 | + return self.plugin_class.name |
208 | 207 |
|
209 | 208 | def get_short_description(self):
|
210 | 209 | instance = self.get_plugin_instance()[0]
|
211 | 210 | if instance is not None:
|
212 | 211 | return force_str(instance)
|
213 | 212 | return _("<Empty>")
|
214 | 213 |
|
215 |
| - def get_plugin_class(self): |
| 214 | + @cached_property |
| 215 | + def plugin_class(self): |
216 | 216 | from cms.plugin_pool import plugin_pool
|
217 | 217 |
|
218 | 218 | return plugin_pool.get_plugin(self.plugin_type)
|
219 | 219 |
|
| 220 | + def get_plugin_class(self): |
| 221 | + return self.plugin_class |
| 222 | + |
220 | 223 | def get_plugin_class_instance(self, admin=None):
|
221 | 224 | plugin_class = self.get_plugin_class()
|
222 | 225 | # needed so we have the same signature as the original ModelAdmin
|
@@ -264,7 +267,8 @@ def get_bound_plugin(self):
|
264 | 267 | return self._inst
|
265 | 268 |
|
266 | 269 | def get_plugin_info(self, children=None, parents=None):
|
267 |
| - plugin_class = self.get_plugin_class() |
| 270 | + plugin_class = self.plugin_class |
| 271 | + |
268 | 272 | return {
|
269 | 273 | 'type': 'plugin',
|
270 | 274 | 'position': self.position,
|
@@ -445,26 +449,32 @@ def get_action_urls(self, js_compat=True):
|
445 | 449 | This method replaces the set of legacy methods `get_add_url`, ``get_edit_url`, `get_move_url`,
|
446 | 450 | `get_delete_url`, `get_copy_url`.
|
447 | 451 | """
|
| 452 | + if not hasattr(CMSPlugin, '_edit_url'): |
| 453 | + CMSPlugin._edit_url = admin_reverse('cms_placeholder_edit_plugin', args=(0,)) |
| 454 | + CMSPlugin._add_url = admin_reverse('cms_placeholder_add_plugin') |
| 455 | + CMSPlugin._delete_url = admin_reverse('cms_placeholder_delete_plugin', args=(0,)) |
| 456 | + CMSPlugin._move_url = admin_reverse('cms_placeholder_move_plugin') |
| 457 | + CMSPlugin._copy_url = admin_reverse('cms_placeholder_copy_plugins') |
| 458 | + |
448 | 459 | if js_compat:
|
449 | 460 | # TODO: Remove this condition
|
450 | 461 | # once the javascript files have been refactored
|
451 | 462 | # to use the new naming schema (ending in _url).
|
452 |
| - data = { |
453 |
| - 'edit_plugin': admin_reverse('cms_placeholder_edit_plugin', args=(self.pk,)), |
454 |
| - 'add_plugin': admin_reverse('cms_placeholder_add_plugin'), |
455 |
| - 'delete_plugin': admin_reverse('cms_placeholder_delete_plugin', args=(self.pk,)), |
456 |
| - 'move_plugin': admin_reverse('cms_placeholder_move_plugin'), |
457 |
| - 'copy_plugin': admin_reverse('cms_placeholder_copy_plugins'), |
| 463 | + return { |
| 464 | + 'edit_plugin': re.sub(r"/0/", f"/{self.pk}/", CMSPlugin._edit_url), |
| 465 | + 'add_plugin': CMSPlugin._add_url, |
| 466 | + 'delete_plugin': re.sub(r"/0/", f"/{self.pk}/", CMSPlugin._delete_url), |
| 467 | + 'move_plugin': CMSPlugin._move_url, |
| 468 | + 'copy_plugin': CMSPlugin._copy_url, |
458 | 469 | }
|
459 | 470 | else:
|
460 |
| - data = { |
461 |
| - 'edit_url': admin_reverse('cms_placeholder_edit_plugin', args=(self.pk,)), |
462 |
| - 'add_url': admin_reverse('cms_placeholder_add_plugin'), |
463 |
| - 'delete_url': admin_reverse('cms_placeholder_delete_plugin', args=(self.pk,)), |
464 |
| - 'move_url': admin_reverse('cms_placeholder_move_plugin'), |
465 |
| - 'copy_url': admin_reverse('cms_placeholder_copy_plugins'), |
| 471 | + return { |
| 472 | + 'edit_url': re.sub(r"/0/", f"/{self.pk}/", CMSPlugin._edit_url), |
| 473 | + 'add_url': CMSPlugin._add_url, |
| 474 | + 'delete_url': re.sub(r"/0/", f"/{self.pk}/", CMSPlugin._delete_url), |
| 475 | + 'move_url': CMSPlugin._move_url, |
| 476 | + 'copy_url': CMSPlugin._copy_url, |
466 | 477 | }
|
467 |
| - return data |
468 | 478 |
|
469 | 479 |
|
470 | 480 | def get_plugin_media_path(instance, filename):
|
|
0 commit comments