Skip to content

Commit a333893

Browse files
wfehrfsbraun
andauthored
added 2 settings to provide custom functions for processing data (#27)
- instead of having X forks for custom code, 2 entrypoints can be used to provide some possibility to change data in projects Co-authored-by: Fabian Braun <[email protected]>
1 parent 241555f commit a333893

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ If you have a custom user model, you should designate a "migration user" by spec
7878
CMS_MIGRATION_USER_ID = <user id>
7979
```
8080

81+
If you want to adjust data to get the migration running in your project, there are 2 function-points available:
82+
83+
```
84+
CMS_MIGRATION_PROCESS_MIGRATION_PREPARATION = "mymodule.myfunction2"
85+
CMS_MIGRATION_PROCESS_PAGE_REFERENCES = "mymodule.myfunction"
86+
```
87+
88+
The latter function is supplied with parameters `page` and `replacement_page`.
89+
8190
## Running
8291
Simply run the following command to run the data migration.
8392
**Note:** This command calls the django migrate command, this is because it has to run commands that save information that would have been lost by running the cms migrations directly.

djangocms_4_migration/management/commands/migration_cleanup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ def _fix_page_references(page):
123123
**{rel.field.name: replacement_page}
124124
)
125125

126+
custom_function = getattr(settings, "CMS_MIGRATION_PROCESS_PAGE_REFERENCES", None)
127+
if custom_function:
128+
module, function = custom_function.rsplit(".", 1)
129+
getattr(
130+
__import__(module, fromlist=[""]),
131+
function,
132+
)(page, replacement_page)
133+
126134

127135
def _delete_page(page):
128136
try:

djangocms_4_migration/management/commands/migration_preparation.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from django.conf import settings
34
from django.core.management.base import BaseCommand
45
from django.db import connection
56

@@ -19,3 +20,11 @@ def handle(self, *args, **options):
1920
cursor.execute("DROP table djangocms_history_placeholderoperation;")
2021
except:
2122
logger.info("djangocms_history already removed")
23+
24+
custom_function = getattr(settings, "CMS_MIGRATION_PROCESS_MIGRATION_PREPARATION", None)
25+
if custom_function:
26+
module, function = custom_function.rsplit(".", 1)
27+
getattr(
28+
__import__(module, fromlist=[""]),
29+
function,
30+
)()

0 commit comments

Comments
 (0)