From a2275ed0c0bb123076a3b3c8ed2fb5c59b838e94 Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Wed, 7 Aug 2024 11:20:07 -0400 Subject: [PATCH] -Add downloads page with link to project and author CSVs. --- physionet-django/console/navbar.py | 1 + .../console/credentialing_stats.html | 4 +- physionet-django/console/urls.py | 3 + physionet-django/console/views.py | 167 ++++++++++++++++++ 4 files changed, 173 insertions(+), 2 deletions(-) diff --git a/physionet-django/console/navbar.py b/physionet-django/console/navbar.py index 60676f0335..fd04c64d39 100644 --- a/physionet-django/console/navbar.py +++ b/physionet-django/console/navbar.py @@ -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', [ diff --git a/physionet-django/console/templates/console/credentialing_stats.html b/physionet-django/console/templates/console/credentialing_stats.html index 6bac5bd7cd..154f5dd286 100644 --- a/physionet-django/console/templates/console/credentialing_stats.html +++ b/physionet-django/console/templates/console/credentialing_stats.html @@ -2,13 +2,13 @@ {% load static %} -{% block title %}Identity checks{% endblock %} +{% block title %}Credentialing metrics{% endblock %} {% block content %}
- Time to check identity + Credentialing metrics
diff --git a/physionet-django/console/urls.py b/physionet-django/console/urls.py index 59f93f1692..cbef9d01c2 100644 --- a/physionet-django/console/urls.py +++ b/physionet-django/console/urls.py @@ -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'), diff --git a/physionet-django/console/views.py b/physionet-django/console/views.py index 6e38b6f974..73de8e9d3d 100644 --- a/physionet-django/console/views.py +++ b/physionet-django/console/views.py @@ -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): """