Skip to content
Permalink
Browse files

implemented export to tsv and csv

  • Loading branch information...
nad2000 committed Sep 12, 2019
1 parent e9a380d commit 22e083d82a2b615fe4b3fbe0936164c650264c2a
Showing with 32 additions and 2 deletions.
  1. +19 −2 orcid_hub/views.py
  2. +13 −0 tests/test_views.py
@@ -2045,9 +2045,26 @@ class ResourceRecordAdmin(RecordModelView):
], "Resource"),
]

export_column_headers = dict(
name="Resource Name",
type="Resource Type",
start_date="Resource Start date",
end_date="Resource End date",
url="Resource URL",
host_name="Resource Host Name",
host_city="Resource Host City",
host_region="Resource Host Region",
host_country="Resource Host Country",
host_disambiguated_id="Resource Host Disambiguated ID",
host_disambiguation_source="Resource Host Disambiguation Source",
external_id_type="Resource External ID Type",
external_id_value="Resource External Id Value",
external_id_url="Resource External ID URL",
external_id_relationship="Resource External ID Relationship")

def get_export_columns(self):
"""Create a list of exported columns with lables."""
return [(c, self.model._meta.fields[c].help_text or n) for c, n in super().get_export_columns()]
"""Create a list of exported columns with labels."""
return [(c, self.export_column_headers.get(c, n)) for c, n in super().get_export_columns()]


admin.add_view(UserAdmin(User))
@@ -4487,6 +4487,19 @@ def test_research_resources(client, mocker):
task = Task.get(filename="resources.tsv")
assert task.records.count() == 2

for export_type in ["csv", "tsv"]:
resp = client.get(f"/admin/resourcerecord/export/{export_type}/?task_id={task.id}")
file_name = f"resources_reimport.{export_type}"
resp = client.post(
"/load/task/RESOURCE",
data={"file_": (BytesIO(resp.data), file_name)},
follow_redirects=True)
assert resp.status_code == 200
assert b"SYN-18-UOA-001" in resp.data
assert b"invitee1@mailinator.com" in resp.data
t = Task.get(filename=file_name)
assert t.records.count() == 2

send = mocker.patch("emails.message.MessageSendMixin.send")

resp = client.post("/activate_all/?url=/resources", data=dict(task_id=task.id))

0 comments on commit 22e083d

Please sign in to comment.
You can’t perform that action at this time.