Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit e9cc04a

Browse files
committed
Start work on cmsplugin_filer migration
1 parent b0aece1 commit e9cc04a

File tree

2 files changed

+188
-1
lines changed

2 files changed

+188
-1
lines changed
+187
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# Generated by Django 2.2.17 on 2020-11-04 21:30
2+
3+
from django.apps import apps as global_apps
4+
from django.db import migrations
5+
from djangocms_file.models import get_templates as get_file_templates
6+
from djangocms_picture.models import get_templates as get_picture_templates
7+
8+
9+
def forwards_filer_file(apps, schema_editor):
10+
try:
11+
CMSPluginFilerFile = apps.get_model('cmsplugin_filer_file', 'FilerFile')
12+
except LookupError:
13+
return
14+
15+
DjangoCMSFileFile = apps.get_model('djangocms_file', 'File')
16+
for old_object in CMSPluginFilerFile.objects.all():
17+
old_cmsplugin_ptr = old_object.cmsplugin_ptr
18+
new_object = DjangoCMSFileFile(
19+
file_name=old_object.title,
20+
file_src=old_object.file,
21+
# defaults for fields that don't exist in the old_object
22+
link_target='',
23+
template=get_file_templates()[0][0],
24+
show_file_size=1,
25+
# fields for the cms_cmsplugin table
26+
position=old_cmsplugin_ptr.position,
27+
language=old_cmsplugin_ptr.language,
28+
plugin_type='FilePlugin',
29+
creation_date=old_cmsplugin_ptr.creation_date,
30+
changed_date=old_cmsplugin_ptr.changed_date,
31+
parent=old_cmsplugin_ptr.parent,
32+
placeholder=old_cmsplugin_ptr.placeholder,
33+
depth=old_cmsplugin_ptr.depth,
34+
numchild=old_cmsplugin_ptr.numchild,
35+
path=old_cmsplugin_ptr.path,
36+
)
37+
old_object.delete()
38+
new_object.save()
39+
40+
41+
def forwards_filer_folder(apps, schema_editor):
42+
try:
43+
CMSPluginFilerFolder = apps.get_model('cmsplugin_filer_folder', 'FilerFolder')
44+
except LookupError:
45+
return
46+
47+
DjangoCMSFileFolder = apps.get_model('djangocms_file', 'Folder')
48+
for old_object in CMSPluginFilerFolder.objects.all():
49+
old_cmsplugin_ptr = old_object.cmsplugin_ptr
50+
new_object = DjangoCMSFileFolder(
51+
folder_src=old_object.folder,
52+
# defaults for fields that don't exist in the old_object
53+
template=get_file_templates()[0][0],
54+
link_target='',
55+
show_file_size=0,
56+
# fields for the cms_cmsplugin table
57+
position=old_cmsplugin_ptr.position,
58+
language=old_cmsplugin_ptr.language,
59+
plugin_type='FolderPlugin',
60+
creation_date=old_cmsplugin_ptr.creation_date,
61+
changed_date=old_cmsplugin_ptr.changed_date,
62+
parent=old_cmsplugin_ptr.parent,
63+
placeholder=old_cmsplugin_ptr.placeholder,
64+
depth=old_cmsplugin_ptr.depth,
65+
numchild=old_cmsplugin_ptr.numchild,
66+
path=old_cmsplugin_ptr.path,
67+
)
68+
old_object.delete()
69+
new_object.save()
70+
71+
72+
def forwards_filer_image(apps, schema_editor):
73+
try:
74+
CMSPluginFilerImage = apps.get_model('cmsplugin_filer_image', 'FilerImage')
75+
except LookupError:
76+
return
77+
78+
DjangoCMSPicture = apps.get_model('djangocms_picture', 'Picture')
79+
for old_object in CMSPluginFilerImage.objects.all():
80+
old_cmsplugin_ptr = old_object.cmsplugin_ptr
81+
attributes = {}
82+
if old_object.alt_text:
83+
attributes.update({'alt': old_object.alt_text})
84+
new_object = DjangoCMSPicture(
85+
caption_text=old_object.caption_text,
86+
external_picture=old_object.image_url
87+
if old_object.image_url else '',
88+
use_automatic_scaling=old_object.use_autoscale,
89+
width=old_object.width,
90+
height=old_object.height,
91+
use_crop=old_object.crop,
92+
use_upscale=old_object.upscale,
93+
alignment=old_object.alignment if old_object.alignment else '',
94+
picture=old_object.image,
95+
thumbnail_options=old_object.thumbnail_option,
96+
attributes=attributes,
97+
link_attributes=old_object.link_attributes,
98+
# defaults for fields that don't exist in the old_object
99+
use_no_cropping=0,
100+
template=get_picture_templates()[0][0],
101+
# fields for the cms_cmsplugin table
102+
position=old_cmsplugin_ptr.position,
103+
language=old_cmsplugin_ptr.language,
104+
plugin_type='PicturePlugin',
105+
creation_date=old_cmsplugin_ptr.creation_date,
106+
changed_date=old_cmsplugin_ptr.changed_date,
107+
parent=old_cmsplugin_ptr.parent,
108+
placeholder=old_cmsplugin_ptr.placeholder,
109+
depth=old_cmsplugin_ptr.depth,
110+
numchild=old_cmsplugin_ptr.numchild,
111+
path=old_cmsplugin_ptr.path,
112+
)
113+
old_object.delete()
114+
new_object.save()
115+
116+
def forwards_filer_video(apps, schema_editor):
117+
pass
118+
119+
# == TODO ==
120+
#
121+
# * [ ] forward: djangocms-video
122+
# * [x] forward: djangocms-file
123+
# * [x] version: djangocms-picture
124+
# * [ ] version: django-filer
125+
126+
# == Notes ==
127+
#
128+
# djangocms-picture 0008: added ``use_responsive_image`` (default='inherit')
129+
130+
131+
class Migration(migrations.Migration):
132+
'''
133+
Move data from filer-plugins to the new djangocms-*-plugins. Inspiration:
134+
https://docs.djangoproject.com/en/2.0/howto/writing-migrations/
135+
#migrating-data-between-third-party-apps
136+
'''
137+
operations = [
138+
migrations.RunPython(forwards)
139+
]
140+
dependencies = [
141+
('d120', '0002_auto_20161217_1707'),
142+
]
143+
run_before = []
144+
145+
file_installed = global_apps.is_installed('cmsplugin_filer_file')
146+
folder_installed = global_apps.is_installed('cmsplugin_filer_folder')
147+
image_installed = global_apps.is_installed('cmsplugin_filer_image')
148+
teaser_installed = global_apps.is_installed('cmsplugin_filer_teaser')
149+
video_installed = global_apps.is_installed('cmsplugin_filer_video')
150+
151+
# -- Images --
152+
153+
if image_installed:
154+
dependencies.append(('cmsplugin_filer_image', '0010_auto_20191127_1058'))
155+
#('djangocms_picture', '0007_fix_alignment'),
156+
#('djangocms_picture', '0008_picture_use_responsive_image'),
157+
#('djangocms_picture', '0009_auto_20181212_1003'),
158+
#('djangocms_picture', '0010_auto_20190627_0432'),
159+
dependencies.append(('djangocms_picture', '0011_auto_20190314_1536'))
160+
operations.append(migrations.RunPython(forwards_filer_image))
161+
162+
# -- Files & Folders --
163+
164+
if file_installed:
165+
dependencies.append(('cmsplugin_filer_file', '0005_auto_20160713_1853'))
166+
operations.append(migrations.RunPython(forwards_filer_file))
167+
if folder_installed:
168+
dependencies.append(('cmsplugin_filer_folder', '0003_auto_20160713_1853'))
169+
operations.append(migrations.RunPython(forwards_filer_folder))
170+
171+
if file_installed or folder_installed:
172+
#('djangocms_file', '0010_removed_null_fields'),
173+
dependencies.append(('djangocms_file', '0011_auto_20181211_0357'))
174+
175+
# -- Teaser --
176+
177+
if teaser_installed:
178+
dependencies.append(('cmsplugin_filer_teaser', '0004_auto_20191127_1058'))
179+
# TODO
180+
181+
# -- Video --
182+
183+
if video_installed:
184+
dependencies.append(('cmsplugin_filer_video', '0004_auto_20191126_2231'))
185+
dependencies.append(('djangocms_video', '0002_set_related_name_for_cmsplugin_ptr'))
186+
run_before.append(('djangocms_video', '0003_field_adaptions'))
187+
operations.append(migrations.RunPython(forwards_filer_video))

d120/settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
'cmsplugin_filer_file',
5454
'cmsplugin_filer_folder',
5555
'cmsplugin_filer_teaser',
56-
'cmsplugin_filer_utils',
56+
'cmsplugin_filer_utils', # this isn't even an app
5757
'cmsplugin_filer_video',
5858
'djangocms_redirect',
5959
'djangocms_history',

0 commit comments

Comments
 (0)