Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Added

### Changed
* Added an ID attribute to Entry exported yaml data for importing its data.
Contributed by @userlocalhost

### Fixed

Expand Down
1 change: 1 addition & 0 deletions dashboard/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def _get_attr_value(atype: int, value: dict):
resp_data: dict = {}
for index, entry_info in enumerate(values):
data: dict = {
"id": entry_info["entry"]["id"],
"name": entry_info["entry"]["name"],
"attrs": {},
}
Expand Down
3 changes: 3 additions & 0 deletions dashboard/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,7 @@ def test_yaml_export(self):
"date": {"type": AttrTypeValue["date"], "value": date(2020, 1, 1)},
}
entities = []
test_entries = []
for index in range(2):
entity = Entity.objects.create(name="Entity-%d" % index, created_user=user)
for attr_name, info in attr_info.items():
Expand Down Expand Up @@ -1283,6 +1284,7 @@ def test_yaml_export(self):
attrv = attr.add_value(user, info["value"])

entry.register_es()
test_entries.append(entry)

entities.append(entity)

Expand All @@ -1308,6 +1310,7 @@ def test_yaml_export(self):
len(resp_data[entity.name]), Entry.objects.filter(schema=entity).count()
)
for e_data in resp_data[entity.name]:
self.assertTrue(e_data["id"] in [x.id for x in test_entries])
self.assertTrue(e_data["name"] in ["e-0", "e-1"])
self.assertTrue(all([x in attr_info.keys() for x in e_data["attrs"]]))

Expand Down
4 changes: 2 additions & 2 deletions entry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ def export(self, user):
else:
attrinfo[attr.schema.name] = None

return {"name": self.name, "attrs": attrinfo}
return {"id": self.id, "name": self.name, "attrs": attrinfo}

def export_v2(self, user, with_entity: bool = False) -> dict:
attrinfo = []
Expand Down Expand Up @@ -1790,7 +1790,7 @@ def export_v2(self, user, with_entity: bool = False) -> dict:
}
)

return {"name": self.name, "attrs": attrinfo}
return {"id": self.id, "name": self.name, "attrs": attrinfo}

# NOTE: Type-Write
def get_es_document(self, es=None, entity_attrs=None):
Expand Down
2 changes: 2 additions & 0 deletions entry/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ExportedEntryAttribute(TypedDict):


class ExportedEntry(TypedDict):
id: int
name: str
attrs: list[ExportedEntryAttribute]
referrals: NotRequired[list[dict]] # same as ExportedEntityEntries, avoiding cycle definition
Expand Down Expand Up @@ -321,6 +322,7 @@ def _get_attr_value(atype: int, value: dict):
resp_data: List[ExportedEntityEntries] = []
for index, entry_info in enumerate(values):
data: ExportedEntry = {
"id": entry_info["entry"]["id"],
"name": entry_info["entry"]["name"],
"attrs": [],
}
Expand Down
10 changes: 8 additions & 2 deletions entry/tests/test_api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4155,7 +4155,7 @@ def test_export_advanced_search_result_with_no_value(self):
"entry.tasks.export_search_result_v2.delay", Mock(side_effect=tasks.export_search_result_v2)
)
def test_export_with_all_entities(self):
self.add_entry(self.user, "Entry", self.entity, values={"val": "hoge"})
test_entry = self.add_entry(self.user, "Entry", self.entity, values={"val": "hoge"})

resp = self.client.post(
"/entry/api/v2/advanced_search_result_export/",
Expand Down Expand Up @@ -4202,7 +4202,13 @@ def test_export_with_all_entities(self):
[
{
"entity": "test-entity",
"entries": [{"attrs": [{"name": "val", "value": "hoge"}], "name": "Entry"}],
"entries": [
{
"attrs": [{"name": "val", "value": "hoge"}],
"name": "Entry",
"id": test_entry.id,
}
],
}
],
)
Expand Down
3 changes: 3 additions & 0 deletions entry/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,8 @@ def test_export_entry(self):
)
exported_data = entry.export(user)
self.assertTrue("new_attr" in exported_data["attrs"])
self.assertEqual(exported_data["id"], entry.id)
self.assertEqual(exported_data["name"], entry.name)

def test_export_entry_v2(self):
user = User.objects.create(username="hoge")
Expand Down Expand Up @@ -1901,6 +1903,7 @@ def test_export_entry_v2(self):
entry.attrs.get(name="str2").add_value(user, "bar")

exported_data = entry.export_v2(user)
self.assertEqual(exported_data["id"], entry.id)
self.assertEqual(exported_data["name"], entry.name)
self.assertEqual(
len(exported_data["attrs"]),
Expand Down