26 |
26 |
|
27 |
27 |
from combo.apps.assets.models import Asset
|
28 |
28 |
from combo.apps.assets.utils import add_tar_content, clean_assets_files, tar_assets_files, untar_assets_files
|
29 |
|
from combo.apps.maps.models import MapLayer
|
30 |
|
from combo.apps.pwa.models import PwaNavigationEntry, PwaSettings
|
31 |
29 |
|
32 |
30 |
from .models import Page
|
33 |
31 |
|
... | ... | |
53 |
51 |
else:
|
54 |
52 |
payment = False
|
55 |
53 |
|
|
54 |
if 'combo.apps.maps' in settings.INSTALLED_APPS:
|
|
55 |
from combo.apps.maps.models import MapLayer
|
|
56 |
else:
|
|
57 |
cartography = False
|
|
58 |
|
|
59 |
if 'combo.apps.pwa' in settings.INSTALLED_APPS:
|
|
60 |
from combo.apps.pwa.models import PwaNavigationEntry, PwaSettings
|
|
61 |
else:
|
|
62 |
pwa = False
|
|
63 |
|
56 |
64 |
export = {}
|
57 |
65 |
if pages:
|
58 |
66 |
export['pages'] = Page.export_all_for_json()
|
... | ... | |
79 |
87 |
# format.
|
80 |
88 |
data = {'pages': data}
|
81 |
89 |
|
82 |
|
if if_empty and (Page.objects.count() or MapLayer.objects.count()):
|
83 |
|
return
|
84 |
|
|
85 |
90 |
if 'combo.apps.lingo' in settings.INSTALLED_APPS:
|
86 |
91 |
from combo.apps.lingo.models import PaymentBackend, Regie
|
87 |
92 |
|
... | ... | |
89 |
94 |
else:
|
90 |
95 |
payment_support = False
|
91 |
96 |
|
|
97 |
if 'combo.apps.maps' in settings.INSTALLED_APPS:
|
|
98 |
from combo.apps.maps.models import MapLayer
|
|
99 |
|
|
100 |
cartography_support = True
|
|
101 |
else:
|
|
102 |
cartography_support = False
|
|
103 |
|
|
104 |
if 'combo.apps.pwa' in settings.INSTALLED_APPS:
|
|
105 |
from combo.apps.pwa.models import PwaNavigationEntry, PwaSettings
|
|
106 |
|
|
107 |
pwa_support = True
|
|
108 |
else:
|
|
109 |
pwa_support = False
|
|
110 |
|
|
111 |
if if_empty and (Page.objects.count() or (cartography_support and MapLayer.objects.count())):
|
|
112 |
return
|
|
113 |
|
92 |
114 |
# check groups used in access control are all available.
|
93 |
115 |
groups = set()
|
94 |
116 |
for page in data.get('pages') or []:
|
... | ... | |
105 |
127 |
|
106 |
128 |
with transaction.atomic():
|
107 |
129 |
if clean:
|
108 |
|
MapLayer.objects.all().delete()
|
|
130 |
if cartography_support:
|
|
131 |
MapLayer.objects.all().delete()
|
109 |
132 |
Asset.objects.all().delete()
|
110 |
133 |
Page.objects.all().delete()
|
111 |
|
PwaSettings.objects.all().delete()
|
112 |
|
PwaNavigationEntry.objects.all().delete()
|
|
134 |
if pwa_support:
|
|
135 |
PwaSettings.objects.all().delete()
|
|
136 |
PwaNavigationEntry.objects.all().delete()
|
113 |
137 |
if payment_support:
|
114 |
138 |
PaymentBackend.objects.all().delete()
|
115 |
139 |
Regie.objects.all().delete()
|
116 |
140 |
|
117 |
141 |
try:
|
118 |
|
MapLayer.load_serialized_objects(data.get('map-layers') or [])
|
|
142 |
if data.get('map-layers') and cartography_support:
|
|
143 |
MapLayer.load_serialized_objects(data.get('map-layers'))
|
119 |
144 |
Asset.load_serialized_objects(data.get('assets') or [])
|
120 |
145 |
pages = Page.load_serialized_pages(data.get('pages') or [], request=request)
|
121 |
146 |
|
122 |
|
if data.get('pwa'):
|
|
147 |
if data.get('pwa') and pwa_support:
|
123 |
148 |
PwaSettings.load_serialized_settings(data['pwa'].get('settings'))
|
124 |
149 |
PwaNavigationEntry.load_serialized_objects(data['pwa'].get('navigation'))
|
125 |
150 |
if data.get('payment') and payment_support:
|
... | ... | |
153 |
178 |
except KeyError:
|
154 |
179 |
raise ImportSiteError(_('TAR file should provide _site.json file'))
|
155 |
180 |
|
156 |
|
if if_empty and (Page.objects.count() or MapLayer.objects.count()):
|
|
181 |
if 'combo.apps.maps' in settings.INSTALLED_APPS:
|
|
182 |
from combo.apps.maps.models import MapLayer
|
|
183 |
|
|
184 |
cartography_support = True
|
|
185 |
else:
|
|
186 |
cartography_support = False
|
|
187 |
|
|
188 |
if if_empty and (Page.objects.count() or (cartography_support and MapLayer.objects.count())):
|
157 |
189 |
return
|
158 |
190 |
|
159 |
191 |
if clean:
|
160 |
|
-
|