Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Multi Report recursion error #3714

Merged
merged 8 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rocky/reports/views/aggregate_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.shortcuts import redirect
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView

from reports.report_types.aggregate_organisation_report.report import AggregateOrganisationReport
from reports.report_types.helpers import get_ooi_types_from_aggregate_report
Expand Down Expand Up @@ -69,7 +70,7 @@ def get_context_data(self, **kwargs):


class ReportTypesSelectionAggregateReportView(
AggregateReportStepsMixin, BreadcrumbsAggregateReportView, ReportTypeSelectionView
AggregateReportStepsMixin, BreadcrumbsAggregateReportView, ReportTypeSelectionView, TemplateView
):
"""
Shows all possible report types from a list of Objects.
Expand Down
2 changes: 1 addition & 1 deletion rocky/reports/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def get_context_data(self, **kwargs):
return context


class ReportTypeSelectionView(BaseReportView, ReportBreadcrumbs, TemplateView):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TemplateView is removed, it clashes with ListView from the BaseOOILIst. use it in specific views where needed.

class ReportTypeSelectionView(BaseReportView, ReportBreadcrumbs):
"""
Shows report types and handles selections and requests.
"""
Expand Down
3 changes: 2 additions & 1 deletion rocky/reports/views/generate_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.shortcuts import redirect
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView

from reports.report_types.helpers import get_ooi_types_with_report
from reports.views.base import (
Expand Down Expand Up @@ -68,7 +69,7 @@ def get_context_data(self, **kwargs):


class ReportTypesSelectionGenerateReportView(
GenerateReportStepsMixin, BreadcrumbsGenerateReportView, ReportTypeSelectionView
GenerateReportStepsMixin, BreadcrumbsGenerateReportView, ReportTypeSelectionView, TemplateView
):
"""
Shows all possible report types from a list of OOIs.
Expand Down
28 changes: 4 additions & 24 deletions rocky/reports/views/multi_report.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime
from typing import Any

from django.contrib import messages
from django.http import HttpRequest, HttpResponse
from django.shortcuts import redirect
from django.urls import reverse
Expand Down Expand Up @@ -63,11 +62,6 @@ class OOISelectionMultiReportView(MultiReportStepsMixin, BreadcrumbsMultiReportV
current_step = 1
ooi_types = MultiOrganizationReport.input_ooi_types

def get(self, request, *args, **kwargs):
Copy link
Contributor Author

@Rieven Rieven Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed all get from MultiReport views as we use now post requests.

if not self.get_ooi_selection():
messages.error(request, self.NONE_OOI_SELECTION_MESSAGE)
return self.get(request, *args, **kwargs)


class ReportTypesSelectionMultiReportView(
MultiReportStepsMixin, BreadcrumbsMultiReportView, OOISelectionView, ReportTypeSelectionView
Expand All @@ -81,12 +75,7 @@ class ReportTypesSelectionMultiReportView(
breadcrumbs_step = 4
current_step = 2
report_type = MultiOrganizationReport

def get(self, request, *args, **kwargs):
if not self.get_ooi_selection():
messages.error(request, self.NONE_OOI_SELECTION_MESSAGE)
return redirect(self.get_previous())
return self.get(request, *args, **kwargs)
ooi_types = MultiOrganizationReport.input_ooi_types
Copy link
Contributor Author

@Rieven Rieven Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooi_types must be present otherwise when selecting all oois it will fetch all ooi types. We want specific ooi types stored in the report types. I have refactor this part in #3705 which is done more efficiently in a get function.



class SetupScanMultiReportView(MultiReportStepsMixin, BreadcrumbsMultiReportView, ReportPluginView):
Expand All @@ -97,11 +86,7 @@ class SetupScanMultiReportView(MultiReportStepsMixin, BreadcrumbsMultiReportView
template_name = "generate_report/setup_scan.html"
breadcrumbs_step = 5
current_step = 3

def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
if self.all_plugins_enabled():
return redirect(self.get_next())
return super().get(request, *args, **kwargs)
ooi_types = MultiOrganizationReport.input_ooi_types


class ExportSetupMultiReportView(MultiReportStepsMixin, BreadcrumbsMultiReportView, ReportFinalSettingsView):
Expand All @@ -113,13 +98,7 @@ class ExportSetupMultiReportView(MultiReportStepsMixin, BreadcrumbsMultiReportVi
breadcrumbs_step = 6
current_step = 4
report_type = MultiOrganizationReport

def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
if not self.get_report_type_ids():
messages.error(request, self.NONE_REPORT_TYPE_SELECTION_MESSAGE)
return redirect(self.get_previous())

return super().get(request, *args, **kwargs)
ooi_types = MultiOrganizationReport.input_ooi_types


class MultiReportView(BreadcrumbsMultiReportView, ReportPluginView):
Expand All @@ -129,6 +108,7 @@ class MultiReportView(BreadcrumbsMultiReportView, ReportPluginView):

template_name = "multi_report.html"
current_step = 5
ooi_types = MultiOrganizationReport.input_ooi_types

def multi_reports_for_oois(self) -> dict[str, dict[str, Any]]:
report = MultiOrganizationReport(self.octopoes_api_connector)
Expand Down