Skip to content

Commit 56b392a

Browse files
authored
chore: Remove duplicate reference to process hook (#51)
1 parent ca9c318 commit 56b392a

File tree

3 files changed

+6
-35
lines changed

3 files changed

+6
-35
lines changed

djangocms_transfer/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def get_serializer_name(default="python"):
99
return getattr(settings, "DJANGO_CMS_TRANSFER_SERIALIZER", default)
1010

1111

12-
def custom_process_hook(transfer_hook, plugin, plugin_data=None):
12+
def custom_process_hook(transfer_hook, plugin, plugin_data):
1313
from importlib import import_module
1414

1515
from django.conf import settings
@@ -24,7 +24,4 @@ def custom_process_hook(transfer_hook, plugin, plugin_data=None):
2424
except (ImportError, AttributeError) as e:
2525
raise ImportError(f"Could not import '{hook}': {e}")
2626

27-
if plugin_data:
28-
return func(plugin, plugin_data)
29-
else:
30-
return func(plugin)
27+
return func(plugin, plugin_data)

djangocms_transfer/datastructures.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import importlib
21
from collections import namedtuple
3-
from typing import Callable
42

53
from cms.api import add_plugin
64
from cms.models import CMSPlugin
7-
from django.conf import settings
85
from django.core.serializers import deserialize
96
from django.db import transaction
107
from django.utils.encoding import force_str
@@ -68,7 +65,6 @@ def restore(self, placeholder, language, parent=None):
6865
target=parent,
6966
**data,
7067
)
71-
self._call_user_site_import_processor_if_necessary(plugin, self.data)
7268

7369
field = ("target",) if plugin_target else ()
7470
# An empty *update_fields* iterable will skip the save
@@ -89,28 +85,6 @@ def restore(self, placeholder, language, parent=None):
8985
# customize plugin-data on import with configured function
9086
custom_process_hook(
9187
"DJANGOCMS_TRANSFER_PROCESS_IMPORT_PLUGIN_DATA",
92-
plugin
88+
plugin, self.data
9389
)
94-
95-
plugin.save()
9690
return plugin
97-
98-
def _call_user_site_import_processor_if_necessary(
99-
self, plugin: CMSPlugin, plugin_data: dict
100-
):
101-
# customize plugin-data on import with configured function
102-
if processor_symbol := getattr(
103-
settings, "DJANGOCMS_TRANSFER_PROCESS_IMPORT_PLUGIN_DATA", None
104-
):
105-
function = self._resolve_function_from_full_path(processor_symbol)
106-
function(plugin, plugin_data)
107-
108-
def _resolve_function_from_full_path(
109-
self, fully_qualified_path: str
110-
) -> Callable:
111-
try:
112-
module_name, function_name = fully_qualified_path.rsplit(".", 1)
113-
module = importlib.import_module(module_name)
114-
return getattr(module, function_name)
115-
except (AttributeError, ImportError):
116-
raise ImportError(f"could not resolve {fully_qualified_path}")

tests/transfer/test_helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_nonexistent_module(self):
2727
ImportError,
2828
custom_process_hook,
2929
"DJANGOCMS_TRANSFER_PROCESS_IMPORT_PLUGIN_DATA",
30-
self.plugin
30+
self.plugin, self.plugin_data
3131
)
3232
self.assertRaises(
3333
ImportError,
@@ -41,9 +41,9 @@ def test_existent_module(self):
4141
self.assertTrue(
4242
custom_process_hook(
4343
"DJANGOCMS_TRANSFER_PROCESS_IMPORT_PLUGIN_DATA",
44-
self.plugin
44+
self.plugin, {}
4545
),
46-
self.plugin
46+
(self.plugin, {})
4747
)
4848
self.assertTrue(
4949
custom_process_hook(

0 commit comments

Comments
 (0)