diff --git a/combo/data/models.py b/combo/data/models.py index 423691d2..89091a9b 100644 --- a/combo/data/models.py +++ b/combo/data/models.py @@ -586,7 +586,7 @@ class Page(models.Model): if page is None: qs_kwargs = {} if snapshot: - qs_kwargs = {'snapshot': snapshot} + qs_kwargs = {'snapshot': snapshot} # don't take uuid from snapshot: it has to be unique ! elif json_page['fields'].get('parent'): qs_kwargs = {'parent__slug': json_page['fields']['parent'][0].split('/')[-1] or 'index'} page, created = Page.objects.get_or_create(slug=json_page['fields']['slug'], **qs_kwargs) @@ -604,8 +604,12 @@ class Page(models.Model): ) % json_page['fields']['title'], ) + page_uuid = page.uuid page = next(serializers.deserialize('json', json.dumps([json_page]), ignorenonexistent=True)) page.object.snapshot = snapshot + if snapshot: + # keep the generated uuid + page.object.uuid = page_uuid page.save() for cell in json_page.get('cells'): cell['fields']['groups'] = [[x] for x in cell['fields']['groups'] if isinstance(x, str)] diff --git a/combo/manager/views.py b/combo/manager/views.py index 0231b6f0..33761241 100644 --- a/combo/manager/views.py +++ b/combo/manager/views.py @@ -659,7 +659,7 @@ def snapshot_export(request, *args, **kwargs): page = snapshot.get_page() response = HttpResponse(content_type='application/json') response['Content-Disposition'] = 'attachment; filename="export_page_{}_{}.json"'.format( - snapshot.get_page().slug, snapshot.timestamp.strftime('%Y%m%d') + page.slug, snapshot.timestamp.strftime('%Y%m%d') ) json.dump(page.get_serialized_page(), response, indent=2) return response diff --git a/tests/test_manager.py b/tests/test_manager.py index 74d98569..98d3be53 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -925,12 +925,16 @@ def test_export_page_snapshot(freezer, app, admin_user): history = app.get('/manage/pages/%s/history' % page.id, status=200) resp = history.click('export', index=0, verbose=True) + snapshot_page = Page.snapshots.latest('pk') + assert snapshot_page.uuid != page.uuid assert resp.headers['content-type'] == 'application/json' assert resp.headers['content-disposition'] == 'attachment; filename="export_page_one_20200717.json"' assert resp.json['fields']['title'] == 'Updated Title' resp = history.click('export', index=1, verbose=True) + snapshot_page = Page.snapshots.latest('pk') + assert snapshot_page.uuid != page.uuid assert resp.headers['content-type'] == 'application/json' assert resp.headers['content-disposition'] == 'attachment; filename="export_page_one_20200716.json"' @@ -2471,9 +2475,6 @@ def test_page_discover_placeholder_with_error_cells(app, admin_user): def test_page_versionning(app, admin_user): - Page.objects.all().delete() - PageSnapshot.objects.all() - page = Page(title='One', slug='one') page.save() @@ -2520,6 +2521,8 @@ def test_page_versionning(app, admin_user): resp2 = resp.click('view', index=1) assert len(ctx.captured_queries) == 70 assert Page.snapshots.latest('pk').related_cells == {'cell_types': ['data_textcell']} + snapshot_page = Page.snapshots.latest('pk') + assert snapshot_page.uuid != page.uuid assert resp2.text.index('Hello world') < resp2.text.index('Foobar3') resp2 = resp.click('view', index=0)