diff --git a/hypha/apply/projects/filters.py b/hypha/apply/projects/filters.py index b32018def1..aa7c9f0f9d 100644 --- a/hypha/apply/projects/filters.py +++ b/hypha/apply/projects/filters.py @@ -70,6 +70,18 @@ class Meta: fields = ["project_status", "project_lead", "project_fund"] model = Project + def __init__(self, *args, exclude=None, **kwargs): + if exclude is None: + exclude = [] + + super().__init__(*args, **kwargs) + + self.filters = { + field: filter + for field, filter in self.filters.items() + if field not in exclude + } + def filter_reporting(self, queryset, name, value): if value == "1": return queryset.filter(outstanding_reports__gt=0) diff --git a/hypha/apply/projects/views/project.py b/hypha/apply/projects/views/project.py index da213273af..7982a9c474 100644 --- a/hypha/apply/projects/views/project.py +++ b/hypha/apply/projects/views/project.py @@ -2282,3 +2282,14 @@ class ProjectListView(SingleTableMixin, FilterView): queryset = Project.objects.for_table() table_class = ProjectsListTable template_name = "application_projects/project_list.html" + + excluded_fields = settings.PROJECTS_TABLE_EXCLUDED_FIELDS + + def get_filterset_kwargs(self, filterset_class, **kwargs): + new_kwargs = super().get_filterset_kwargs(filterset_class) + new_kwargs["exclude"] = self.excluded_fields + new_kwargs.update(kwargs) + return new_kwargs + + def get_table_kwargs(self): + return {"exclude": self.excluded_fields} diff --git a/hypha/core/context_processors.py b/hypha/core/context_processors.py index ac836c4708..4403ff4ac0 100644 --- a/hypha/core/context_processors.py +++ b/hypha/core/context_processors.py @@ -23,6 +23,7 @@ def global_vars(request): "SENTRY_DEBUG": settings.SENTRY_DEBUG, "SENTRY_PUBLIC_KEY": settings.SENTRY_PUBLIC_KEY, "SUBMISSIONS_TABLE_EXCLUDED_FIELDS": settings.SUBMISSIONS_TABLE_EXCLUDED_FIELDS, + "PROJECTS_TABLE_EXCLUDED_FIELDS": settings.PROJECTS_TABLE_EXCLUDED_FIELDS, "HIJACK_ENABLE": settings.HIJACK_ENABLE, "LANGUAGE_SWITCHER": settings.LANGUAGE_SWITCHER, "SUBMISSION_ANONYMIZATION_ENABLED": settings.SUBMISSION_ANONYMIZATION_ENABLED, diff --git a/hypha/settings/base.py b/hypha/settings/base.py index 150b28eadc..59b4be8b04 100644 --- a/hypha/settings/base.py +++ b/hypha/settings/base.py @@ -176,6 +176,10 @@ "SUBMISSIONS_TABLE_EXCLUDED_FIELDS", ["organization_name"] ) +# Columns/filters to exclude from the project tables. +# Possible values are: project_fund, project_lead, project_status, reporting +PROJECTS_TABLE_EXCLUDED_FIELDS = env.list("PROJECTS_TABLE_EXCLUDED_FIELDS", []) + # No of co-applicants can be added to a submission (default 10) SUBMISSIONS_COAPPLICANT_INVITES_LIMIT = env.int( "SUBMISSIONS_COAPPLICANT_INVITES_LIMIT", 10