Skip to content

Commit

Permalink
Merge branch 'feature/report-recipe' of github.com:minvws/nl-kat-coor…
Browse files Browse the repository at this point in the history
…dination into feature/schedule-report
  • Loading branch information
Rieven committed Sep 11, 2024
2 parents 780870e + 881aac8 commit a59d07b
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 239 deletions.
13 changes: 8 additions & 5 deletions rocky/reports/report_types/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

CONCATENATED_REPORTS = [ConcatenatedReport]

ALL_REPORT_TYPES = REPORTS + AGGREGATE_REPORTS + MULTI_REPORTS + CONCATENATED_REPORTS


def get_ooi_types_with_report() -> set[type[OOI]]:
"""
Expand All @@ -53,20 +55,21 @@ def get_report_types_for_ooi(ooi_pk: str) -> list[type[Report]]:
return [report for report in REPORTS if ooi_type in report.input_ooi_types]


def get_report_types_for_oois(ooi_pks: list[str]) -> set[type[Report]]:
def get_report_types_for_oois(oois: list[str]) -> set[type[Report]]:
"""
Get all report types that can be generated for a given list of OOIs
"""
return {report for ooi_pk in ooi_pks for report in get_report_types_for_ooi(ooi_pk)}

return {report for ooi_pk in oois for report in get_report_types_for_ooi(ooi_pk)}


def get_report_by_id(report_id: str) -> type[Report] | type[MultiReport] | type[AggregateReport]:
def get_report_by_id(report_id: str) -> type[Report]:
"""
Get report type by id
"""
if report_id is None:
if not report_id:
return ConcatenatedReport
for report in REPORTS + MULTI_REPORTS + AGGREGATE_REPORTS + CONCATENATED_REPORTS:
for report in ALL_REPORT_TYPES:
if report.id == report_id:
return report
raise ValueError(f"Report with id {report_id} not found")
Expand Down
14 changes: 8 additions & 6 deletions rocky/reports/templates/forms/report_form_fields.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<input type="hidden"
name="observed_at"
value="{{ observed_at|date:"Y-m-d" }}">
{% for ooi in selected_oois %}<input type="hidden" name="ooi" value="{{ ooi }}">{% endfor %}
{% if report_recipe.input_oois and not disable_ooi_selection_fields %}
{% for ooi in report_recipe.input_oois %}<input type="hidden" name="ooi" value="{{ ooi }}">{% endfor %}
{% endif %}
{% for ooi_type in ooi_types_selection %}<input type="hidden" name="ooi_type" value="{{ ooi_type }}">{% endfor %}
{% for clearance_level in clearance_levels_selection %}
<input type="hidden" name="clearance_level" value="{{ clearance_level }}">
{% endfor %}
{% for clearance_type in clearance_types_selection %}
<input type="hidden" name="clearance_type" value="{{ clearance_type }}">
{% endfor %}
{% if selected_report_types %}
{% for report_type in selected_report_types %}
{% if report_recipe.report_types and not disable_report_type_fields %}
{% for report_type in report_recipe.report_types %}
<input type="hidden" name="report_type" value="{{ report_type }}">
{% endfor %}
{% endif %}
{% if plugins.required %}
{% for required_plugin in plugins.required %}
<input type="hidden" name="plugin" value="{{ required_plugin.id }}">
{% if report_recipe.plugins.required and not disable_plugin_fields %}
{% for required_plugin in report_recipe.plugins.required %}
<input type="hidden" name="plugin" value="{{ required_plugin }}">
{% endfor %}
{% endif %}
{% if request.GET.page %}<input type="hidden" name="page" value="{{ request.GET.page }}">{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<section>
<div>
{% if selected_oois and selected_report_types %}
{% if report_recipe.input_oois and report_recipe.report_types %}
<h2>{% translate "Report schedule" %}</h2>
<p>
{% blocktranslate trimmed %}
Expand Down
4 changes: 2 additions & 2 deletions rocky/reports/templates/partials/report_ooi_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h2>
{% include "forms/report_form_fields.html" %}

{% else %}
{% include "forms/report_form_fields.html" with selected_oois=None %}
{% include "forms/report_form_fields.html" with disable_ooi_selection_fields=True %}

{% endif %}
<table>
Expand Down Expand Up @@ -104,7 +104,7 @@ <h2>
</div>
</section>
<form novalidate id="select_all_objects_form" class="inline" method="get">
{% include "forms/report_form_fields.html" with selected_oois=None %}
{% include "forms/report_form_fields.html" with disable_ooi_selection_fields=True %}

{% if "all" not in selected_oois %}<input type="hidden" name="ooi" value="all">{% endif %}
</form>
26 changes: 14 additions & 12 deletions rocky/reports/templates/partials/report_setup_scan.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div>
<h2>{% translate "Configuration" %}</h2>
<p class="emphasized">{% translate "Set up the required plugins for this report." %}</p>
{% if selected_oois and selected_report_types %}
{% if report_recipe.input_oois and report_recipe.report_types %}
{% include "partials/return_button.html" with btn_text="Change selection" %}
{% include "partials/plugin_overview_table.html" %}

Expand Down Expand Up @@ -37,10 +37,10 @@ <h2>{% translate "Plugins" %}</h2>
{% endblocktranslate %}
</p>
<h3>{% translate "Required plugins" %}</h3>
<p>{% translate "This report type requires the following plugins to be enabled:" %}</p>
{% if all_plugins_enabled.required %}
{% if enabled_plugins.required %}
<p>{% translate "Good job! All required plugins are enabled." %}</p>
{% else %}
{% elif report_recipe.plugins.required %}
<p>{% translate "This report type requires the following plugins to be enabled:" %}</p>
<div class="required-plugin-container">
<div class="toolbar">
<div class="checkbox">
Expand All @@ -57,14 +57,16 @@ <h3>{% translate "Required plugins" %}</h3>
{% endfor %}
</div>
</div>
{% else %}
<p>{% translate "There are no required plugins." %}</p>
{% endif %}
<h3>{% translate "Suggested plugins" %}</h3>
<p>
{% translate "This report requires at least one of the following plugins to be enabled to generate the report:" %}
</p>
{% if all_plugins_enabled.optional %}
{% if enabled_plugins.optional %}
<p>{% translate "Good job! All suggested plugins are enabled" %}</p>
{% else %}
{% elif report_recipe.plugins.optional %}
<p>
{% translate "This report requires at least one of the following plugins to be enabled to generate the report:" %}
</p>
<div class="optional-plugin-container hide-overflow">
<div class="toolbar">
<div class="checkbox">
Expand All @@ -76,10 +78,8 @@ <h3>{% translate "Suggested plugins" %}</h3>
</div>
<div class="column-4 tiles plugins images-cover">
{% for optional_plugin in plugins.optional|dictsort:"enabled" %}
{% if optional_plugin not in plugins.required %}
{% include "partials/plugin_tile.html" with plugin=optional_plugin form_id="continue-to-configurationt" show_report_types="yes" plugin_report_types=plugin_data.plugin_report_types %}
{% include "partials/plugin_tile.html" with plugin=optional_plugin form_id="continue-to-configurationt" show_report_types="yes" plugin_report_types=plugin_data.plugin_report_types %}

{% endif %}
{% endfor %}
</div>
<div class="toolbar">
Expand All @@ -89,6 +89,8 @@ <h3>{% translate "Suggested plugins" %}</h3>
data-show-text="{% translate "Show more suggested plugins" %}"></button>
</div>
</div>
{% else %}
<p>{% translate "There are no optional plugins." %}</p>
{% endif %}
<form id="continue-to-configuration"
class="inline"
Expand Down
8 changes: 2 additions & 6 deletions rocky/reports/templates/partials/report_types_selection.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,15 @@ <h2>
<span class="icon ti-chevron-left"></span>{% translate "Change selection" %}
</button>
</form>
{% if available_report_types_aggregate %}
<h2>{% translate "Available report types" %} ({{ count_available_report_types_aggregate }})</h2>
{% else %}
<h2>{% translate "Available report types" %} ({{ available_report_types|length }})</h2>
{% endif %}
<h2>{% translate "Available report types" %} ({{ count_available_report_types }})</h2>
<p>{% translate "All report types that are available for your selection." %}</p>
<a class="toggle-all {% if all_report_types_checked %}toggle-on{% endif %}"
data-toggle-target="report_type">{% translate "Toggle all report types" %}</a>
<form class="inline layout-wide checkboxes_required"
method="post"
action="{{ next }}">
{% csrf_token %}
{% include "forms/report_form_fields.html" with selected_report_types=None %}
{% include "forms/report_form_fields.html" with disable_report_type_fields=True %}

<div class="column-4 tiles">
{% if available_report_types_aggregate %}
Expand Down
2 changes: 1 addition & 1 deletion rocky/reports/templates/partials/report_types_tiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<input type="checkbox"
name="report_type"
value="{{ report_type.id }}"
{% if report_type.id in selected_report_types %}checked{% endif %} />
{% if report_type.id in report_recipe.report_types %}checked{% endif %} />
</p>
<p class="tile-description">{{ report_type.description }}</p>
</div>
Expand Down
59 changes: 17 additions & 42 deletions rocky/reports/views/aggregate_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
from django.urls import reverse
from django.utils.http import urlencode
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView
from tools.view_helpers import PostRedirect

from reports.report_types.aggregate_organisation_report.report import AggregateOrganisationReport
from reports.report_types.definitions import AggregateReport, MultiReport, Report
from reports.report_types.helpers import get_ooi_types_from_aggregate_report, get_report_types_from_aggregate_report
from reports.report_types.definitions import Report
from reports.report_types.helpers import get_ooi_types_from_aggregate_report
from reports.views.base import (
REPORTS_PRE_SELECTION,
OOISelectionView,
Expand Down Expand Up @@ -84,7 +85,8 @@ class OOISelectionAggregateReportView(
ooi_types = get_ooi_types_from_aggregate_report(AggregateOrganisationReport)

def post(self, request, *args, **kwargs):
if not self.selected_oois:
report_recipe = self.get_report_recipe()
if not report_recipe.input_oois:
messages.error(request, self.NONE_OOI_SELECTION_MESSAGE)
return self.get(request, *args, **kwargs)

Expand All @@ -95,10 +97,7 @@ def get_context_data(self, **kwargs):


class ReportTypesSelectionAggregateReportView(
AggregateReportStepsMixin,
BreadcrumbsAggregateReportView,
OOISelectionView,
ReportTypeSelectionView,
AggregateReportStepsMixin, BreadcrumbsAggregateReportView, OOISelectionView, ReportTypeSelectionView, TemplateView
):
"""
Shows all possible report types from a list of Objects.
Expand All @@ -108,44 +107,19 @@ class ReportTypesSelectionAggregateReportView(
template_name = "aggregate_report/select_report_types.html"
breadcrumbs_step = 4
current_step = 2
ooi_types = get_ooi_types_from_aggregate_report(AggregateOrganisationReport)

def setup(self, request, *args, **kwargs):
super().setup(request, *args, **kwargs)
self.available_report_types = self.get_report_types_for_aggregate_report(
get_report_types_from_aggregate_report(AggregateOrganisationReport)
)
report_type = AggregateOrganisationReport
ooi_types = get_ooi_types_from_aggregate_report(report_type)

def post(self, request, *args, **kwargs):
if not self.selected_oois:
report_recipe = self.get_report_recipe()
if not report_recipe.input_oois:
messages.error(request, self.NONE_OOI_SELECTION_MESSAGE)
return PostRedirect(self.get_previous())
return self.get(request, *args, **kwargs)

def get_report_types_for_aggregate_report(
self, reports_dict: dict[str, set[type[Report]]]
) -> dict[str, list[dict[str, str]]]:
report_types = {}
for option, reports in reports_dict.items():
report_types[option] = self.get_report_types(reports)
return report_types

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["available_report_types_aggregate"] = self.available_report_types

context["count_available_report_types_aggregate"] = len(self.available_report_types["required"]) + len(
self.available_report_types["optional"]
)
context["all_report_types_checked"] = (
len(self.get_report_type_selection()) == context["count_available_report_types_aggregate"]
)
context["total_oois"] = self.get_total_objects()
return context


class SetupScanAggregateReportView(
SaveAggregateReportMixin, AggregateReportStepsMixin, BreadcrumbsAggregateReportView, ReportPluginView
SaveAggregateReportMixin, AggregateReportStepsMixin, BreadcrumbsAggregateReportView, ReportPluginView, TemplateView
):
"""
Show required and optional plugins to start scans to generate OOIs to include in report.
Expand All @@ -156,8 +130,7 @@ class SetupScanAggregateReportView(
current_step = 3

def post(self, request, *args, **kwargs):
# If the user wants to change selection, but all plugins are enabled, it needs to go even further back
if not self.selected_report_types:
if not self.report_recipe.report_types:
messages.error(request, self.NONE_REPORT_TYPE_SELECTION_MESSAGE)
return PostRedirect(self.get_previous())

Expand All @@ -170,7 +143,9 @@ def post(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)


class ExportSetupAggregateReportView(AggregateReportStepsMixin, BreadcrumbsAggregateReportView, ReportPluginView):
class ExportSetupAggregateReportView(
AggregateReportStepsMixin, BreadcrumbsAggregateReportView, ReportPluginView, TemplateView
):
"""
Shows the export setup page where users can set their export preferences.
"""
Expand All @@ -180,7 +155,7 @@ class ExportSetupAggregateReportView(AggregateReportStepsMixin, BreadcrumbsAggre
current_step = 4

def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
if not self.selected_report_types:
if not self.report_recipe.report_types:
messages.error(request, self.NONE_REPORT_TYPE_SELECTION_MESSAGE)
return PostRedirect(self.get_previous())
return super().get(request, *args, **kwargs)
Expand All @@ -201,7 +176,7 @@ class SaveAggregateReportView(SaveAggregateReportMixin, BreadcrumbsAggregateRepo
breadcrumbs_step = 6
current_step = 6
ooi_types = get_ooi_types_from_aggregate_report(AggregateOrganisationReport)
report_types: list[type[Report] | type[MultiReport] | type[AggregateReport]]
report_types: list[type[Report]]

def post(self, request, *args, **kwargs):
old_report_names = request.POST.getlist("old_report_name")
Expand Down
Loading

0 comments on commit a59d07b

Please sign in to comment.