Skip to content

Commit d6b145a

Browse files
committed
Added setting FIELD_OF_SCIENCE_HIDE that removes references to Field of Science from all pages when True
Signed-off-by: Chris Barnett <[email protected]>
1 parent 72dbd32 commit d6b145a

File tree

13 files changed

+212
-30
lines changed

13 files changed

+212
-30
lines changed

coldfront/config/core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
GRANT_ENABLE = ENV.bool("GRANT_ENABLE", default=True)
2525
PUBLICATION_ENABLE = ENV.bool("PUBLICATION_ENABLE", default=True)
2626

27+
# ------------------------------------------------------------------------------
28+
# Hide Field of Science. Hide Field of Science related functionality if True
29+
# ------------------------------------------------------------------------------
30+
FIELD_OF_SCIENCE_HIDE = ENV.bool("FIELD_OF_SCIENCE_HIDE", default=False)
31+
2732
# ------------------------------------------------------------------------------
2833
# Enable Project Review
2934
# ------------------------------------------------------------------------------
@@ -64,6 +69,7 @@
6469
"PUBLICATION_ENABLE",
6570
"INVOICE_ENABLED",
6671
"PROJECT_ENABLE_PROJECT_REVIEW",
72+
"FIELD_OF_SCIENCE_HIDE",
6773
]
6874

6975
ADMIN_COMMENTS_SHOW_EMPTY = ENV.bool("ADMIN_COMMENTS_SHOW_EMPTY", default=True)

coldfront/config/urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
path("", portal_views.home, name="home"),
2525
path("center-summary", portal_views.center_summary, name="center-summary"),
2626
path("allocation-summary", portal_views.allocation_summary, name="allocation-summary"),
27-
path("allocation-by-fos", portal_views.allocation_by_fos, name="allocation-by-fos"),
2827
path("user/", include("coldfront.core.user.urls")),
2928
path("project/", include("coldfront.core.project.urls")),
3029
path("allocation/", include("coldfront.core.allocation.urls")),
3130
path("resource/", include("coldfront.core.resource.urls")),
3231
]
3332

33+
if not settings.FIELD_OF_SCIENCE_HIDE:
34+
urlpatterns.append(path("allocation-by-fos", portal_views.allocation_by_fos, name="allocation-by-fos"))
35+
3436
if settings.GRANT_ENABLE:
3537
urlpatterns.append(path("grant/", include("coldfront.core.grant.urls")))
3638

coldfront/core/portal/templates/portal/center_summary.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ <h2>{% settings_value 'CENTER_NAME' %} Scientific Impact</h2>
5959
<!-- End Grants -->
6060
{% endif %}
6161

62+
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
6263
<!-- Start Allocation by Field of Science -->
6364
<div class="card mb-3 border-primary">
6465
<div class="card-header bg-primary text-white">
@@ -72,6 +73,7 @@ <h2>{% settings_value 'CENTER_NAME' %} Scientific Impact</h2>
7273
</div>
7374
</div>
7475
<!-- End Allocation by Field of Science -->
76+
{% endif %}
7577

7678
<!-- Start Allocation Charts -->
7779
<div class="card mb-3 border-primary">
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SPDX-FileCopyrightText: (C) ColdFront Authors
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
import logging
6+
7+
from django.test import TestCase, override_settings
8+
9+
from coldfront.core.utils.common import import_from_settings
10+
11+
logging.disable(logging.CRITICAL)
12+
13+
14+
class PortalViewBaseTest(TestCase):
15+
"""Base class for portal view tests."""
16+
17+
@classmethod
18+
def setUpTestData(cls):
19+
"""Test Data setup for all portal view tests."""
20+
pass
21+
22+
23+
class CenterSummaryViewTest(PortalViewBaseTest):
24+
"""Tests for center summary view"""
25+
26+
@classmethod
27+
def setUpTestData(cls):
28+
"""Set up users and project for testing"""
29+
cls.url = "/center-summary"
30+
super(PortalViewBaseTest, cls).setUpTestData()
31+
32+
def test_centersummary_renders_field_of_science_not_hidden(self):
33+
self.assertFalse(import_from_settings("FIELD_OF_SCIENCE_HIDE", True))
34+
response = self.client.get(self.url)
35+
self.assertEqual(response.status_code, 200)
36+
self.assertContains(response, "<!-- Start Allocation by Field of Science -->")
37+
# sanity check for other chart
38+
self.assertContains(response, "<!-- Start Allocation Charts -->")
39+
40+
@override_settings(FIELD_OF_SCIENCE_HIDE=True)
41+
def test_centersummary_renders_field_of_science_hidden(self):
42+
self.assertTrue(import_from_settings("FIELD_OF_SCIENCE_HIDE", False))
43+
response = self.client.get(self.url)
44+
self.assertEqual(response.status_code, 200)
45+
self.assertNotContains(response, "<!-- Start Allocation by Field of Science -->")
46+
# sanity check for other chart
47+
self.assertContains(response, "<!-- Start Allocation Charts -->")

coldfront/core/project/forms.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import datetime
66

