Skip to content

Generic Multipurpose Search #606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions coldfront/config/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#------------------------------------------------------------------------------
Expand Down
16 changes: 10 additions & 6 deletions coldfront/core/project/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@
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)
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)


Expand Down
13 changes: 13 additions & 0 deletions coldfront/core/project/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions docs/pages/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down