|
1 |
from django.db import migrations
|
|
2 |
|
|
3 |
|
|
4 |
def forwards(apps, schema_editor):
|
|
5 |
WcsCardsCell = apps.get_model('wcs', 'WcsCardsCell')
|
|
6 |
WcsCardInfosCell = apps.get_model('wcs', 'WcsCardInfosCell')
|
|
7 |
WcsCardCell = apps.get_model('wcs', 'WcsCardCell')
|
|
8 |
|
|
9 |
# migrate cards cell
|
|
10 |
for cell in WcsCardsCell.objects.order_by('pk'):
|
|
11 |
new_cell = WcsCardCell(
|
|
12 |
# base cell config
|
|
13 |
page=cell.page,
|
|
14 |
placeholder=cell.placeholder,
|
|
15 |
order=cell.order,
|
|
16 |
slug=cell.slug,
|
|
17 |
extra_css_class=cell.extra_css_class,
|
|
18 |
template_name=cell.template_name,
|
|
19 |
condition=cell.condition,
|
|
20 |
public=cell.public,
|
|
21 |
restricted_to_unlogged=cell.restricted_to_unlogged,
|
|
22 |
last_update_timestamp=cell.last_update_timestamp,
|
|
23 |
# cell config
|
|
24 |
carddef_reference=cell.carddef_reference,
|
|
25 |
related_card_path='__all__',
|
|
26 |
card_ids='',
|
|
27 |
only_for_user=cell.only_for_user,
|
|
28 |
without_user=cell.without_user,
|
|
29 |
limit=cell.limit,
|
|
30 |
custom_schema={},
|
|
31 |
display_mode='table',
|
|
32 |
title_type='auto',
|
|
33 |
custom_title='',
|
|
34 |
cached_title=cell.cached_title,
|
|
35 |
)
|
|
36 |
if cell.custom_title:
|
|
37 |
new_cell.title_type = 'manual'
|
|
38 |
new_cell.custom_title = cell.custom_title
|
|
39 |
new_cell.save()
|
|
40 |
new_cell.groups.set(cell.groups.all())
|
|
41 |
# validity infos are lost
|
|
42 |
|
|
43 |
# update page's related_cells cache
|
|
44 |
if 'wcs_wcscardcell' not in new_cell.page.related_cells.get('cell_types', []):
|
|
45 |
new_cell.page.related_cells['cell_types'].append('wcs_wcscardcell')
|
|
46 |
new_cell.page.save()
|
|
47 |
|
|
48 |
# migrate card cell
|
|
49 |
for cell in WcsCardInfosCell.objects.order_by('pk'):
|
|
50 |
new_cell = WcsCardCell(
|
|
51 |
# base cell config
|
|
52 |
page=cell.page,
|
|
53 |
placeholder=cell.placeholder,
|
|
54 |
order=cell.order,
|
|
55 |
slug=cell.slug,
|
|
56 |
extra_css_class=cell.extra_css_class,
|
|
57 |
template_name=cell.template_name,
|
|
58 |
condition=cell.condition,
|
|
59 |
public=cell.public,
|
|
60 |
restricted_to_unlogged=cell.restricted_to_unlogged,
|
|
61 |
last_update_timestamp=cell.last_update_timestamp,
|
|
62 |
# cell config
|
|
63 |
carddef_reference=cell.carddef_reference,
|
|
64 |
related_card_path=cell.related_card_path,
|
|
65 |
card_ids=cell.card_ids,
|
|
66 |
only_for_user=cell.only_for_user,
|
|
67 |
without_user=cell.without_user,
|
|
68 |
limit=cell.limit,
|
|
69 |
custom_schema=cell.custom_schema,
|
|
70 |
display_mode=cell.display_mode,
|
|
71 |
title_type=cell.title_type,
|
|
72 |
custom_title=cell.custom_title,
|
|
73 |
cached_title=cell.cached_title,
|
|
74 |
cached_json=cell.cached_json,
|
|
75 |
)
|
|
76 |
|
|
77 |
new_cell.save()
|
|
78 |
new_cell.groups.set(cell.groups.all())
|
|
79 |
# validity infos are lost
|
|
80 |
|
|
81 |
# update page's related_cells cache
|
|
82 |
if 'wcs_wcscardcell' not in new_cell.page.related_cells.get('cell_types', []):
|
|
83 |
new_cell.page.related_cells['cell_types'].append('wcs_wcscardcell')
|
|
84 |
new_cell.page.save()
|
|
85 |
|
|
86 |
|
|
87 |
class Migration(migrations.Migration):
|
|
88 |
|
|
89 |
dependencies = [
|
|
90 |
('wcs', '0051_new_card_cell'),
|
|
91 |
]
|
|
92 |
|
|
93 |
operations = [
|
|
94 |
migrations.RunPython(forwards, reverse_code=migrations.RunPython.noop),
|
|
95 |
]
|
0 |
|
-
|