def platform_admin_list_complaints(): page = get_page_from_request() if page is None: abort(404, "Invalid page argument ({}).".format(request.args.get('page'))) response = complaint_api_client.get_all_complaints(page=page) prev_page = None if response['links'].get('prev'): prev_page = generate_previous_dict( 'main.platform_admin_list_complaints', None, page) next_page = None if response['links'].get('next'): next_page = generate_next_dict('main.platform_admin_list_complaints', None, page) return render_template( 'views/platform-admin/complaints.html', complaints=response['complaints'], page_title='All Complaints', page=page, prev_page=prev_page, next_page=next_page, )
def platform_admin_callback_failures(): page = get_page_from_request() if page is None: abort(404, "Invalid page argument ({}).".format(request.args.get('page'))) response = callback_failures_client.get_failing_callbacks(page=page) prev_page = None if response['links'].get('prev'): prev_page = generate_previous_dict( 'main.platform_admin_callback_failures', None, page) next_page = None if response['links'].get('next'): next_page = generate_next_dict('main.platform_admin_callback_failures', None, page) return render_template( 'views/platform-admin/callback_failures.html', callback_failures=response['callbacks'], page_title='Callback failures', page=page, prev_page=prev_page, next_page=next_page, )
def uploaded_letters(service_id, letter_print_day): page = get_page_from_request() if page is None: abort(404, "Invalid page argument ({}).".format(request.args.get('page'))) uploaded_letters = upload_api_client.get_letters_by_service_and_print_day( current_service.id, letter_print_day=letter_print_day, page=page, ) prev_page = None if uploaded_letters['links'].get('prev'): prev_page = generate_previous_dict( '.uploaded_letters', service_id, page, url_args={'letter_print_day': letter_print_day}) next_page = None if uploaded_letters['links'].get('next'): next_page = generate_next_dict( '.uploaded_letters', service_id, page, url_args={'letter_print_day': letter_print_day}) return render_template( 'views/uploads/uploaded-letters.html', notifications=add_preview_of_content_uploaded_letters( uploaded_letters['notifications']), prev_page=prev_page, next_page=next_page, show_pagination=True, total=uploaded_letters['total'], letter_printing_statement=get_letter_printing_statement( 'created', letter_print_day, ), letter_print_day=letter_print_day, single_notification_url=partial( url_for, '.view_notification', service_id=current_service.id, from_uploaded_letters=letter_print_day, ))
def platform_admin_list_complaints(): page = get_page_from_request() if page is None: abort(404, "Invalid page argument ({}).".format(request.args.get("page"))) response = complaint_api_client.get_all_complaints(page=page) prev_page = None if response["links"].get("prev"): prev_page = generate_previous_dict("main.platform_admin_list_complaints", None, page) next_page = None if response["links"].get("next"): next_page = generate_next_dict("main.platform_admin_list_complaints", None, page) return render_template( "views/platform-admin/complaints.html", complaints=response["complaints"], page_title="All Complaints", page=page, prev_page=prev_page, next_page=next_page, )
def get_notifications(service_id, message_type, status_override=None): # TODO get the api to return count of pages as well. page = get_page_from_request() if page is None: abort(404, "Invalid page argument ({}).".format(request.args.get('page'))) filter_args = parse_filter_args(request.args) filter_args['status'] = set_status_filters(filter_args) service_data_retention_days = None if message_type is not None: service_data_retention_days = current_service.get_days_of_retention( message_type) if request.path.endswith('csv') and current_user.has_permissions( 'view_activity'): return Response(generate_notifications_csv( service_id=service_id, page=page, page_size=5000, template_type=[message_type], status=filter_args.get('status'), limit_days=service_data_retention_days), mimetype='text/csv', headers={ 'Content-Disposition': 'inline; filename="notifications.csv"' }) notifications = notification_api_client.get_notifications_for_service( service_id=service_id, page=page, template_type=[message_type] if message_type else [], status=filter_args.get('status'), limit_days=service_data_retention_days, to=request.form.get('to', ''), ) url_args = { 'message_type': message_type, 'status': request.args.get('status') } prev_page = None if 'links' in notifications and notifications['links'].get('prev', None): prev_page = generate_previous_dict('main.view_notifications', service_id, page, url_args=url_args) next_page = None if 'links' in notifications and notifications['links'].get('next', None): next_page = generate_next_dict('main.view_notifications', service_id, page, url_args) if message_type: download_link = url_for('.view_notifications_csv', service_id=current_service.id, message_type=message_type, status=request.args.get('status')) else: download_link = None return { 'service_data_retention_days': service_data_retention_days, 'counts': render_template('views/activity/counts.html', status=request.args.get('status'), status_filters=get_status_filters( current_service, message_type, service_api_client.get_service_statistics( service_id, today_only=False, limit_days=service_data_retention_days))), 'notifications': render_template( 'views/activity/notifications.html', notifications=list( add_preview_of_content_to_notifications( notifications['notifications'])), page=page, limit_days=service_data_retention_days, prev_page=prev_page, next_page=next_page, status=request.args.get('status'), message_type=message_type, download_link=download_link, ), }
def get_notifications(service_id, message_type, status_override=None): # TODO get the api to return count of pages as well. page = get_page_from_request() if page is None: abort( 404, "Invalid page argument ({}) reverting to page 1.".format( request.args['page'], None)) if message_type not in ['email', 'sms', 'letter']: abort(404) filter_args = parse_filter_args(request.args) filter_args['status'] = set_status_filters(filter_args) if request.path.endswith('csv'): return Response(generate_notifications_csv( service_id=service_id, page=page, page_size=5000, template_type=[message_type], status=filter_args.get('status'), limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS']), mimetype='text/csv', headers={ 'Content-Disposition': 'inline; filename="notifications.csv"' }) notifications = notification_api_client.get_notifications_for_service( service_id=service_id, page=page, template_type=[message_type], status=filter_args.get('status'), limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS'], to=request.form.get('to', ''), ) url_args = { 'message_type': message_type, 'status': request.args.get('status') } prev_page = None if 'links' in notifications and notifications['links'].get('prev', None): prev_page = generate_previous_dict('main.view_notifications', service_id, page, url_args=url_args) next_page = None if 'links' in notifications and notifications['links'].get('next', None): next_page = generate_next_dict('main.view_notifications', service_id, page, url_args) return { 'counts': render_template('views/activity/counts.html', status=request.args.get('status'), status_filters=get_status_filters( current_service, message_type, service_api_client.get_detailed_service(service_id) ['data']['statistics'])), 'notifications': render_template('views/activity/notifications.html', notifications=list( add_preview_of_content_to_notifications( notifications['notifications'])), page=page, prev_page=prev_page, next_page=next_page, status=request.args.get('status'), message_type=message_type, download_link=url_for( '.view_notifications_csv', service_id=current_service['id'], message_type=message_type, status=request.args.get('status'))), }
def view_notifications(service_id, message_type): # TODO get the api to return count of pages as well. page = get_page_from_request() if page is None: abort(404, "Invalid page argument ({}) reverting to page 1.".format(request.args['page'], None)) if message_type not in ['email', 'sms']: abort(404) filter_args = _parse_filter_args(request.args) filter_args['status'] = _set_status_filters(filter_args) notifications = notification_api_client.get_notifications_for_service( service_id=service_id, page=page, template_type=[message_type], status=filter_args.get('status'), limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS']) view_dict = dict( message_type=message_type, status=request.args.get('status') ) prev_page = None if notifications['links'].get('prev', None): prev_page = generate_previous_next_dict( 'main.view_notifications', service_id, view_dict, page - 1, 'Previous page', 'page {}'.format(page - 1)) next_page = None if notifications['links'].get('next', None): next_page = generate_previous_next_dict( 'main.view_notifications', service_id, view_dict, page + 1, 'Next page', 'page {}'.format(page + 1)) if request.path.endswith('csv'): csv_content = generate_notifications_csv( notification_api_client.get_notifications_for_service( service_id=service_id, page=page, page_size=notifications['total'], template_type=[message_type], status=filter_args.get('status'), limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS'])['notifications']) return csv_content, 200, { 'Content-Type': 'text/csv; charset=utf-8', 'Content-Disposition': 'inline; filename="notifications.csv"' } return render_template( 'views/notifications.html', notifications=notifications['notifications'], page=page, prev_page=prev_page, next_page=next_page, status=request.args.get('status'), message_type=message_type, download_link=url_for( '.view_notifications_csv', service_id=current_service['id'], message_type=message_type, status=request.args.get('status') ), status_filters=get_status_filters( current_service, message_type, service_api_client.get_detailed_service(service_id)['data']['statistics'] ) )
def get_notifications(service_id, message_type, status_override=None): # TODO get the api to return count of pages as well. page = get_page_from_request() if page is None: abort(404, "Invalid page argument ({}).".format(request.args.get("page"))) if message_type not in ["email", "sms", "letter", None]: abort(404) filter_args = parse_filter_args(request.args) filter_args["status"] = set_status_filters(filter_args) service_data_retention_days = current_app.config.get( "ACTIVITY_STATS_LIMIT_DAYS", None) if message_type is not None: service_data_retention_days = current_service.get_days_of_retention( message_type) if request.path.endswith("csv") and current_user.has_permissions( "view_activity"): return Response( generate_notifications_csv( service_id=service_id, page=page, page_size=5000, template_type=[message_type], status=filter_args.get("status"), limit_days=service_data_retention_days, ), mimetype="text/csv", headers={ "Content-Disposition": 'inline; filename="notifications.csv"' }, ) notifications = notification_api_client.get_notifications_for_service( service_id=service_id, page=page, template_type=[message_type] if message_type else [], status=filter_args.get("status"), limit_days=service_data_retention_days, to=request.form.get("to", ""), ) url_args = { "message_type": message_type, "status": request.args.get("status") } prev_page = None if "links" in notifications and notifications["links"].get("prev", None): prev_page = generate_previous_dict("main.view_notifications", service_id, page, url_args=url_args) next_page = None if "links" in notifications and notifications["links"].get("next", None): next_page = generate_next_dict("main.view_notifications", service_id, page, url_args) if message_type: download_link = url_for( ".view_notifications_csv", service_id=current_service.id, message_type=message_type, status=request.args.get("status"), ) else: download_link = None return { "service_data_retention_days": service_data_retention_days, "counts": render_template( "views/activity/counts.html", status=request.args.get("status"), status_filters=get_status_filters( current_service, message_type, service_api_client.get_service_statistics( service_id, today_only=False, limit_days=service_data_retention_days), ), ), "notifications": render_template( "views/activity/notifications.html", notifications=list( add_preview_of_content_to_notifications( notifications["notifications"])), page=page, limit_days=service_data_retention_days, prev_page=prev_page, next_page=next_page, status=request.args.get("status"), message_type=message_type, download_link=download_link, ), }
def get_notifications(service_id, message_type, status_override=None): # TODO get the api to return count of pages as well. page = get_page_from_request() if page is None: abort(404, "Invalid page argument ({}) reverting to page 1.".format(request.args["page"], None)) if message_type not in ["email", "sms"]: abort(404) filter_args = _parse_filter_args(request.args) filter_args["status"] = _set_status_filters(filter_args) notifications = notification_api_client.get_notifications_for_service( service_id=service_id, page=page, template_type=[message_type], status=filter_args.get("status"), limit_days=current_app.config["ACTIVITY_STATS_LIMIT_DAYS"], ) url_args = {"message_type": message_type, "status": request.args.get("status")} prev_page = None if notifications["links"].get("prev", None): prev_page = generate_previous_dict("main.view_notifications", service_id, page, url_args=url_args) next_page = None if notifications["links"].get("next", None): next_page = generate_next_dict("main.view_notifications", service_id, page, url_args) if request.path.endswith("csv"): csv_content = generate_notifications_csv( notification_api_client.get_notifications_for_service( service_id=service_id, page=page, page_size=notifications["total"], template_type=[message_type], status=filter_args.get("status"), limit_days=current_app.config["ACTIVITY_STATS_LIMIT_DAYS"], )["notifications"] ) return ( csv_content, 200, {"Content-Type": "text/csv; charset=utf-8", "Content-Disposition": 'inline; filename="notifications.csv"'}, ) return { "counts": render_template( "views/activity/counts.html", status=request.args.get("status"), status_filters=get_status_filters( current_service, message_type, service_api_client.get_detailed_service(service_id)["data"]["statistics"] ), ), "notifications": render_template( "views/activity/notifications.html", notifications=notifications["notifications"], page=page, prev_page=prev_page, next_page=next_page, status=request.args.get("status"), message_type=message_type, download_link=url_for( ".view_notifications_csv", service_id=current_service["id"], message_type=message_type, status=request.args.get("status"), ), ), }