Skip to content

Commit

Permalink
chunk_processing: add filename on chunk item
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienbeau committed Apr 22, 2022
1 parent 9f70400 commit 78e0da1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions chunk_processing/components/splitter_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class ChunkSplitterJson(Component):
_name = "chunk.splitter.json"
_usage = "json"

def _convert_items_to_data(self, items):
return json.dumps(items, indent=2).encode("utf-8")

def _parse_data(self, data):
items = json.loads(data.decode("utf-8"))
for idx, item in enumerate(items):
Expand Down
7 changes: 7 additions & 0 deletions chunk_processing/models/chunk_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class ChunkItem(models.Model):
("failed", "Failed"),
]
)
filename = fields.Char(compute="_compute_filename")

def _compute_filename(self):
for record in self:
record.filename = (
f"{record.start_idx}-{record.stop_idx}.{record.group_id.data_format}"
)

def manual_run(self):
""" Run the import without try/except, easier for debug """
Expand Down
3 changes: 2 additions & 1 deletion chunk_processing/views/chunk_item_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
</header>
<sheet>
<group>
<field name="data" />
<field name="data" filename="filename" />
<field name="filename" invisible="1" />
<field name="start_idx" />
<field name="stop_idx" />
<field name="nbr_error" />
Expand Down

0 comments on commit 78e0da1

Please sign in to comment.