0001-misc-allow-importing-objects-with-non-existent-field.patch
combo/apps/assets/models.py | ||
---|---|---|
51 | 51 |
json_asset['model'] = 'assets.asset' |
52 | 52 |
asset, created = Asset.objects.get_or_create(key=json_asset['fields']['key']) |
53 | 53 |
json_asset['pk'] = asset.id |
54 |
asset = [x for x in serializers.deserialize('json', json.dumps([json_asset]))][0]
|
|
54 |
asset = next(serializers.deserialize('json', json.dumps([json_asset]), ignorenonexistent=True))
|
|
55 | 55 |
asset.save() |
combo/apps/gallery/models.py | ||
---|---|---|
43 | 43 |
return {'images': [x.get_as_serialized_object() for x in self.image_set.all()]} |
44 | 44 | |
45 | 45 |
def import_subobjects(self, cell_json): |
46 |
for image in cell_json['images']: |
|
47 |
image['fields']['gallery_id'] = self.id |
|
48 |
for image in serializers.deserialize('json', json.dumps(cell_json['images'])): |
|
46 |
images = serializers.deserialize('json', json.dumps(cell_json['images']), |
|
47 |
ignorenonexistent=True) |
|
48 |
for image in images: |
|
49 |
image.object.gallery_id = self.id |
|
49 | 50 |
image.save() |
50 | 51 | |
51 | 52 |
combo/apps/maps/models.py | ||
---|---|---|
152 | 152 |
json_layer['model'] = 'maps.maplayer' |
153 | 153 |
layer, created = MapLayer.objects.get_or_create(slug=json_layer['fields']['slug']) |
154 | 154 |
json_layer['pk'] = layer.id |
155 |
layer = [x for x in serializers.deserialize('json', json.dumps([json_layer]))][0]
|
|
155 |
layer = next(serializers.deserialize('json', json.dumps([json_layer]), ignorenonexistent=True))
|
|
156 | 156 |
layer.save() |
157 | 157 | |
158 | 158 |
def get_geojson(self, request=None, multiple_layers=False): |
combo/apps/pwa/models.py | ||
---|---|---|
159 | 159 |
def load_serialized_object(cls, json_entry): |
160 | 160 |
json_entry['model'] = 'pwa.pwanavigationentry' |
161 | 161 |
# deserialize once to get link_page by natural key |
162 |
fake_entry = [x for x in serializers.deserialize('json', json.dumps([json_entry]))][0] |
|
162 |
fake_entry = next(serializers.deserialize('json', json.dumps([json_entry]), |
|
163 |
ignorenonexistent=True)) |
|
163 | 164 |
entry, created = cls.objects.get_or_create( |
164 | 165 |
label=json_entry['fields']['label'], |
165 | 166 |
url=json_entry['fields']['url'], |
166 | 167 |
link_page=fake_entry.object.link_page, |
167 | 168 |
defaults={'order': 0}) |
168 | 169 |
json_entry['pk'] = entry.id |
169 |
entry = [x for x in serializers.deserialize('json', json.dumps([json_entry]))][0]
|
|
170 |
entry = next(serializers.deserialize('json', json.dumps([json_entry]), ignorenonexistent=True))
|
|
170 | 171 |
entry.save() |
171 | 172 |
if json_entry.get('icon:base64'): |
172 | 173 |
decode = base64.decodestring if six.PY2 else base64.decodebytes |
combo/data/models.py | ||
---|---|---|
392 | 392 |
json_page['fields']['groups'] = [[x] for x in json_page['fields']['groups'] if isinstance(x, six.string_types)] |
393 | 393 |
page, created = Page.objects.get_or_create(slug=json_page['fields']['slug'], snapshot=snapshot) |
394 | 394 |
json_page['pk'] = page.id |
395 |
page = [x for x in serializers.deserialize('json', json.dumps([json_page]))][0]
|
|
395 |
page = next(serializers.deserialize('json', json.dumps([json_page]), ignorenonexistent=True))
|
|
396 | 396 |
page.object.snapshot = snapshot |
397 | 397 |
page.save() |
398 | 398 |
for cell in json_page.get('cells'): |
... | ... | |
411 | 411 |
@classmethod |
412 | 412 |
def load_serialized_cells(cls, cells): |
413 | 413 |
# load new cells |
414 |
for index, cell in enumerate(serializers.deserialize('json', json.dumps(cells))): |
|
414 |
deserialized_cells = serializers.deserialize('json', json.dumps(cells), |
|
415 |
ignorenonexistent=True) |
|
416 |
for index, cell in enumerate(deserialized_cells): |
|
415 | 417 |
cell.save() |
416 | 418 |
# will populate cached_* attributes |
417 | 419 |
cell.object.save() |
... | ... | |
1041 | 1043 |
def import_subobjects(self, cell_json): |
1042 | 1044 |
for link in cell_json['links']: |
1043 | 1045 |
link['fields']['placeholder'] = self.link_placeholder |
1044 |
for link in serializers.deserialize('json', json.dumps(cell_json['links'])): |
|
1046 |
links = serializers.deserialize('json', json.dumps(cell_json['links']), ignorenonexistent=True) |
|
1047 |
for link in links: |
|
1045 | 1048 |
link.save() |
1046 | 1049 | |
1047 | 1050 |
def duplicate_m2m(self, new_cell): |
tests/test_import_export.py | ||
---|---|---|
274 | 274 | |
275 | 275 |
import_site(data=json.loads(output)) |
276 | 276 |
assert Image.objects.all().count() == 2 |
277 |
assert image1.title == 'foo'
|
|
277 |
image1 = Image.objects.get(title='foo')
|
|
278 | 278 |
assert image1.image == 'path/foo.jpg' |
279 |
assert image1.gallery.placeholder == 'images' |
|
280 | ||
281 |
def test_import_export_extra_fields(app, some_data): |
|
282 |
site_export = export_site() |
|
283 |
for page in site_export['pages']: |
|
284 |
if page['fields']['slug'] == 'one': |
|
285 |
page['fields']['extra_field_not_in_model'] = True |
|
286 |
elif page['fields']['slug'] == 'three': |
|
287 |
page['cells'][0]['fields']['extra_field_not_in_model'] = True |
|
288 | ||
289 |
import_site(site_export) |
|
290 |
assert Page.objects.count() == 3 |
|
291 |
assert TextCell.objects.count() == 1 |
|
279 |
- |