diff --git a/coldfront/config/core.py b/coldfront/config/core.py index b4421880ee..742b0fa4e8 100644 --- a/coldfront/config/core.py +++ b/coldfront/config/core.py @@ -24,6 +24,11 @@ GRANT_ENABLE = ENV.bool("GRANT_ENABLE", default=True) PUBLICATION_ENABLE = ENV.bool("PUBLICATION_ENABLE", default=True) +# ------------------------------------------------------------------------------ +# Hide Field of Science. Hide Field of Science related functionality if True +# ------------------------------------------------------------------------------ +FIELD_OF_SCIENCE_HIDE = ENV.bool("FIELD_OF_SCIENCE_HIDE", default=False) + # ------------------------------------------------------------------------------ # Enable Project Review # ------------------------------------------------------------------------------ @@ -64,6 +69,7 @@ "PUBLICATION_ENABLE", "INVOICE_ENABLED", "PROJECT_ENABLE_PROJECT_REVIEW", + "FIELD_OF_SCIENCE_HIDE", ] ADMIN_COMMENTS_SHOW_EMPTY = ENV.bool("ADMIN_COMMENTS_SHOW_EMPTY", default=True) diff --git a/coldfront/config/urls.py b/coldfront/config/urls.py index 86bcb0bd95..145005a275 100644 --- a/coldfront/config/urls.py +++ b/coldfront/config/urls.py @@ -27,13 +27,15 @@ path("", portal_views.home, name="home"), path("center-summary", portal_views.center_summary, name="center-summary"), path("allocation-summary", portal_views.allocation_summary, name="allocation-summary"), - path("allocation-by-fos", portal_views.allocation_by_fos, name="allocation-by-fos"), path("user/", include("coldfront.core.user.urls")), path("project/", include("coldfront.core.project.urls")), path("allocation/", include("coldfront.core.allocation.urls")), path("resource/", include("coldfront.core.resource.urls")), ] +if not settings.FIELD_OF_SCIENCE_HIDE: + urlpatterns.append(path("allocation-by-fos", portal_views.allocation_by_fos, name="allocation-by-fos")) + if settings.GRANT_ENABLE: urlpatterns.append(path("grant/", include("coldfront.core.grant.urls"))) diff --git a/coldfront/core/portal/templates/portal/center_summary.html b/coldfront/core/portal/templates/portal/center_summary.html index adc38e987d..8fefc61a46 100644 --- a/coldfront/core/portal/templates/portal/center_summary.html +++ b/coldfront/core/portal/templates/portal/center_summary.html @@ -59,6 +59,7 @@

{% settings_value 'CENTER_NAME' %} Scientific Impact

{% endif %} +{% if not settings.FIELD_OF_SCIENCE_HIDE %}
@@ -72,6 +73,7 @@

{% settings_value 'CENTER_NAME' %} Scientific Impact

+{% endif %}
diff --git a/coldfront/core/portal/tests/test_views.py b/coldfront/core/portal/tests/test_views.py index 8cad2fd30d..3151e479e6 100644 --- a/coldfront/core/portal/tests/test_views.py +++ b/coldfront/core/portal/tests/test_views.py @@ -4,7 +4,9 @@ import logging -from django.test import TestCase +from django.test import TestCase, override_settings + +from coldfront.core.utils.common import import_from_settings logging.disable(logging.CRITICAL) @@ -33,3 +35,20 @@ def test_centersummary_renders(self): self.assertContains(response, "Active Allocations and Users") self.assertContains(response, "Resources and Allocations Summary") self.assertNotContains(response, "We're having a bit of system trouble at the moment. Please check back soon!") + + def test_centersummary_renders_field_of_science_not_hidden(self): + self.assertFalse(import_from_settings("FIELD_OF_SCIENCE_HIDE", True)) + response = self.client.get(self.url) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "") + # sanity check for other chart + self.assertContains(response, "") + + @override_settings(FIELD_OF_SCIENCE_HIDE=True) + def test_centersummary_renders_field_of_science_hidden(self): + self.assertTrue(import_from_settings("FIELD_OF_SCIENCE_HIDE", False)) + response = self.client.get(self.url) + self.assertEqual(response.status_code, 200) + self.assertNotContains(response, "") + # sanity check for other chart + self.assertContains(response, "") diff --git a/coldfront/core/project/forms.py b/coldfront/core/project/forms.py index c0e2c9bd7c..eee55af2aa 100644 --- a/coldfront/core/project/forms.py +++ b/coldfront/core/project/forms.py @@ -4,6 +4,8 @@ import datetime +from crispy_forms.helper import FormHelper, Layout +from crispy_forms.layout import Field from django import forms from django.db.models.functions import Lower from django.shortcuts import get_object_or_404 @@ -28,6 +30,25 @@ class ProjectSearchForm(forms.Form): field_of_science = forms.CharField(label=FIELD_OF_SCIENCE, max_length=100, required=False) show_all_projects = forms.BooleanField(initial=False, required=False) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.helper = FormHelper() + # form tag is in templates + self.helper.form_tag = False + if import_from_settings("FIELD_OF_SCIENCE_HIDE", False): + self.helper.layout = Layout( + Field("last_name"), + Field("username"), + Field("show_all_projects"), + ) + else: + self.helper.layout = Layout( + Field("last_name"), + Field("username"), + Field("field_of_science"), + Field("show_all_projects"), + ) + class ProjectAddUserForm(forms.Form): username = forms.CharField(max_length=150, disabled=True) @@ -180,7 +201,24 @@ def clean(self): proj_attr.clean() -class ProjectCreationForm(forms.ModelForm): +class ProjectUpdateForm(forms.ModelForm): class Meta: model = Project - fields = ["title", "description", "field_of_science"] + exclude = [] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.helper = FormHelper() + # form tag is in templates + self.helper.form_tag = False + if import_from_settings("FIELD_OF_SCIENCE_HIDE", False): + self.helper.layout = Layout( + Field("title"), + Field("description"), + ) + else: + self.helper.layout = Layout( + Field("title"), + Field("description"), + Field("field_of_science"), + ) diff --git a/coldfront/core/project/templates/project/project_archive.html b/coldfront/core/project/templates/project/project_archive.html index 71ca648671..2bf7c8bfec 100644 --- a/coldfront/core/project/templates/project/project_archive.html +++ b/coldfront/core/project/templates/project/project_archive.html @@ -22,7 +22,9 @@

