Skip to content

Commit

Permalink
-Add downloads page with link to project and author CSVs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tompollard committed Aug 7, 2024
1 parent 45b5696 commit a2275ed
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 2 deletions.
1 change: 1 addition & 0 deletions physionet-django/console/navbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def get_menu_items(self, request):
NavLink(_('Editorial'), 'editorial_stats'),
NavLink(_('Credentialing'), 'credentialing_stats'),
NavLink(_('Submissions'), 'submission_stats'),
NavLink(_('Download data'), 'downloads'),
]),

NavSubmenu(_('Pages'), 'pages', 'window-maximize', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

{% load static %}

{% block title %}Identity checks{% endblock %}
{% block title %}Credentialing metrics{% endblock %}

{% block content %}

<div class="card mb-3">
<div class="card-header">
Time to check identity
Credentialing metrics
</div>
<div class="card-body">
<div class="table-responsive">
Expand Down
3 changes: 3 additions & 0 deletions physionet-django/console/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
path('usage/editorial/stats/', views.editorial_stats, name='editorial_stats'),
path('usage/credentialing/stats/', views.credentialing_stats, name='credentialing_stats'),
path('usage/submission/stats/', views.submission_stats, name='submission_stats'),
path('downloads/', views.downloads, name='downloads'),
path('download/users/', views.download_users, name='download_users'),
path('download/projects/', views.download_projects, name='download_projects'),

# redirects
path('redirects/', views.view_redirects, name='redirects'),
Expand Down
167 changes: 167 additions & 0 deletions physionet-django/console/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2336,6 +2336,173 @@ def submission_stats(request):
{'submenu': 'submission', 'stats': stats})


@console_permission_required('project.can_view_stats')
def downloads(request):
"""
Display page in the console with a list of downloadable CSVs.
"""
return render(request, 'console/downloads.html',
{'submenu': 'submission'})


@console_permission_required('project.can_view_stats')
def download_users(request):
"""
Delivers a CSV file containing data on users.
"""
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="users.csv"'

writer = csv.writer(response)
csv_header = ["user_id",
"username",
"join_date",
"last_login",
"registration_ip",
"is_active_user",
"primary_email",
"all_emails",
"first_names",
"last_name",
"full_name",
"affiliation",
"location",
"website",
"orcid_id",
"credentialing_status",
"credentialing_organization_name",
"credentialing_job_title",
"credentialing_city",
"credentialing_state_or_province",
"credentialing_country",
"credentialing_webpage",
"credentialing_reference_name",
"credentialing_reference_email",
"credentialing_reference_org",
"credentialing_reference_response",
"credentialing_research_summary"]

writer.writerow(csv_header)

users = User.objects.all()
for user in users:
credentials = user.credential_applications.filter(
status=CredentialApplication.Status.ACCEPTED).order_by('decision_datetime').last()
writer.writerow([user.id,
user.username,
user.join_date,
user.last_login,
user.registration_ip,
user.is_active,
user.get_primary_email() if credentials else None,
', '.join(user.get_emails()),
user.profile.first_names,
user.profile.last_name,
user.profile.get_full_name(),
user.profile.affiliation,
user.profile.location,
user.profile.website,
user.get_orcid_id(),
user.get_credentialing_status(),
credentials.organization_name if credentials else None,
credentials.job_title if credentials else None,
credentials.city if credentials else None,
credentials.state_province if credentials else None,
credentials.country if credentials else None,
credentials.webpage if credentials else None,
credentials.reference_name if credentials else None,
credentials.reference_email if credentials else None,
credentials.reference_organization if credentials else None,
credentials.reference_response_text if credentials else None,
credentials.research_summary if credentials else None,
])
return response


@console_permission_required('project.can_view_stats')
def download_projects(request):
"""
Delivers a CSV file containing data on published projects.
"""
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="projects.csv"'

writer = csv.writer(response)
writer.writerow(["project_id",
"core_project_id",
"project_slug",
"version",
"publish_date",
"has_other_versions",
"version_order",
"is_latest_version",
"project_doi",
"core_project_doi",
"full_description",
"submitting_author_id",
"title",
"abstract",
"background",
"methods",
"content_description",
"usage_notes",
"installation",
"acknowledgements",
"conflicts_of_interest",
"release_notes",
"short_description",
"access_policy",
"license",
"data_use_agreement",
"project_home_page",
"ethics_statement",
"corresponding_author_id",
"author_ids",
"associated_paper",
"associated_paper_url",
])

projects = PublishedProject.objects.all()

for project in projects:
authors = project.authors.all().order_by('display_order')
publication = project.publications.first()
writer.writerow([project.id,
project.core_project.id,
project.slug,
project.version,
project.publish_datetime,
project.has_other_versions,
project.version_order,
project.is_latest_version,
project.doi,
project.core_project.doi,
project.full_description,
project.submitting_author().id,
project.title,
project.abstract,
project.background,
project.methods,
project.content_description,
project.usage_notes,
project.installation,
project.acknowledgements,
project.conflicts_of_interest,
project.release_notes,
project.short_description,
project.access_policy,
project.license,
project.dua,
project.project_home_page,
project.ethics_statement,
project.corresponding_author().id,
', '.join(str(author.id) for author in authors),
publication.citation if publication else None,
publication.url if publication else None,
])
return response


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

0 comments on commit a2275ed

Please sign in to comment.