mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 05:29:38 -04:00
Merge pull request #2951 from alphagov/performance-platform-xlsx
Provide Performance Platform report as Excel file
This commit is contained in:
@@ -239,10 +239,10 @@ def live_services_csv():
|
||||
}
|
||||
|
||||
|
||||
@main.route("/platform-admin/reports/performance-platform.csv")
|
||||
@main.route("/platform-admin/reports/performance-platform.xlsx")
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def performance_platform_csv():
|
||||
def performance_platform_xlsx():
|
||||
results = service_api_client.get_live_services_data()["data"]
|
||||
live_services_columns = ["service_id", "agency", "service_name", "_timestamp", "service", "count"]
|
||||
live_services_data = []
|
||||
@@ -259,9 +259,9 @@ def performance_platform_csv():
|
||||
1
|
||||
])
|
||||
|
||||
return Spreadsheet.from_rows(live_services_data).as_csv_data, 200, {
|
||||
'Content-Type': 'text/csv; charset=utf-8',
|
||||
'Content-Disposition': 'inline; filename="{} performance platform report.csv"'.format(
|
||||
return Spreadsheet.from_rows(live_services_data).as_excel_file, 200, {
|
||||
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'Content-Disposition': 'attachment; filename="{} performance platform report.xlsx"'.format(
|
||||
format_date_numeric(datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%fZ")),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class HeaderNavigation(Navigation):
|
||||
'live_services',
|
||||
'live_services_csv',
|
||||
'organisations',
|
||||
'performance_platform_csv',
|
||||
'performance_platform_xlsx',
|
||||
'platform_admin',
|
||||
'platform_admin_letter_validation_preview',
|
||||
'platform_admin_list_complaints',
|
||||
@@ -496,7 +496,7 @@ class MainNavigation(Navigation):
|
||||
'organisation_preview_letter_branding',
|
||||
'organisation_settings',
|
||||
'organisations',
|
||||
'performance_platform_csv',
|
||||
'performance_platform_xlsx',
|
||||
'platform_admin',
|
||||
'platform_admin_letter_validation_preview',
|
||||
'platform_admin_list_complaints',
|
||||
@@ -713,7 +713,7 @@ class CaseworkNavigation(Navigation):
|
||||
'organisation_preview_letter_branding',
|
||||
'organisation_settings',
|
||||
'organisations',
|
||||
'performance_platform_csv',
|
||||
'performance_platform_xlsx',
|
||||
'platform_admin_letter_validation_preview',
|
||||
'platform_admin_list_complaints',
|
||||
'platform_admin_reports',
|
||||
@@ -970,7 +970,7 @@ class OrgNavigation(Navigation):
|
||||
'old_terms',
|
||||
'old_using_notify',
|
||||
'organisations',
|
||||
'performance_platform_csv',
|
||||
'performance_platform_xlsx',
|
||||
'platform_admin',
|
||||
'platform_admin_letter_validation_preview',
|
||||
'platform_admin_list_complaints',
|
||||
|
||||
@@ -15,6 +15,6 @@
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a target="_blank" href="{{ url_for('main.performance_platform_csv') }}">Download performance platform csv report</a>
|
||||
<a target="_blank" href="{{ url_for('main.performance_platform_xlsx') }}">Download performance platform report (.xlsx)</a>
|
||||
<p>
|
||||
{% endblock %}
|
||||
|
||||
17
app/utils.py
17
app/utils.py
@@ -4,7 +4,7 @@ import re
|
||||
import unicodedata
|
||||
from datetime import datetime, time, timedelta, timezone
|
||||
from functools import wraps
|
||||
from io import StringIO
|
||||
from io import BytesIO, StringIO
|
||||
from itertools import chain
|
||||
from os import path
|
||||
from urllib.parse import urlparse
|
||||
@@ -12,6 +12,7 @@ from urllib.parse import urlparse
|
||||
import ago
|
||||
import dateutil
|
||||
import pyexcel
|
||||
import pyexcel_xlsx
|
||||
import yaml
|
||||
from flask import abort, current_app, redirect, request, session, url_for
|
||||
from flask_login import current_user
|
||||
@@ -278,6 +279,20 @@ class Spreadsheet():
|
||||
pyexcel.free_resources()
|
||||
return instance
|
||||
|
||||
@property
|
||||
def as_rows(self):
|
||||
return list(csv.reader(
|
||||
self.as_csv_data.strip().splitlines(),
|
||||
quoting=csv.QUOTE_MINIMAL,
|
||||
skipinitialspace=True,
|
||||
))
|
||||
|
||||
@property
|
||||
def as_excel_file(self):
|
||||
io = BytesIO()
|
||||
pyexcel_xlsx.save_data(io, {'Sheet 1': self.as_rows})
|
||||
return io.getvalue()
|
||||
|
||||
|
||||
def get_help_argument():
|
||||
return request.args.get('help') if request.args.get('help') in ('1', '2', '3') else None
|
||||
|
||||
Reference in New Issue
Block a user