def generic_report_csv_view(request, report_name): """ View to generate csv files from reports. """ # TODO: Determine the proper group names for the intersection of the # reports validate_user_is_in_group(request, ['staff', 'r&d']) # Find the report for the given name. report_class = genericreportclasses.find_report_class(report_name) if report_class is None: raise Http404 # Run the query for the report. report = report_class() series_range, aggregation = get_common_vars_for_charts(request) report_name_to_filter_values = parse_report_filter_values( request, [report]) report_data = report.get_data( series_range, aggregation, report_name_to_filter_values[report.name()]) # Convert the data into a CSV file. response = HttpResponse(content_type="text/csv") response["Content-Disposition"] = ( 'attachment; filename="%s.csv"' % report_name) writer = csv.writer(response) for row in report_data: writer.writerow(row) return response
def generic_heatmap_report_view(request, report_class_name): """ View to visualize Heatmaps. """ series_range, aggregation = get_common_vars_for_charts(request) report_class = genericreportclasses.find_report_class(report_class_name)() filter_values = {} return render_response( "heatmap.html", { "lat_longs": report_class.get_data( series_range, aggregation, filter_values), }, request)
def generic_report_view(request, menu_name, dropdown_option): series_range, aggregation = get_common_vars_for_charts(request) # Making sure at least the first option will always be selected if dropdown_option=='': dropdown_option = settings.TOP_MENU_OPTIONS[menu_name]\ ["menu_options"][0][0] # TODO: Determine the proper group names for the intersection of the # reports validate_user_is_in_group(request, ['staff', 'r&d']) # Find the report classes for this dropdown and create an instance of each # report. report_class_names = menu_builder.report_classes_for_menu_option( menu_name, dropdown_option) report_classes = [ genericreportclasses.find_report_class(report_class_name) for report_class_name in report_class_names] reports = [report_class() for report_class in report_classes] # Get a dictionary report_name_to_filter_values = parse_report_filter_values(request, reports) # Run the queries for each report. report_data = {} for report in reports: # If report is heatmap we dont get that data her but later on # when the heatmap view is called. Store the time it took to # run the query in the report object so it can display that information # if it wants. if not report.is_heatmap(): start_time = time.time() report_data[report.name()] = report.get_data( series_range, aggregation, report_name_to_filter_values[report.name()]) report.loading_time = time.time() - start_time # Generate the html for the charts. charts = render_chart_template( reports, report_data, request, report_name_to_filter_values) return render_response( "generic_chart.html", _add_common_context_params(request, series_range, aggregation, { 'url': reverse( "generic_report", kwargs=dict( menu_name=menu_name, dropdown_option=dropdown_option)), 'dropdown_option_key': dropdown_option, 'show_date_picker': any(report.show_date_picker() for report in reports), 'show_agg_widget': any(report.supports_aggregation() for report in reports), 'active_menu': menu_name, 'active_menu_option_info': _get_active_menu_option_info(menu_name, dropdown_option), 'charts': charts, }), request)