0001-data-allow-missing-link_page-on-LinkCell-import-6032.patch
combo/data/models.py | ||
---|---|---|
1461 | 1461 |
self.check_validity() |
1462 | 1462 |
return result |
1463 | 1463 | |
1464 |
@staticmethod |
|
1465 |
@utils.cache_during_request |
|
1466 |
def get_page_slugs(): |
|
1467 |
return {page.slug for page in Page.objects.all()} |
|
1468 | ||
1469 |
@classmethod |
|
1470 |
def prepare_serialized_data(cls, cell_data): |
|
1471 |
if 'link_page' in cell_data['fields']: |
|
1472 |
link_page_slug = cell_data['fields']['link_page'][0].strip('/').split('/')[-1] |
|
1473 |
if link_page_slug not in cls.get_page_slugs(): |
|
1474 |
del cell_data['fields']['link_page'] |
|
1475 |
return cell_data |
|
1476 | ||
1464 | 1477 |
def get_additional_label(self): |
1465 | 1478 |
title = self.title |
1466 | 1479 |
if not title and self.link_page: |
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, SiteSettings, TextCell |
|
24 |
from combo.data.models import LinkCell, Page, SiteSettings, TextCell
|
|
25 | 25 |
from combo.data.utils import MissingGroups, export_site, import_site |
26 | 26 | |
27 | 27 |
pytestmark = pytest.mark.django_db |
... | ... | |
519 | 519 |
site_settings.refresh_from_db() |
520 | 520 |
assert site_settings.initial_login_page_path == '' |
521 | 521 |
assert site_settings.welcome_page_path == '' |
522 | ||
523 | ||
524 |
def test_import_export_linkcell_to_missing_page(app, admin_user): |
|
525 |
page1 = Page.objects.create(title='One', slug='one') |
|
526 |
page2 = Page.objects.create(title='Two', slug='two') |
|
527 |
link_cell = LinkCell.objects.create(page=page1, link_page=page2, placeholder='content', order=0) |
|
528 | ||
529 |
output = get_output_of_command('export_site') |
|
530 |
payload = json.loads(output) |
|
531 |
del payload['pages'][1] |
|
532 |
import_site(data=payload, clean=True) |
|
533 | ||
534 |
cell = LinkCell.objects.get() |
|
535 |
assert cell.link_page == None |
|
536 |
assert cell.get_validity_info().invalid_reason_code == 'data_url_not_defined' |
tests/test_manager.py | ||
---|---|---|
926 | 926 |
resp.form['site_file'] = Upload('site-export.json', site_export, 'application/json') |
927 | 927 |
with CaptureQueriesContext(connection) as ctx: |
928 | 928 |
resp = resp.form.submit() |
929 |
assert len(ctx.captured_queries) in [303, 304]
|
|
929 |
assert len(ctx.captured_queries) in [304, 305]
|
|
930 | 930 |
assert Page.objects.count() == 4 |
931 | 931 |
assert PageSnapshot.objects.all().count() == 4 |
932 | 932 | |
... | ... | |
937 | 937 |
resp.form['site_file'] = Upload('site-export.json', site_export, 'application/json') |
938 | 938 |
with CaptureQueriesContext(connection) as ctx: |
939 | 939 |
resp = resp.form.submit() |
940 |
assert len(ctx.captured_queries) == 273
|
|
940 |
assert len(ctx.captured_queries) == 274
|
|
941 | 941 |
assert set(Page.objects.get(slug='one').related_cells['cell_types']) == {'data_textcell', 'data_linkcell'} |
942 | 942 |
assert Page.objects.count() == 4 |
943 | 943 |
assert LinkCell.objects.count() == 2 |
944 |
- |