data: include site settings in import/export (#57923)
This commit is contained in:
parent
0e9e217d90
commit
a00f7e1d5b
|
@ -2221,3 +2221,15 @@ class SiteSettings(models.Model):
|
|||
max_length=100,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def export_json(cls):
|
||||
settings = SiteSettings.objects.get()
|
||||
return {
|
||||
'initial_login_page_path': settings.initial_login_page_path,
|
||||
'welcome_page_path': settings.welcome_page_path,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def import_json(cls, data):
|
||||
SiteSettings.objects.update(**data)
|
||||
|
|
|
@ -27,7 +27,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from combo.apps.assets.models import Asset
|
||||
from combo.apps.assets.utils import add_tar_content, clean_assets_files, tar_assets_files, untar_assets_files
|
||||
|
||||
from .models import Page, extract_context_from_sub_slug
|
||||
from .models import Page, SiteSettings, extract_context_from_sub_slug
|
||||
|
||||
|
||||
class MissingSubSlug(Exception):
|
||||
|
@ -48,7 +48,7 @@ class MissingGroups(ImportSiteError):
|
|||
return _('Missing groups: %s') % ', '.join(self.names)
|
||||
|
||||
|
||||
def export_site(pages=True, cartography=True, pwa=True, assets=True, payment=True):
|
||||
def export_site(pages=True, cartography=True, pwa=True, assets=True, payment=True, site_settings=True):
|
||||
'''Dump site objects to JSON-dumpable dictionnary'''
|
||||
|
||||
if 'combo.apps.lingo' in settings.INSTALLED_APPS:
|
||||
|
@ -83,6 +83,8 @@ def export_site(pages=True, cartography=True, pwa=True, assets=True, payment=Tru
|
|||
'backends': PaymentBackend.export_all_for_json(),
|
||||
'regies': Regie.export_all_for_json(),
|
||||
}
|
||||
if site_settings:
|
||||
export['site_settings'] = SiteSettings.export_json()
|
||||
return export
|
||||
|
||||
|
||||
|
@ -155,6 +157,8 @@ def import_site(data, if_empty=False, clean=False, request=None):
|
|||
if data.get('payment') and payment_support:
|
||||
PaymentBackend.load_serialized_objects(data['payment'].get('backends'))
|
||||
Regie.load_serialized_objects(data['payment'].get('regies'))
|
||||
if data.get('site_settings'):
|
||||
SiteSettings.import_json(data['site_settings'])
|
||||
except DeserializationError as e:
|
||||
message = str(e)
|
||||
if not message.startswith('Page matching query does not exist.'):
|
||||
|
|
|
@ -319,6 +319,7 @@ class SiteExportForm(forms.Form):
|
|||
assets = forms.BooleanField(label=_('Assets'), required=False, initial=True)
|
||||
asset_files = forms.BooleanField(label=_('Assets Files'), required=False, initial=False)
|
||||
payment = forms.BooleanField(label=_('Online Payment'), required=False, initial=True)
|
||||
site_settings = forms.BooleanField(label=_('Site Settings'), required=False, initial=True)
|
||||
|
||||
|
||||
class SiteSettingsForm(forms.ModelForm):
|
||||
|
|
|
@ -21,7 +21,7 @@ from combo.apps.gallery.models import GalleryCell, Image
|
|||
from combo.apps.lingo.models import PaymentBackend, Regie
|
||||
from combo.apps.maps.models import Map, MapLayer, MapLayerOptions
|
||||
from combo.apps.pwa.models import PwaNavigationEntry, PwaSettings
|
||||
from combo.data.models import Page, TextCell
|
||||
from combo.data.models import Page, SiteSettings, TextCell
|
||||
from combo.data.utils import MissingGroups, export_site, import_site
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
@ -486,3 +486,36 @@ def test_import_export_payment(app):
|
|||
empty_output = get_output_of_command('export_site')
|
||||
assert len(json.loads(empty_output)['payment']['backends']) == 0
|
||||
assert len(json.loads(empty_output)['payment']['regies']) == 0
|
||||
|
||||
|
||||
def test_import_export_settings(app):
|
||||
site_settings = SiteSettings.objects.get()
|
||||
site_settings.initial_login_page_path = '/test/'
|
||||
site_settings.welcome_page_path = '/hop/'
|
||||
site_settings.save()
|
||||
|
||||
output = get_output_of_command('export_site')
|
||||
payload = json.loads(output)
|
||||
assert len(payload['site_settings']) == 2
|
||||
|
||||
site_settings.initial_login_page_path = ''
|
||||
site_settings.welcome_page_path = ''
|
||||
site_settings.save()
|
||||
|
||||
import_site(payload)
|
||||
site_settings.refresh_from_db()
|
||||
assert site_settings.initial_login_page_path == '/test/'
|
||||
assert site_settings.welcome_page_path == '/hop/'
|
||||
|
||||
site_settings.initial_login_page_path = ''
|
||||
site_settings.welcome_page_path = ''
|
||||
site_settings.save()
|
||||
|
||||
output = get_output_of_command('export_site')
|
||||
payload = json.loads(output)
|
||||
assert len(payload['site_settings']) == 2
|
||||
|
||||
import_site(payload)
|
||||
site_settings.refresh_from_db()
|
||||
assert site_settings.initial_login_page_path == ''
|
||||
assert site_settings.welcome_page_path == ''
|
||||
|
|
|
@ -926,7 +926,7 @@ def test_site_export_import_json(app, admin_user):
|
|||
resp.form['site_file'] = Upload('site-export.json', site_export, 'application/json')
|
||||
with CaptureQueriesContext(connection) as ctx:
|
||||
resp = resp.form.submit()
|
||||
assert len(ctx.captured_queries) in [302, 303]
|
||||
assert len(ctx.captured_queries) in [303, 304]
|
||||
assert Page.objects.count() == 4
|
||||
assert PageSnapshot.objects.all().count() == 4
|
||||
|
||||
|
@ -937,7 +937,7 @@ def test_site_export_import_json(app, admin_user):
|
|||
resp.form['site_file'] = Upload('site-export.json', site_export, 'application/json')
|
||||
with CaptureQueriesContext(connection) as ctx:
|
||||
resp = resp.form.submit()
|
||||
assert len(ctx.captured_queries) == 272
|
||||
assert len(ctx.captured_queries) == 273
|
||||
assert set(Page.objects.get(slug='one').related_cells['cell_types']) == {'data_textcell', 'data_linkcell'}
|
||||
assert Page.objects.count() == 4
|
||||
assert LinkCell.objects.count() == 2
|
||||
|
@ -954,6 +954,7 @@ def test_site_export_import_json(app, admin_user):
|
|||
site_json = json.loads(site_export.decode())
|
||||
assert 'pages' not in site_json
|
||||
assert 'pwa' in site_json
|
||||
assert 'site_settings' in site_json
|
||||
|
||||
Page.objects.all().delete()
|
||||
resp = app.get('/manage/')
|
||||
|
|
Loading…
Reference in New Issue