Skip to content

Commit

Permalink
Add option to download a published authors CSV from the console (#2279)
Browse files Browse the repository at this point in the history
This adds another download option on top of what was introduced in #2270
. It gives the option to download all of the published author objects
and related data.

I've included all the base `PublishedAuthor` fields and have linked to a
couple of other relevant fields (`user_id`, `project_id`, etc.). I'm
happy to add / remove fields as desired.
  • Loading branch information
tompollard authored Aug 21, 2024
2 parents 11d9429 + 971782b commit 5556e8b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
8 changes: 8 additions & 0 deletions physionet-django/console/templates/console/downloads.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ <h6>Published projects</h6>
</a>
</div>

<div class="mb-4">
<h6>Published authors</h6>
<p>Download a complete list of published authors, including their names, email addresses, and affiliations.</p>
<a href="{% url 'download_published_authors' %}" class="btn btn-primary">
Download published authors
</a>
</div>

</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions physionet-django/console/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
path('downloads/', views.downloads, name='downloads'),
path('download/users/', views.download_users, name='download_users'),
path('download/projects/', views.download_projects, name='download_projects'),
path('download/published_authors/', views.download_published_authors, name='download_published_authors'),

# redirects
path('redirects/', views.view_redirects, name='redirects'),
Expand Down
52 changes: 52 additions & 0 deletions physionet-django/console/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
EditLog,
License,
Publication,
PublishedAuthor,
PublishedProject,
Reference,
StorageRequest,
Expand Down Expand Up @@ -2542,6 +2543,57 @@ def clean_html(html_content):
return response


@console_permission_required('user.change_credentialapplication')
def download_published_authors(request):
"""
Delivers a CSV file containing data on published authors.
"""
authors = PublishedAuthor.objects.all()
response = StreamingHttpResponse(
(csv.writer(Echo(), quoting=csv.QUOTE_ALL).writerow(row) for row in get_published_authors(authors)),
content_type='text/csv'
)

response['Content-Disposition'] = 'attachment; filename="published_authors.csv"'
return response


def get_published_authors(authors):
"""
Generates published author data for download
"""
csv_header = ["published_author_id",
"project_id",
"user_id",
"first_names",
"last_name",
"corresponding_email",
"all_emails",
"affiliations",
"approval_datetime",
"is_corresponding",
"is_submitting",
"display_order"
]
yield csv_header

for author in authors:

yield [author.id,
author.project.id,
author.user.id,
author.first_names,
author.last_name,
author.corresponding_email,
', '.join(author.user.get_emails()),
'; '.join([a.name for a in author.affiliations.all()]),
author.approval_datetime,
author.is_corresponding,
author.is_submitting,
author.display_order
]


@console_permission_required('project.can_view_access_logs')
def download_credentialed_users(request):
"""
Expand Down

0 comments on commit 5556e8b

Please sign in to comment.