Skip to content
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

Allow projects to be searched by title and status #622

Open
wants to merge 1 commit 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
8 changes: 7 additions & 1 deletion coldfront/core/project/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.db.models.functions import Lower
from cProfile import label

from coldfront.core.project.models import (Project, ProjectAttribute, ProjectAttributeType, ProjectReview,
from coldfront.core.project.models import (Project, ProjectAttribute, ProjectAttributeType, ProjectReview, ProjectStatusChoice,
ProjectUserRoleChoice)
from coldfront.core.utils.common import import_from_settings

Expand All @@ -25,11 +25,17 @@ class ProjectSearchForm(forms.Form):
USERNAME = 'Username'
FIELD_OF_SCIENCE = 'Field of Science'

title = forms.CharField(label='Title',
max_length=100, required=False)
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)
status = forms.ModelMultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
queryset=ProjectStatusChoice.objects.all().order_by(Lower("name")),
required=False)
show_all_projects = forms.BooleanField(initial=False, required=False)


Expand Down
10 changes: 10 additions & 0 deletions coldfront/core/project/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ def get_queryset(self):
Q(projectuser__status__name='Active')
).order_by(order_by)

# Project Title
if data.get('title'):
projects = projects.filter(
title__icontains=data.get('title'))

# Last Name
if data.get('last_name'):
projects = projects.filter(
Expand All @@ -236,6 +241,11 @@ def get_queryset(self):
projects = projects.filter(
field_of_science__description__icontains=data.get('field_of_science'))

# Status
if data.get('status'):
projects = projects.filter(
status__in=data.get('status'))

else:
projects = Project.objects.prefetch_related('pi', 'field_of_science', 'status',).filter(
Q(status__name__in=['New', 'Active', ]) &
Expand Down