Skip to content

Commit

Permalink
Let Bloom users choose whether to see bloom NOFOs or all NOFOs
Browse files Browse the repository at this point in the history
Add a "group" selector to the NOFO index page for Bloom users.
  • Loading branch information
pcraig3 committed Sep 23, 2024
1 parent c520532 commit a76829d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- Add "#" to beginning of ids
- Add uswds JavaScript files to the base theme file (not the NOFO theme file)
- The motivation for this is so that we can get tooltips to work
- Add a group filter ("Bloom/All") for Bloom users on NOFO index

### Changed

Expand Down
20 changes: 15 additions & 5 deletions bloom_nofos/nofos/templates/nofos/nofo_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,32 @@
{% load tz %}

{% block title %}
All NOFOs
{{ nofo_group|title }}{% if nofo_status and nofo_status != 'all' %} {{ nofo_status }}{% endif %} NOFOs
{% endblock %}

{% block body_class %}nofo_index{% endblock %}

{% block content %}
{% include "includes/alerts.html" with messages=messages success_heading="NOFO imported successfully" error_heading="NOFO deleted" only %}

<h1 class="font-heading-xl margin-y-0">All{% if nofo_status and nofo_status != 'all' %} {{ nofo_status }}{% endif %} NOFOs</h1>
<h1 class="font-heading-xl margin-y-0">{{ nofo_group|title }}{% if nofo_status and nofo_status != 'all' %} {{ nofo_status }}{% endif %} NOFOs</h1>

<p class="nofo_index--filter">
<a href="{% url 'nofos:nofo_index' %}?status=all" {% if nofo_status == 'all' %}aria-current="page"{% endif %}>All NOFOs</a> |
<a href="{% url 'nofos:nofo_index' %}" {% if not nofo_status or nofo_status == 'unpublished' %}aria-current="page"{% endif %}>All unpublished NOFOs</a> |
<a href="{% url 'nofos:nofo_index' %}?status=published" {% if nofo_status == 'published' %}aria-current="page"{% endif %}>All published NOFOs</a>
<a href="{% url 'nofos:nofo_index' %}?status=all&group={{ nofo_group }}" {% if nofo_status == 'all' %}aria-current="page"{% endif %}>{{ nofo_group|title }} NOFOs</a> |
<a href="{% url 'nofos:nofo_index' %}?group={{ nofo_group }}" {% if not nofo_status or nofo_status == 'unpublished' %}aria-current="page"{% endif %}>{{ nofo_group|title }} unpublished NOFOs</a> |
<a href="{% url 'nofos:nofo_index' %}?status=published&group={{ nofo_group }}" {% if nofo_status == 'published' %}aria-current="page"{% endif %}>All{% if nofo_group != 'all' %} {{ nofo_group|title }}{% endif %} published NOFOs</a>
</p>

{% if user.group == 'bloom' %}
<p class="nofo_index--filter">
<label class="usa-label display-inline-block font-sans-md margin-top-0" for="group-filter">Nofo Group:</label>
<select class="usa-select border-2px width-auto display-inline-block margin-top-0" name="group-filter" id="group-filter" onchange="location = this.value;">
<option value="{% url 'nofos:nofo_index' %}?status={{ nofo_status }}&group=bloom" {% if nofo_group == 'bloom' %}selected{% endif %}>Bloom</option>
<option value="{% url 'nofos:nofo_index' %}?status={{ nofo_status }}&group=all" {% if nofo_group == 'all' %}selected{% endif %}>All</option>
</select>
</p>
{% endif %}

{% if nofo_list %}
<table class="sortable usa-table usa-table--borderless width-full">
<caption>
Expand Down
13 changes: 12 additions & 1 deletion bloom_nofos/nofos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def get_queryset(self):

# default status: return unpublished NOFOs
self.status = self.request.GET.get("status", "unpublished")
# default group: 'all' nofos unless a bloom user. if bloom user, default to 'bloom'
self.group = self.request.GET.get(
"group", "bloom" if self.request.user.group == "bloom" else "all"
)

if self.status:
if self.status == "unpublished":
Expand All @@ -108,6 +112,12 @@ def get_queryset(self):
else:
queryset = queryset.filter(status=self.status)

# Apply group filter for Bloom users, doesn't apply to anyone else
if self.request.user.group == "bloom":
# Only "bloom" is actually used to filter
if self.group == "bloom":
queryset = queryset.filter(group="bloom")

# Filter NOFOs by the user's group unless they are 'bloom' users
user_group = self.request.user.group
if user_group != "bloom":
Expand All @@ -118,7 +128,8 @@ def get_queryset(self):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["today_m_j"] = dateformat.format(timezone.now(), "M j")
context["nofo_status"] = self.status # Add the status to the context
context["nofo_status"] = self.status
context["nofo_group"] = self.group
return context


Expand Down

0 comments on commit a76829d

Please sign in to comment.