Skip to content
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
6 changes: 6 additions & 0 deletions coldfront/config/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion coldfront/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")))

Expand Down
2 changes: 2 additions & 0 deletions coldfront/core/portal/templates/portal/center_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ <h2>{% settings_value 'CENTER_NAME' %} Scientific Impact</h2>
<!-- End Grants -->
{% endif %}

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

<!-- Start Allocation Charts -->
<div class="card mb-3 border-primary">
Expand Down
21 changes: 20 additions & 1 deletion coldfront/core/portal/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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, "<!-- Start Allocation by Field of Science -->")
# sanity check for other chart
self.assertContains(response, "<!-- Start Allocation Charts -->")

@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, "<!-- Start Allocation by Field of Science -->")
# sanity check for other chart
self.assertContains(response, "<!-- Start Allocation Charts -->")
42 changes: 40 additions & 2 deletions coldfront/core/project/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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"),
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ <h3 class="card-title">
<a href="mailto:{{ project.pi.email }}"><i class="far fa-envelope" aria-hidden="true"></i><span class="sr-only">Email</span></a>
</h3>
<p class="card-text text-justify"><strong>Description: </strong>{{ project.description }}</p>
<p class="card-text text-justify"><strong>Field of Science: </strong>{{ project.field_of_science }}</p>
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
<p class="card-text text-justify"><strong>Field of Science: </strong>{{ project.field_of_science }}</p>
{% endif %}
<p class="card-text text-justify"><strong>Status: </strong>{{ project.status}}</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h2>Archived Projects</h2>
<div id="collapseOne" class="collapse {{expand_accordion}}" data-parent="#accordion">
<div class="card-body">
<form id="filter_form" method="GET" action="{% url 'project-archived-list' %}">
{{ project_search_form|crispy }}
{% crispy project_search_form project_search_form.helper %}
<input type="submit" class="btn btn-primary" value="Search">
<button id="form_reset_button" type="button" class="btn btn-secondary">Reset</button>
</form>
Expand Down Expand Up @@ -61,11 +61,13 @@ <h2>Archived Projects</h2>
<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>
</th>
<th scope="col">Title and Description</th>
<th scope="col" class="text-nowrap">
Field of Science
<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>
<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>
</th>
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
<th scope="col" class="text-nowrap">
Field of Science
<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>
<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>
</th>
{% endif %}
<th scope="col" class="text-nowrap">
Status
<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>
Expand All @@ -84,7 +86,9 @@ <h2>Archived Projects</h2>
<td>{{ project.pi.username }}</td>
<td style="text-align: justify; text-justify: inter-word;"><strong>Title: </strong> {{ project.title }}
<br> <strong>Description: </strong>{{ project.description }}</td>
<td>{{ project.field_of_science.description }}</td>
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
<td>{{ project.field_of_science.description }}</td>
{% endif %}
<td>{{ project.status.name }}</td>
{% if PROJECT_INSTITUTION_EMAIL_MAP %}
<p class="card-text text-justify"><strong>Institution: </strong>{{ project.institution }}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
{% block content %}
<form method="post">
{% csrf_token %}
{{ form|crispy }}
{% crispy form form.helper %}
<input class="btn btn-primary" type="submit" value="Save" />
<a class="btn btn-secondary" href="{% url 'project-list' %}" role="button">Cancel</a>
</form>

{% if not settings.FIELD_OF_SCIENCE_HIDE %}
<script>
$(document).ready(function() {
$('#id_field_of_science').select2();
});
</script>
{% endif %}

{% endblock %}

4 changes: 3 additions & 1 deletion coldfront/core/project/templates/project/project_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ <h3 class="card-title">
{% else %}
<p class="card-text text-justify"><strong>ID: </strong>{{ project.id }}</p>
{% endif %}
<p class="card-text text-justify"><strong>Field of Science: </strong>{{ project.field_of_science }}</p>
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
<p class="card-text text-justify"><strong>Field of Science: </strong>{{ project.field_of_science }}</p>
{% endif %}
<p class="card-text text-justify"><strong>Project Status: </strong>{{ project.status }}
{% if project.last_project_review and project.last_project_review.status.name == 'Pending'%}
<span class="badge badge-pill badge-info">project review pending</span>
Expand Down
18 changes: 11 additions & 7 deletions coldfront/core/project/templates/project/project_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h2>Projects</h2>
<div id="collapseOne" class="collapse {{expand_accordion}}" data-parent="#accordion">
<div class="card-body">
<form id="filter_form" method="GET" action="{% url 'project-list' %}" autocomplete="off">
{{ project_search_form|crispy }}
{% crispy project_search_form project_search_form.helper %}
<input type="submit" class="btn btn-primary" value="Search">
<button id="form_reset_button" type="button" class="btn btn-secondary">Reset</button>
</form>
Expand All @@ -61,11 +61,13 @@ <h2>Projects</h2>
<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>
</th>
<th scope="col">Title</th>
<th scope="col" class="text-nowrap">
Field of Science
<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>
<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>
</th>
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
<th scope="col" class="text-nowrap">
Field of Science
<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>
<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>
</th>
{% endif %}
<th scope="col" class="text-nowrap">
Status
<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>
Expand All @@ -90,7 +92,9 @@ <h2>Projects</h2>
{% endif %}
<td>{{ project.pi.username }}</td>
<td style="text-align: justify; text-justify: inter-word;">{{ project.title }}</td>
<td>{{ project.field_of_science.description }}</td>
{% if not settings.FIELD_OF_SCIENCE_HIDE %}
<td>{{ project.field_of_science.description }}</td>
{% endif %}
<td>{{ project.status.name }}</td>
{% if PROJECT_INSTITUTION_EMAIL_MAP %}
<td>{{ project.institution }}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
{% block content %}
<form method="post">
{% csrf_token %}
{{ form|crispy }}
{% crispy form form.helper %}
<input class="btn btn-primary" type="submit" value="Save" />
<a class="btn btn-secondary" href="{% url 'project-detail' object.pk %}" role="button">Cancel</a>
</form>

{% if not settings.FIELD_OF_SCIENCE_HIDE %}
<script>
$(document).ready(function() {
$('#id_field_of_science').select2();
});
</script>
{% endif %}

{% endblock %}

Loading