diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f9d71e369..552132119 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -53,6 +53,7 @@ v31.0.0 (next) - Creation date displayed under the project name - Add ability to sort by date and name - Add ability to filter by pipeline type + - Add ability to filter by run status https://github.com/nexB/scancode.io/issues/413 diff --git a/Makefile b/Makefile index fb4f6262b..0ec2cdf86 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,9 @@ PYTHON_EXE?=python3 MANAGE=bin/python manage.py ACTIVATE?=. bin/activate; VIRTUALENV_PYZ=etc/thirdparty/virtualenv.pyz -BLACK_ARGS=--exclude="migrations|data|lib|bin|var" . +BLACK_ARGS=--exclude="migrations|data|lib|bin|var" +PYCODESTYLE_ARGS=--max-line-length=88 \ + --exclude=lib,thirdparty,docs,bin,migrations,settings.py,data,pipelines,var # Do not depend on Python to generate the SECRET_KEY GET_SECRET_KEY=`base64 /dev/urandom | head -c50` # Customize with `$ make envfile ENV_FILE=/etc/scancodeio/.env` @@ -64,11 +66,11 @@ envfile: isort: @echo "-> Apply isort changes to ensure proper imports ordering" - bin/isort . + @${ACTIVATE} isort . black: @echo "-> Apply black code formatter" - bin/black ${BLACK_ARGS} + @${ACTIVATE} black ${BLACK_ARGS} . doc8: @echo "-> Run doc8 validation" @@ -78,11 +80,11 @@ valid: isort black doc8 check: doc8 @echo "-> Run pycodestyle (PEP8) validation" - @${ACTIVATE} pycodestyle --max-line-length=88 --exclude=lib,thirdparty,docs,bin,migrations,settings.py,data,pipelines,var . + @${ACTIVATE} pycodestyle ${PYCODESTYLE_ARGS} . @echo "-> Run isort imports ordering validation" @${ACTIVATE} isort --check-only . @echo "-> Run black validation" - @${ACTIVATE} black --check ${BLACK_ARGS} + @${ACTIVATE} black --check ${BLACK_ARGS} . clean: @echo "-> Clean the Python env" @@ -111,7 +113,7 @@ sqlitedb: @$(MAKE) migrate run: - ${MANAGE} runserver 8001 --noreload --insecure + ${MANAGE} runserver 8001 --insecure --noreload test: @echo "-> Run the test suite" @@ -122,7 +124,7 @@ worker: bump: @echo "-> Bump the version" - bin/bumpver update --no-fetch --patch + @${ACTIVATE} bumpver update --no-fetch --patch docs: rm -rf docs/_build/ diff --git a/scanpipe/filters.py b/scanpipe/filters.py index 36d8edb61..2922c763e 100644 --- a/scanpipe/filters.py +++ b/scanpipe/filters.py @@ -32,6 +32,7 @@ from scanpipe.models import DiscoveredPackage from scanpipe.models import Project from scanpipe.models import ProjectError +from scanpipe.models import Run scanpipe_app = apps.get_app_config("scanpipe") @@ -153,6 +154,18 @@ class ProjectFilterSet(FilterSetUtilsMixin, django_filters.FilterSet): choices=scanpipe_app.get_pipeline_choices(include_blank=False), widget=BulmaDropdownWidget, ) + status = django_filters.ChoiceFilter( + label="Status", + method="filter_run_status", + choices=[ + ("not_started", "Not started"), + ("queued", "Queued"), + ("running", "Running"), + ("succeed", "Success"), + ("failed", "Failure"), + ], + widget=BulmaDropdownWidget, + ) class Meta: model = Project @@ -177,6 +190,14 @@ def __init__(self, data=None, *args, **kwargs): ] ) + def filter_run_status(self, queryset, name, value): + """ + Filter by Run status using the `RunQuerySet` methods. + """ + run_queryset_method = value + run_queryset = getattr(Run.objects, run_queryset_method)() + return queryset.filter(runs__in=run_queryset) + class JSONContainsFilter(django_filters.CharFilter): """ diff --git a/scanpipe/templates/scanpipe/project_list.html b/scanpipe/templates/scanpipe/project_list.html index 6799110eb..3112e35b2 100644 --- a/scanpipe/templates/scanpipe/project_list.html +++ b/scanpipe/templates/scanpipe/project_list.html @@ -21,6 +21,11 @@