7+
from crispy_forms.helper import FormHelper, Layout
8+
from crispy_forms.layout import Field
79
from django import forms
810
from django.db.models.functions import Lower
911
from django.shortcuts import get_object_or_404
@@ -28,6 +30,25 @@ class ProjectSearchForm(forms.Form):
2830
field_of_science = forms.CharField(label=FIELD_OF_SCIENCE, max_length=100, required=False)
2931
show_all_projects = forms.BooleanField(initial=False, required=False)
3032

33+
def __init__(self, *args, **kwargs):
34+
super().__init__(*args, **kwargs)
35+
self.helper = FormHelper()
36+
# form tag is in templates
37+
self.helper.form_tag = False
38+
if import_from_settings("FIELD_OF_SCIENCE_HIDE", False):
39+
self.helper.layout = Layout(
40+
Field("last_name"),
41+
Field("username"),
42+
Field("show_all_projects"),
43+
)
44+
else:
45+
self.helper.layout = Layout(
46+
Field("last_name"),
47+
Field("username"),
48+
Field("field_of_science"),
49+
Field("show_all_projects"),
50+
)
51+
3152

3253
class ProjectAddUserForm(forms.Form):
3354
username = forms.CharField(max_length=150, disabled=True)
@@ -207,7 +228,24 @@ def clean(self):
207228
proj_attr.clean()
208229

209230

210-
class ProjectCreationForm(forms.ModelForm):
231+
class ProjectUpdateForm(forms.ModelForm):
211232
class Meta:
212233
model = Project
213-
fields = ["title", "description", "field_of_science"]
234+
exclude = []
235+
236+
def __init__(self, *args, **kwargs):
237+
super().__init__(*args, **kwargs)
238+
self.helper = FormHelper()
239+
# form tag is in templates
240+
self.helper.form_tag = False
241+
if import_from_settings("FIELD_OF_SCIENCE_HIDE", False):
242+
self.helper.layout = Layout(
243+
Field("title"),
244+
Field("description"),
245+
)
246+
else:
247+
self.helper.layout = Layout(
248+
Field("title"),
249+
Field("description"),
250+
Field("field_of_science"),
251+
)

coldfront/core/project/templates/project/project_archive.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ <h3 class="card-title">
2222
<a href="mailto:{{ project.pi.email }}"><i class="far fa-envelope" aria-hidden="true"></i><span class="sr-only">Email</span></a>
2323
</h3>
2424
<p class="card-text text-justify"><strong>Description: </strong>{{ project.description }}</p>
25-
<p class="card-text text-justify"><strong>Field of Science: </strong>{{ project.field_of_science }}</p>
25+
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
26+
<p class="card-text text-justify"><strong>Field of Science: </strong>{{ project.field_of_science }}</p>
27+
{% endif %}
2628
<p class="card-text text-justify"><strong>Status: </strong>{{ project.status}}</p>
2729
</div>
2830
</div>

coldfront/core/project/templates/project/project_archived_list.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h2>Archived Projects</h2>
3333
<div id="collapseOne" class="collapse {{expand_accordion}}" data-parent="#accordion">
3434
<div class="card-body">
3535
<form id="filter_form" method="GET" action="{% url 'project-archived-list' %}">
36-
{{ project_search_form|crispy }}
36+
{% crispy project_search_form project_search_form.helper %}
3737
<input type="submit" class="btn btn-primary" value="Search">
3838
<button id="form_reset_button" type="button" class="btn btn-secondary">Reset</button>
3939
</form>
@@ -61,11 +61,13 @@ <h2>Archived Projects</h2>
6161
<a href="?order_by=pi__username&direction=des&{{filter_parameters}}"><i class="fas fa-sort-down" aria-hidden="true"></i><span class="sr-only">Sort PI desc</span></a>
6262
</th>
6363
<th scope="col">Title and Description</th>
64-
<th scope="col" class="text-nowrap">
65-
Field of Science
66-
<a href="?order_by=field_of_science&direction=asc&{{filter_parameters}}"><i class="fas fa-sort-up" aria-hidden="true"></i><span class="sr-only">Sort Field of Science asc</span></a>
67-
<a href="?order_by=field_of_science&direction=des&{{filter_parameters}}"><i class="fas fa-sort-down" aria-hidden="true"></i><span class="sr-only">Sort Field of Science desc</span></a>
68-
</th>
64+
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
65+
<th scope="col" class="text-nowrap">
66+
Field of Science
67+
<a href="?order_by=field_of_science&direction=asc&{{filter_parameters}}"><i class="fas fa-sort-up" aria-hidden="true"></i><span class="sr-only">Sort Field of Science asc</span></a>
68+
<a href="?order_by=field_of_science&direction=des&{{filter_parameters}}"><i class="fas fa-sort-down" aria-hidden="true"></i><span class="sr-only">Sort Field of Science desc</span></a>
69+
</th>
70+
{% endif %}
6971
<th scope="col" class="text-nowrap">
7072
Status
7173
<a href="?order_by=status&direction=asc&{{filter_parameters}}"><i class="fas fa-sort-up" aria-hidden="true"></i><span class="sr-only">Sort Status asc</span></a>
@@ -84,7 +86,9 @@ <h2>Archived Projects</h2>
8486
<td>{{ project.pi.username }}</td>
8587
<td style="text-align: justify; text-justify: inter-word;"><strong>Title: </strong> {{ project.title }}
8688
<br> <strong>Description: </strong>{{ project.description }}</td>
87-
<td>{{ project.field_of_science.description }}</td>
89+
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
90+
<td>{{ project.field_of_science.description }}</td>
91+
{% endif %}
8892
<td>{{ project.status.name }}</td>
8993
{% if PROJECT_INSTITUTION_EMAIL_MAP %}
9094
<p class="card-text text-justify"><strong>Institution: </strong>{{ project.institution }}</p>

