From f1bf922ac6daf236bb2dbf9f24b872edd674f2cc Mon Sep 17 00:00:00 2001 From: Mobmaker <45888585+Mobmaker55@users.noreply.github.com> Date: Tue, 16 Apr 2024 15:37:15 -0400 Subject: [PATCH 1/3] Generic Multipurpose Search --- coldfront/config/core.py | 4 ++++ coldfront/core/project/forms.py | 18 +++++++++++------- coldfront/core/project/views.py | 13 +++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/coldfront/config/core.py b/coldfront/config/core.py index 581452f40e..63887a71e8 100644 --- a/coldfront/config/core.py +++ b/coldfront/config/core.py @@ -60,6 +60,10 @@ #------------------------------------------------------------------------------ ONDEMAND_URL = ENV.str('ONDEMAND_URL', default=None) +#------------------------------------------------------------------------------ +# Toggle Generic Search Form +#------------------------------------------------------------------------------ +GENERIC_SEARCH_FIELD = ENV.str('GENERIC_SEARCH_FIELD', default=False) #------------------------------------------------------------------------------ # Default Strings. Override these in local_settings.py #------------------------------------------------------------------------------ diff --git a/coldfront/core/project/forms.py b/coldfront/core/project/forms.py index beeea24e9c..d54045676c 100644 --- a/coldfront/core/project/forms.py +++ b/coldfront/core/project/forms.py @@ -16,21 +16,25 @@ EMAIL_ADMIN_LIST = import_from_settings('EMAIL_ADMIN_LIST', []) EMAIL_DIRECTOR_EMAIL_ADDRESS = import_from_settings( 'EMAIL_DIRECTOR_EMAIL_ADDRESS', '') - +GENERIC_SEARCH_FIELD = import_from_settings('GENERIC_SEARCH_FIELD', False) class ProjectSearchForm(forms.Form): """ Search form for the Project list page. """ + GENERIC_SEARCH = 'Search Value' LAST_NAME = 'Last Name' USERNAME = 'Username' FIELD_OF_SCIENCE = 'Field of Science' - last_name = forms.CharField( - label=LAST_NAME, max_length=100, required=False) - username = forms.CharField(label=USERNAME, max_length=100, required=False) - field_of_science = forms.CharField( - label=FIELD_OF_SCIENCE, max_length=100, required=False) - show_all_projects = forms.BooleanField(initial=False, required=False) + if GENERIC_SEARCH_FIELD: + generic = forms.CharField(label=GENERIC_SEARCH, max_length=100, required=False) + else: + last_name = forms.CharField( + label=LAST_NAME, max_length=100, required=False) + username = forms.CharField(label=USERNAME, max_length=100, required=False) + field_of_science = forms.CharField( + label=FIELD_OF_SCIENCE, max_length=100, required=False) + show_all_projects = forms.BooleanField(initial=False, required=False) class ProjectAddUserForm(forms.Form): diff --git a/coldfront/core/project/views.py b/coldfront/core/project/views.py index a71dda3491..d376f7d286 100644 --- a/coldfront/core/project/views.py +++ b/coldfront/core/project/views.py @@ -218,6 +218,19 @@ def get_queryset(self): Q(projectuser__status__name='Active') ).order_by(order_by) + # Generic Search + if data.get('generic'): + projects = projects.filter( + Q(pi__last_name__icontains=data.get('generic')) | + Q(title__icontains=data.get('generic')) | + Q(pi__username__icontains=data.get('generic')) | + ( + Q(projectuser__user__username__icontains=data.get('generic')) & + Q(projectuser__status__name='Active') + ) | + Q(description__icontains=data.get('generic')) + ) + # Last Name if data.get('last_name'): projects = projects.filter( From 4fb9e80140e72fd13781c31c328b1134262b150f Mon Sep 17 00:00:00 2001 From: Mobmaker <45888585+Mobmaker55@users.noreply.github.com> Date: Tue, 16 Apr 2024 15:39:32 -0400 Subject: [PATCH 2/3] Added to config.md --- docs/pages/config.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/pages/config.md b/docs/pages/config.md index bd19833296..25874be2cf 100644 --- a/docs/pages/config.md +++ b/docs/pages/config.md @@ -95,6 +95,7 @@ The following settings are ColdFront specific settings related to the core appli | ALLOCATION_RESOURCE_ORDERING | Controls the ordering of parent resources for an allocation (if allocation has multiple resources). Should be a list of field names suitable for Django QuerySet order_by method. Default is ['-is_allocatable', 'name']; i.e. prefer Resources with is_allocatable field set, ordered by name of the Resource.| | INVOICE_ENABLED | Enable or disable invoices. Default True | | ONDEMAND_URL | The URL to your Open OnDemand installation | +| GENERIC_SEARCH_FIELD | Switches from the current search field to a new "multipurpose" search field that will automatically search all current fields, plus more. Default False | LOGIN_FAIL_MESSAGE | Custom message when user fails to login. Here you can paint a custom link to your user account portal | | ENABLE_SU | Enable administrators to login as other users. Default True | From b7c693fbc08b001cf110d9fa2465192f4b80a241 Mon Sep 17 00:00:00 2001 From: Mobmaker <45888585+Mobmaker55@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:48:07 -0400 Subject: [PATCH 3/3] Make sure show all is permanent --- coldfront/core/project/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coldfront/core/project/forms.py b/coldfront/core/project/forms.py index d54045676c..2c1f5f6603 100644 --- a/coldfront/core/project/forms.py +++ b/coldfront/core/project/forms.py @@ -34,7 +34,7 @@ class ProjectSearchForm(forms.Form): username = forms.CharField(label=USERNAME, max_length=100, required=False) field_of_science = forms.CharField( label=FIELD_OF_SCIENCE, max_length=100, required=False) - show_all_projects = forms.BooleanField(initial=False, required=False) + show_all_projects = forms.BooleanField(initial=False, required=False) class ProjectAddUserForm(forms.Form):