From 2b35f6244ed24d2e68841fd8574a05841e880f0f Mon Sep 17 00:00:00 2001 From: tdruez Date: Mon, 15 Jul 2024 17:28:14 +0400 Subject: [PATCH] Refactor fetch_results to remove duplication #138 Signed-off-by: tdruez --- dejacode_toolkit/scancodeio.py | 36 +++++++------------ product_portfolio/filters.py | 3 -- .../tabs/tab_dependencies.html | 10 +++--- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/dejacode_toolkit/scancodeio.py b/dejacode_toolkit/scancodeio.py index 3fec6b5d..5ce28dac 100644 --- a/dejacode_toolkit/scancodeio.py +++ b/dejacode_toolkit/scancodeio.py @@ -224,40 +224,30 @@ def update_from_scan(self, package, user): return updated_fields - def fetch_project_packages(self, project_uuid): - """Return the list of packages for the provided `project_uuid`.""" - project_packages_url = self.get_scan_action_url(project_uuid, "packages") - packages = [] + def fetch_results(self, api_url): + results = [] - next_url = project_packages_url + next_url = api_url while next_url: - logger.debug(f"{self.label}: fetch packages from project_packages_url={next_url}") + logger.debug(f"{self.label}: fetch results from api_url={next_url}") response = self.request_get(url=next_url) if not response: - raise Exception("Error fetching project packages") + raise Exception("Error fetching results") - packages.extend(response["results"]) + results.extend(response["results"]) next_url = response["next"] - return packages + return results + + def fetch_project_packages(self, project_uuid): + """Return the list of packages for the provided `project_uuid`.""" + api_url = self.get_scan_action_url(project_uuid, "packages") + return self.fetch_results(api_url) - # TODO: Remove duplication with fetch_project_packages def fetch_project_dependencies(self, project_uuid): """Return the list of dependencies for the provided `project_uuid`.""" api_url = self.get_scan_action_url(project_uuid, "dependencies") - dependencies = [] - - next_url = api_url - while next_url: - logger.debug(f"{self.label}: fetch dependencies from project_packages_url={next_url}") - response = self.request_get(url=next_url) - if not response: - raise Exception("Error fetching project dependencies") - - dependencies.extend(response["results"]) - next_url = response["next"] - - return dependencies + return self.fetch_results(api_url) # (label, scan_field, model_field, input_type) SCAN_SUMMARY_FIELDS = [ diff --git a/product_portfolio/filters.py b/product_portfolio/filters.py index f6ec7db5..53ca9341 100644 --- a/product_portfolio/filters.py +++ b/product_portfolio/filters.py @@ -333,9 +333,6 @@ class DependencyFilterSet(DataspacedFilterSet): "resolved_to_package__version", ], ) - is_deployment_path = BooleanChoiceFilter( - widget=DropDownWidget(anchor="#codebase"), - ) class Meta: model = ProductDependency diff --git a/product_portfolio/templates/product_portfolio/tabs/tab_dependencies.html b/product_portfolio/templates/product_portfolio/tabs/tab_dependencies.html index 610629e2..ab6452a0 100644 --- a/product_portfolio/templates/product_portfolio/tabs/tab_dependencies.html +++ b/product_portfolio/templates/product_portfolio/tabs/tab_dependencies.html @@ -51,9 +51,11 @@ {% for dependency in filter_dependency.qs %} - - {{ dependency.for_package }} - + {% if dependency.for_package %} + + {{ dependency.for_package }} + + {% endif %} {% if dependency.resolved_to_package %} @@ -63,7 +65,7 @@ {% endif %} - {{ dependency.scope }} + {{ dependency.scpe }} {{ dependency.is_runtime|as_icon }}