Skip to content

Commit

Permalink
Add SCANCODEIO_PAGINATE_BY setting to customize pagination counts` #563
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <[email protected]>
  • Loading branch information
tdruez committed Mar 14, 2023
1 parent b3d4564 commit d5ba13e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ v33.0.0 (unreleased)
with current Project/CodebaseResource path scheme.
https://github.com/nexB/scancode.io/pull/624

- Add ``SCANCODEIO_PAGINATE_BY`` setting to customize the number of items displayed per
page for each object type.
https://github.com/nexB/scancode.io/issues/563

v32.0.1 (2023-02-20)
--------------------

Expand Down
8 changes: 8 additions & 0 deletions docs/scancodeio-settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ A valid policies file is required to enable compliance-related features.
Check out the :ref:`tutorial_license_policies` tutorial for in-depth coverage of
this feature.

SCANCODEIO_PAGINATE_BY
----------------------

The number of objects display per page for each object type can be customized with the
following setting::

SCANCODEIO_PAGINATE_BY=project=30,error=50,resource=100,package=100,dependency=100

SCANCODEIO_REST_API_PAGE_SIZE
-----------------------------

Expand Down
13 changes: 13 additions & 0 deletions scancodeio/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@
# Default to 24 hours.
SCANCODEIO_TASK_TIMEOUT = env.int("SCANCODEIO_TASK_TIMEOUT", default=86400)

# List views pagination, controls the number of items displayed per page.
# Syntax in .env: SCANCODEIO_PAGINATE_BY=project=10,project_error=10
SCANCODEIO_PAGINATE_BY = env.dict(
"SCANCODEIO_PAGINATE_BY",
default={
"project": 20,
"error": 50,
"resource": 100,
"package": 100,
"dependency": 100,
},
)

# Default limit for "most common" entries in QuerySets.
SCANCODEIO_MOST_COMMON_LIMIT = env.int("SCANCODEIO_MOST_COMMON_LIMIT", default=7)

Expand Down
10 changes: 5 additions & 5 deletions scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class ProjectListView(
filterset_class = ProjectFilterSet
template_name = "scanpipe/project_list.html"
prefetch_related = ["runs"]
paginate_by = 20
paginate_by = settings.SCANCODEIO_PAGINATE_BY.get("project", 20)
table_columns = [
"name",
{
Expand Down Expand Up @@ -847,7 +847,7 @@ class CodebaseResourceListView(
model = CodebaseResource
filterset_class = ResourceFilterSet
template_name = "scanpipe/resource_list.html"
paginate_by = 100
paginate_by = settings.SCANCODEIO_PAGINATE_BY.get("resource", 100)
prefetch_related = ["discovered_packages"]
table_columns = [
"path",
Expand Down Expand Up @@ -884,7 +884,7 @@ class DiscoveredPackageListView(
model = DiscoveredPackage
filterset_class = PackageFilterSet
template_name = "scanpipe/package_list.html"
paginate_by = 100
paginate_by = settings.SCANCODEIO_PAGINATE_BY.get("package", 100)
prefetch_related = ["codebase_resources"]
table_columns = [
"package_url",
Expand All @@ -906,7 +906,7 @@ class DiscoveredDependencyListView(
model = DiscoveredDependency
filterset_class = DependencyFilterSet
template_name = "scanpipe/dependency_list.html"
paginate_by = 100
paginate_by = settings.SCANCODEIO_PAGINATE_BY.get("dependency", 100)
prefetch_related = ["for_package", "datafile_resource"]
table_columns = [
"package_url",
Expand All @@ -932,7 +932,7 @@ class ProjectErrorListView(
model = ProjectError
filterset_class = ErrorFilterSet
template_name = "scanpipe/error_list.html"
paginate_by = 50
paginate_by = settings.SCANCODEIO_PAGINATE_BY.get("error", 50)
table_columns = [
"model",
"message",
Expand Down

0 comments on commit d5ba13e

Please sign in to comment.