@@ -61,11 +61,13 @@
Projects
Sort PI desc
Title |
-
- Field of Science
- Sort Field of Science asc
- Sort Field of Science desc
- |
+ {% if not settings.FIELD_OF_SCIENCE_HIDE %}
+
+ Field of Science
+ Sort Field of Science asc
+ Sort Field of Science desc
+ |
+ {% endif %}
Status
Sort Status asc
@@ -90,7 +92,9 @@ Projects
{% endif %}
| {{ project.pi.username }} |
{{ project.title }} |
-
{{ project.field_of_science.description }} |
+ {% if not settings.FIELD_OF_SCIENCE_HIDE %}
+
{{ project.field_of_science.description }} |
+ {% endif %}
{{ project.status.name }} |
{% if PROJECT_INSTITUTION_EMAIL_MAP %}
{{ project.institution }} |
diff --git a/coldfront/core/project/templates/project/project_update_form.html b/coldfront/core/project/templates/project/project_update_form.html
index 159f54457c..8d04057c71 100644
--- a/coldfront/core/project/templates/project/project_update_form.html
+++ b/coldfront/core/project/templates/project/project_update_form.html
@@ -11,14 +11,18 @@
{% block content %}
+{% if not settings.FIELD_OF_SCIENCE_HIDE %}
+{% endif %}
+
{% endblock %}
+
diff --git a/coldfront/core/project/tests/test_views.py b/coldfront/core/project/tests/test_views.py
index 116fdd2619..84068fabe1 100644
--- a/coldfront/core/project/tests/test_views.py
+++ b/coldfront/core/project/tests/test_views.py
@@ -4,7 +4,7 @@
import logging
-from django.test import TestCase
+from django.test import TestCase, override_settings
from coldfront.core.project.models import ProjectUserStatusChoice
from coldfront.core.test_helpers import utils
@@ -114,6 +114,18 @@ def test_projectdetail_addnotification_button_visibility(self):
# non-manager user cannot see add notification button
utils.page_does_not_contain_for_user(self, self.project_user, self.url, "Add Notification")
+ @override_settings(FIELD_OF_SCIENCE_HIDE=True)
+ def test_project_detail_field_of_science_hidden(self):
+ """Test that the setting FIELD_OF_SCIENCE_HIDE=True hides the field of science field on the project detail form."""
+ response = utils.login_and_get_page(self.client, self.admin_user, self.url)
+ self.assertNotContains(response, "Field of Science:")
+
+ @override_settings(FIELD_OF_SCIENCE_HIDE=False)
+ def test_project_detail_field_of_science_visible(self):
+ """Test that the setting FIELD_OF_SCIENCE_HIDE=False shows the field of science field on the project detail form."""
+ response = utils.login_and_get_page(self.client, self.admin_user, self.url)
+ self.assertContains(response, "Field of Science:")
+
class ProjectCreateTest(ProjectViewTestBase):
"""Tests for project create view"""
@@ -133,6 +145,18 @@ def test_project_access(self):
utils.test_user_cannot_access(self, self.project_user, self.url)
utils.test_user_cannot_access(self, self.nonproject_user, self.url)
+ @override_settings(FIELD_OF_SCIENCE_HIDE=True)
+ def test_project_create_field_of_science_hidden(self):
+ """Test that the setting FIELD_OF_SCIENCE_HIDE=True hides the field of science field on the project create form."""
+ response = utils.login_and_get_page(self.client, self.admin_user, self.url)
+ self.assertNotContains(response, "Field of science")
+
+ @override_settings(FIELD_OF_SCIENCE_HIDE=False)
+ def test_project_create_field_of_science_visible(self):
+ """Test that the setting FIELD_OF_SCIENCE_HIDE=False shows the field of science field on the project create form."""
+ response = utils.login_and_get_page(self.client, self.admin_user, self.url)
+ self.assertContains(response, "Field of science")
+
class ProjectAttributeCreateTest(ProjectViewTestBase):
"""Tests for project attribute create view"""
@@ -303,6 +327,29 @@ def test_project_list_search(self):
response = utils.login_and_get_page(self.client, self.admin_user, url)
self.assertEqual(len(response.context["object_list"]), 1)
+ @override_settings(FIELD_OF_SCIENCE_HIDE=True)
+ def test_project_list_search_field_of_science_hidden(self):
+ """Test that project list search works when field_of_science is hidden."""
+ url_base = self.url + "?show_all_projects=on"
+ url = f"{url_base}&last_name={self.project.pi.last_name}"
+ # search by project project_title
+ response = utils.login_and_get_page(self.client, self.admin_user, url)
+ self.assertEqual(len(response.context["object_list"]), 1)
+
+ @override_settings(FIELD_OF_SCIENCE_HIDE=True)
+ def test_project_list_field_of_science_hidden(self):
+ """Test that the setting FIELD_OF_SCIENCE_HIDE=True hides the field of science field on the search form."""
+ url = self.url
+ response = utils.login_and_get_page(self.client, self.admin_user, url)
+ self.assertNotContains(response, "Field of Science")
+
+ @override_settings(FIELD_OF_SCIENCE_HIDE=False)
+ def test_project_list_field_of_science_visible(self):
+ """Test that the setting FIELD_OF_SCIENCE_HIDE=False shows the field of science field on the search form."""
+ url = self.url
+ response = utils.login_and_get_page(self.client, self.admin_user, url)
+ self.assertContains(response, "Field of Science")
+
class ProjectRemoveUsersViewTest(ProjectViewTestBase):
"""Tests for ProjectRemoveUsersView"""
@@ -327,6 +374,18 @@ def test_projectupdateview_access(self):
"""test access to project update page"""
self.project_access_tstbase(self.url)
+ @override_settings(FIELD_OF_SCIENCE_HIDE=True)
+ def test_project_update_field_of_science_hidden(self):
+ """Test that the setting FIELD_OF_SCIENCE_HIDE=True hides the field of science field on the project update form."""
+ response = utils.login_and_get_page(self.client, self.admin_user, self.url)
+ self.assertNotContains(response, "Field of science")
+
+ @override_settings(FIELD_OF_SCIENCE_HIDE=False)
+ def test_project_update_field_of_science_visible(self):
+ """Test that the setting FIELD_OF_SCIENCE_HIDE=False shows the field of science field on the project update form."""
+ response = utils.login_and_get_page(self.client, self.admin_user, self.url)
+ self.assertContains(response, "Field of science")
+
class ProjectReviewListViewTest(ProjectViewTestBase):
"""Tests for ProjectReviewListView"""
@@ -351,6 +410,18 @@ def test_projectarchivedlistview_access(self):
"""test access to project archived list page"""
self.project_access_tstbase(self.url)
+ @override_settings(FIELD_OF_SCIENCE_HIDE=True)
+ def test_projectarchivedlistview_field_of_science_hidden(self):
+ """Test that the setting FIELD_OF_SCIENCE_HIDE=True hides the field of science field on the project archived list search form."""
+ response = utils.login_and_get_page(self.client, self.admin_user, self.url)
+ self.assertNotContains(response, "Field of Science")
+
+ @override_settings(FIELD_OF_SCIENCE_HIDE=False)
+ def test_projectarchivedlistview_field_of_science_visible(self):
+ """Test that the setting FIELD_OF_SCIENCE_HIDE=False shows the field of science field on the project archived list search form."""
+ response = utils.login_and_get_page(self.client, self.admin_user, self.url)
+ self.assertContains(response, "Field of Science")
+
class ProjectNoteCreateViewTest(ProjectViewTestBase):
"""Tests for ProjectNoteCreateView"""
diff --git a/coldfront/core/project/views.py b/coldfront/core/project/views.py
index 7c164c37d3..05062d8d37 100644
--- a/coldfront/core/project/views.py
+++ b/coldfront/core/project/views.py
@@ -39,11 +39,11 @@
ProjectAttributeAddForm,
ProjectAttributeDeleteForm,
ProjectAttributeUpdateForm,
- ProjectCreationForm,
ProjectRemoveUserForm,
ProjectReviewEmailForm,
ProjectReviewForm,
ProjectSearchForm,
+ ProjectUpdateForm,
ProjectUserUpdateForm,
)
from coldfront.core.project.models import (
@@ -301,7 +301,7 @@ def get_queryset(self):
)
# Field of Science
- if data.get("field_of_science"):
+ if data.get("field_of_science", ""):
projects = projects.filter(field_of_science__description__icontains=data.get("field_of_science"))
else:
@@ -568,7 +568,7 @@ def post(self, request, *args, **kwargs):
class ProjectCreateView(LoginRequiredMixin, UserPassesTestMixin, CreateView):
model = Project
template_name_suffix = "_create_form"
- form_class = ProjectCreationForm
+ form_class = ProjectUpdateForm
def test_func(self):
"""UserPassesTestMixin Tests"""
@@ -615,11 +615,7 @@ def get_success_url(self):
class ProjectUpdateView(SuccessMessageMixin, LoginRequiredMixin, UserPassesTestMixin, UpdateView):
model = Project
template_name_suffix = "_update_form"
- fields = [
- "title",
- "description",
- "field_of_science",
- ]
+ form_class = ProjectUpdateForm
success_message = "Project updated."
def test_func(self):