diff options
Diffstat (limited to 'lib/yp/views.py')
-rwxr-xr-x | lib/yp/views.py | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/lib/yp/views.py b/lib/yp/views.py index 2d6d0043..3310e7e6 100755 --- a/lib/yp/views.py +++ b/lib/yp/views.py @@ -4,7 +4,7 @@ # # Security Response Tool Implementation # -# Copyright (C) 2017-2018 Wind River Systems +# Copyright (C) 2017-2020 Wind River Systems # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -21,9 +21,13 @@ #from django.urls import reverse_lazy #from django.views import generic -#from django.http import HttpResponse, HttpResponseNotFound, JsonResponse, HttpResponseRedirect +from django.http import HttpResponse, HttpResponseNotFound, JsonResponse, HttpResponseRedirect from django.shortcuts import render, redirect +from users.models import SrtUser, UserSafe +from srtgui.views import MimeTypeFinder +from yp.reports import YPReportManager + #from orm.models import SrtSetting # quick development/debugging support @@ -33,3 +37,47 @@ def yp_hello(request): context = {} _log("Note:yp_hello") return render(request, 'yp_hello.html', context) + +def report(request,page_name): + if request.method == "GET": + context = YPReportManager.get_context_data(page_name,request=request) + record_list = request.GET.get('record_list', '') + _log("EXPORT_GET!:%s|%s|" % (request,record_list)) + context['record_list'] = record_list + return render(request, 'report.html', context) + elif request.method == "POST": + _log("EXPORT_POST!:%s|%s" % (request,request.FILES)) + parent_page = request.POST.get('parent_page', '') + file_name,response_file_name = YPReportManager.exec_report(parent_page,request=request) + + if file_name.startswith("Error"): + # Refresh the page with the error message + context = YPReportManager.get_context_data(page_name,request=request) + context['error_message'] = file_name + record_list = request.GET.get('record_list', '') + _log("EXPORT_GET_WITH_ERROR!:%s|%s|" % (request,record_list)) + context['record_list'] = record_list + return render(request, 'report.html', context) + elif file_name and response_file_name: + fsock = open(file_name, "rb") + content_type = MimeTypeFinder.get_mimetype(file_name) + + response = HttpResponse(fsock, content_type = content_type) + + disposition = "attachment; filename=" + response_file_name + response["Content-Disposition"] = disposition + + _log("EXPORT_POST_Q{%s|" % (response)) + return response + else: + return render(request, "unavailable_artifact.html", {}) + + return redirect('/') + raise Exception("Invalid HTTP method for this page") + +def manage_report(request): + # does this user have permission to see this record? + if not UserSafe.is_creator(request.user): + return redirect('/') + + return redirect(report,'management') |