Email

Description: {{ project.description }}

-

Field of Science: {{ project.field_of_science }}

+ {% if not settings.FIELD_OF_SCIENCE_HIDE %} +

Field of Science: {{ project.field_of_science }}

+ {% endif %}

Status: {{ project.status}}

diff --git a/coldfront/core/project/templates/project/project_archived_list.html b/coldfront/core/project/templates/project/project_archived_list.html index 3ef395c163..d5c62996c5 100644 --- a/coldfront/core/project/templates/project/project_archived_list.html +++ b/coldfront/core/project/templates/project/project_archived_list.html @@ -33,7 +33,7 @@

Archived Projects

- {{ project_search_form|crispy }} + {% crispy project_search_form project_search_form.helper %}
@@ -61,11 +61,13 @@

Archived Projects

Sort PI desc Title and Description - - 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 @@ -84,7 +86,9 @@

Archived Projects

{{ project.pi.username }} Title: {{ project.title }}
Description: {{ project.description }} - {{ 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 %}

Institution: {{ project.institution }}

diff --git a/coldfront/core/project/templates/project/project_create_form.html b/coldfront/core/project/templates/project/project_create_form.html index b7c115e972..e0aa27fb39 100644 --- a/coldfront/core/project/templates/project/project_create_form.html +++ b/coldfront/core/project/templates/project/project_create_form.html @@ -11,14 +11,18 @@ {% block content %}
{% csrf_token %} - {{ form|crispy }} + {% crispy form form.helper %} Cancel
+{% if not settings.FIELD_OF_SCIENCE_HIDE %} +{% endif %} + {% endblock %} + diff --git a/coldfront/core/project/templates/project/project_detail.html b/coldfront/core/project/templates/project/project_detail.html index acbd285176..943f23e4e0 100644 --- a/coldfront/core/project/templates/project/project_detail.html +++ b/coldfront/core/project/templates/project/project_detail.html @@ -75,7 +75,9 @@

{% else %}

ID: {{ project.id }}

{% endif %} -

Field of Science: {{ project.field_of_science }}

+ {% if not settings.FIELD_OF_SCIENCE_HIDE %} +

Field of Science: {{ project.field_of_science }}

+ {% endif %}

Project Status: {{ project.status }} {% if project.last_project_review and project.last_project_review.status.name == 'Pending'%} project review pending diff --git a/coldfront/core/project/templates/project/project_list.html b/coldfront/core/project/templates/project/project_list.html index 2045548a18..ec5d262b00 100644 --- a/coldfront/core/project/templates/project/project_list.html +++ b/coldfront/core/project/templates/project/project_list.html @@ -34,7 +34,7 @@

Projects

- {{ project_search_form|crispy }} + {% crispy project_search_form project_search_form.helper %}
@@ -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 %}
{% csrf_token %} - {{ form|crispy }} + {% crispy form form.helper %} Cancel
+{% 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):