coldfront/core/project/templates/project/project_create_form.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
{% block content %}
1212
<form method="post">
1313
{% csrf_token %}
14-
{{ form|crispy }}
14+
{% crispy form form.helper %}
1515
<input class="btn btn-primary" type="submit" value="Save" />
1616
<a class="btn btn-secondary" href="{% url 'project-list' %}" role="button">Cancel</a>
1717
</form>
1818

19+
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
1920
<script>
2021
$(document).ready(function() {
2122
$('#id_field_of_science').select2();
2223
});
2324
</script>
25+
{% endif %}
26+
2427
{% endblock %}
28+

coldfront/core/project/templates/project/project_detail.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ <h3 class="card-title">
7575
{% else %}
7676
<p class="card-text text-justify"><strong>ID: </strong>{{ project.id }}</p>
7777
{% endif %}
78-
<p class="card-text text-justify"><strong>Field of Science: </strong>{{ project.field_of_science }}</p>
78+
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
79+
<p class="card-text text-justify"><strong>Field of Science: </strong>{{ project.field_of_science }}</p>
80+
{% endif %}
7981
<p class="card-text text-justify"><strong>Project Status: </strong>{{ project.status }}
8082
{% if project.last_project_review and project.last_project_review.status.name == 'Pending'%}
8183
<span class="badge badge-pill badge-info">project review pending</span>

coldfront/core/project/templates/project/project_list.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h2>Projects</h2>
3434
<div id="collapseOne" class="collapse {{expand_accordion}}" data-parent="#accordion">
3535
<div class="card-body">
3636
<form id="filter_form" method="GET" action="{% url 'project-list' %}" autocomplete="off">
37-
{{ project_search_form|crispy }}
37+
{% crispy project_search_form project_search_form.helper %}
3838
<input type="submit" class="btn btn-primary" value="Search">
3939
<button id="form_reset_button" type="button" class="btn btn-secondary">Reset</button>
4040
</form>
@@ -61,11 +61,13 @@ <h2>Projects</h2>
6161
<a href="?order_by=pi__username&direction=des&{{filter_parameters}}"><i class="fas fa-sort-down" aria-hidden="true"></i><span class="sr-only">Sort PI desc</span></a>
6262
</th>
6363
<th scope="col">Title</th>
64-
<th scope="col" class="text-nowrap">
65-
Field of Science
66-
<a href="?order_by=field_of_science&direction=asc&{{filter_parameters}}"><i class="fas fa-sort-up" aria-hidden="true"></i><span class="sr-only">Sort Field of Science asc</span></a>
67-
<a href="?order_by=field_of_science&direction=des&{{filter_parameters}}"><i class="fas fa-sort-down" aria-hidden="true"></i><span class="sr-only">Sort Field of Science desc</span></a>
68-
</th>
64+
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
65+
<th scope="col" class="text-nowrap">
66+
Field of Science
67+
<a href="?order_by=field_of_science&direction=asc&{{filter_parameters}}"><i class="fas fa-sort-up" aria-hidden="true"></i><span class="sr-only">Sort Field of Science asc</span></a>
68+
<a href="?order_by=field_of_science&direction=des&{{filter_parameters}}"><i class="fas fa-sort-down" aria-hidden="true"></i><span class="sr-only">Sort Field of Science desc</span></a>
69+
</th>
70+
{% endif %}
6971
<th scope="col" class="text-nowrap">
7072
Status
7173
<a href="?order_by=status&direction=asc&{{filter_parameters}}"><i class="fas fa-sort-up" aria-hidden="true"></i><span class="sr-only">Sort Status asc</span></a>
@@ -90,7 +92,9 @@ <h2>Projects</h2>
9092
{% endif %}
9193
<td>{{ project.pi.username }}</td>
9294
<td style="text-align: justify; text-justify: inter-word;">{{ project.title }}</td>
93-
<td>{{ project.field_of_science.description }}</td>
95+
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
96+
<td>{{ project.field_of_science.description }}</td>
97+
{% endif %}
9498
<td>{{ project.status.name }}</td>
9599
{% if PROJECT_INSTITUTION_EMAIL_MAP %}
96100
<td>{{ project.institution }}</td>

0 commit comments

Comments
 (0)