Skip to content

Commit 8ebffca

Browse files
committed
Allow replacing the list of objects to dump
1 parent 341986d commit 8ebffca

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Change log
1313
- Changed the ``assert`` statement for checking the dump version into a
1414
``raise`` statement since assertions could be optimized out.
1515
- Renamed ``InvalidSpec`` to ``InvalidSpecError`` to make ruff happier.
16+
- Added an ``objects`` argument to ``dump_specs`` which allows overriding the
17+
list of objects to dump.
1618

1719

1820
`0.5`_ (2023-03-15)

feincms3_data/data.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,15 @@ def silence(*a):
8989
pass
9090

9191

92-
def dump_specs(specs, *, mappers=None):
92+
def dump_specs(specs, *, mappers=None, objects=None):
9393
stream = io.StringIO()
9494
stream.write('{"version": 1, "specs": ')
9595
json.dump(specs, stream)
9696
stream.write(', "objects": ')
9797
serializer = JSONSerializer(mappers=mappers or {})
98-
serializer.serialize(
99-
chain.from_iterable(_model_queryset(spec) for spec in specs),
100-
stream=stream,
101-
)
98+
if objects is None:
99+
objects = chain.from_iterable(_model_queryset(spec) for spec in specs)
100+
serializer.serialize(objects, stream=stream)
102101
stream.write("}")
103102
return stream.getvalue()
104103

0 commit comments

Comments
 (0)