0001-data-include-site-settings-in-import-export-57923.patch
combo/data/models.py | ||
---|---|---|
2217 | 2217 |
help_text=_('Page to redirect to on the first visit, to suggest user to log in.'), |
2218 | 2218 |
max_length=100, |
2219 | 2219 |
) |
2220 | ||
2221 |
@classmethod |
|
2222 |
def export_json(cls): |
|
2223 |
settings = SiteSettings.objects.get() |
|
2224 |
return { |
|
2225 |
'initial_login_page_path': settings.initial_login_page_path, |
|
2226 |
'welcome_page_path': settings.welcome_page_path, |
|
2227 |
} |
|
2228 | ||
2229 |
@classmethod |
|
2230 |
def import_json(cls, data): |
|
2231 |
SiteSettings.objects.update(**data) |
combo/data/utils.py | ||
---|---|---|
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 | 29 | |
30 |
from .models import Page, extract_context_from_sub_slug |
|
30 |
from .models import Page, SiteSettings, extract_context_from_sub_slug
|
|
31 | 31 | |
32 | 32 | |
33 | 33 |
class MissingSubSlug(Exception): |
... | ... | |
48 | 48 |
return _('Missing groups: %s') % ', '.join(self.names) |
49 | 49 | |
50 | 50 | |
51 |
def export_site(pages=True, cartography=True, pwa=True, assets=True, payment=True): |
|
51 |
def export_site(pages=True, cartography=True, pwa=True, assets=True, payment=True, site_settings=True):
|
|
52 | 52 |
'''Dump site objects to JSON-dumpable dictionnary''' |
53 | 53 | |
54 | 54 |
if 'combo.apps.lingo' in settings.INSTALLED_APPS: |
... | ... | |
83 | 83 |
'backends': PaymentBackend.export_all_for_json(), |
84 | 84 |
'regies': Regie.export_all_for_json(), |
85 | 85 |
} |
86 |
if site_settings: |
|
87 |
export['site_settings'] = SiteSettings.export_json() |
|
86 | 88 |
return export |
87 | 89 | |
88 | 90 | |
... | ... | |
155 | 157 |
if data.get('payment') and payment_support: |
156 | 158 |
PaymentBackend.load_serialized_objects(data['payment'].get('backends')) |
157 | 159 |
Regie.load_serialized_objects(data['payment'].get('regies')) |
160 |
if data.get('site_settings'): |
|
161 |
SiteSettings.import_json(data['site_settings']) |
|
158 | 162 |
except DeserializationError as e: |
159 | 163 |
message = str(e) |
160 | 164 |
if not message.startswith('Page matching query does not exist.'): |
combo/manager/forms.py | ||
---|---|---|
317 | 317 |
assets = forms.BooleanField(label=_('Assets'), required=False, initial=True) |
318 | 318 |
asset_files = forms.BooleanField(label=_('Assets Files'), required=False, initial=False) |
319 | 319 |
payment = forms.BooleanField(label=_('Online Payment'), required=False, initial=True) |
320 |
site_settings = forms.BooleanField(label=_('Site Settings'), required=False, initial=True) |
|
320 | 321 | |
321 | 322 | |
322 | 323 |
class SiteSettingsForm(forms.ModelForm): |
tests/test_import_export.py | ||
---|---|---|
21 | 21 |
from combo.apps.lingo.models import PaymentBackend, Regie |
22 | 22 |
from combo.apps.maps.models import Map, MapLayer, MapLayerOptions |
23 | 23 |
from combo.apps.pwa.models import PwaNavigationEntry, PwaSettings |
24 |
from combo.data.models import Page, TextCell |
|
24 |
from combo.data.models import Page, SiteSettings, TextCell
|
|
25 | 25 |
from combo.data.utils import MissingGroups, export_site, import_site |
26 | 26 | |
27 | 27 |
pytestmark = pytest.mark.django_db |
... | ... | |
486 | 486 |
empty_output = get_output_of_command('export_site') |
487 | 487 |
assert len(json.loads(empty_output)['payment']['backends']) == 0 |
488 | 488 |
assert len(json.loads(empty_output)['payment']['regies']) == 0 |
489 | ||
490 | ||
491 |
def test_import_export_settings(app): |
|
492 |
site_settings = SiteSettings.objects.get() |
|
493 |
site_settings.initial_login_page_path = '/test/' |
|
494 |
site_settings.welcome_page_path = '/hop/' |
|
495 |
site_settings.save() |
|
496 | ||
497 |
output = get_output_of_command('export_site') |
|
498 |
payload = json.loads(output) |
|
499 |
assert len(payload['site_settings']) == 2 |
|
500 | ||
501 |
site_settings.initial_login_page_path = '' |
|
502 |
site_settings.welcome_page_path = '' |
|
503 |
site_settings.save() |
|
504 | ||
505 |
import_site(payload) |
|
506 |
site_settings.refresh_from_db() |
|
507 |
assert site_settings.initial_login_page_path == '/test/' |
|
508 |
assert site_settings.welcome_page_path == '/hop/' |
|
509 | ||
510 |
site_settings.initial_login_page_path = '' |
|
511 |
site_settings.welcome_page_path = '' |
|
512 |
site_settings.save() |
|
513 | ||
514 |
output = get_output_of_command('export_site') |
|
515 |
payload = json.loads(output) |
|
516 |
assert len(payload['site_settings']) == 2 |
|
517 | ||
518 |
import_site(payload) |
|
519 |
site_settings.refresh_from_db() |
|
520 |
assert site_settings.initial_login_page_path == '' |
|
521 |
assert site_settings.welcome_page_path == '' |
tests/test_manager.py | ||
---|---|---|
895 | 895 |
resp.form['site_file'] = Upload('site-export.json', site_export, 'application/json') |
896 | 896 |
with CaptureQueriesContext(connection) as ctx: |
897 | 897 |
resp = resp.form.submit() |
898 |
assert len(ctx.captured_queries) in [307, 308]
|
|
898 |
assert len(ctx.captured_queries) in [308, 309]
|
|
899 | 899 |
assert Page.objects.count() == 4 |
900 | 900 |
assert PageSnapshot.objects.all().count() == 4 |
901 | 901 | |
... | ... | |
906 | 906 |
resp.form['site_file'] = Upload('site-export.json', site_export, 'application/json') |
907 | 907 |
with CaptureQueriesContext(connection) as ctx: |
908 | 908 |
resp = resp.form.submit() |
909 |
assert len(ctx.captured_queries) == 276
|
|
909 |
assert len(ctx.captured_queries) == 277
|
|
910 | 910 |
assert set(Page.objects.get(slug='one').related_cells['cell_types']) == {'data_textcell', 'data_linkcell'} |
911 | 911 |
assert Page.objects.count() == 4 |
912 | 912 |
assert LinkCell.objects.count() == 2 |
... | ... | |
923 | 923 |
site_json = json.loads(site_export.decode()) |
924 | 924 |
assert 'pages' not in site_json |
925 | 925 |
assert 'pwa' in site_json |
926 |
assert 'site_settings' in site_json |
|
926 | 927 | |
927 | 928 |
Page.objects.all().delete() |
928 | 929 |
resp = app.get('/manage/') |
929 |
- |