Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to show site-wide banner announcements #517

Merged
merged 3 commits into from
Mar 22, 2024
Merged
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
13 changes: 13 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"dal_select2",
"fontawesomefree",
"simple_history",
"constance",
]

LOCAL_APPS = [
Expand Down Expand Up @@ -198,6 +199,7 @@
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"constance.context_processors.config",
"gregor_django.utils.context_processors.settings_context",
],
},
Expand Down Expand Up @@ -362,6 +364,17 @@
# https://django-tables2.readthedocs.io/en/latest/pages/custom-rendering.html?highlight=django_tables2_template#available-templates
DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap5.html"

# django-constance
# ------------------------------------------------------------------------------
CONSTANCE_CONFIG = {
"ANNOUNCEMENT_TEXT": ("", "Site-wide announcement message", str),
}

CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend"
CONSTANCE_IGNORE_ADMIN_VERSION_CHECK = True
# CONSTANCE_DATABASE_CACHE_BACKEND = "default"
CONSTANCE_DATABASE_CACHE_AUTOFILL_TIMEOUT = None

# django-anvil-consortium-manager
# ------------------------------------------------------------------------------
# Specify the path to the service account to use for managing access on AnVIL.
Expand Down
21 changes: 21 additions & 0 deletions gregor_django/gregor_anvil/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from anvil_consortium_manager.models import AnVILProjectManagerAccess
from anvil_consortium_manager.tests import factories as acm_factories
from anvil_consortium_manager.tests.utils import AnVILAPIMockTestMixin
from constance.test import override_config
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
Expand Down Expand Up @@ -96,6 +97,26 @@ def test_acm_link_with_edit_but_not_view_permission(self):
reverse("anvil_consortium_manager:index"), response.rendered_content
)

def test_site_announcement_no_text(self):
user = User.objects.create_user(username="test-none", password="test-none")
self.client.force_login(user)
response = self.client.get(self.get_url())
self.assertNotContains(response, """id="alert-announcement""")

@override_config(ANNOUNCEMENT_TEXT="This is a test announcement")
def test_site_announcement_text(self):
user = User.objects.create_user(username="test-none", password="test-none")
self.client.force_login(user)
response = self.client.get(self.get_url())
self.assertContains(response, """id="alert-announcement""")
self.assertContains(response, "This is a test announcement")

@override_config(ANNOUNCEMENT_TEXT="This is a test announcement")
def test_site_announcement_text_unauthenticated_user(self):
response = self.client.get(self.get_url(), follow=True)
self.assertContains(response, """id="alert-announcement""")
self.assertContains(response, "This is a test announcement")


class ConsentGroupDetailTest(TestCase):
"""Tests for the ConsentGroupDetail view."""
Expand Down
13 changes: 11 additions & 2 deletions gregor_django/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,26 @@
</div>
</nav>

{% block extra_navbar %}
{% endblock %}
<main class="flex-shrink-0">
<div class="container">

{% if config.ANNOUNCEMENT_TEXT %}
<div class="alert alert-info my-3" role="alert" id="alert-announcement">
<i class="bi bi-megaphone-fill me-1"></i>
{{ config.ANNOUNCEMENT_TEXT }}
</div>
{% endif %}

{% if messages %}
{% for message in messages %}
<div class="alert {% if message.tags %}alert-{{ message.tags }}{% endif %} alert-dismissible fade show" role="alert">{{ message }}<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>
{% endfor %}
{% endif %}

{% block extra_navbar %}
{% endblock %}


{% block content %}

<div class="my-3 alert alert-warning" role="alert">
Expand Down
4 changes: 4 additions & 0 deletions requirements/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ certifi>=2023.7.22
pyjwt>=2.4.0
urllib3>=1.26.18
sqlparse>=0.4.4

# Dynamic settings
django-constance
django-picklefield # Required by django-constance for database backend
7 changes: 7 additions & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ django==4.2.11
# django-extensions
# django-filter
# django-model-utils
# django-picklefield
# django-tables2
django-allauth==0.54.0
# via -r requirements/requirements.in
django-anvil-consortium-manager @ git+https://github.com/UW-GAC/[email protected]
# via -r requirements/requirements.in
django-autocomplete-light==3.11.0
# via django-anvil-consortium-manager
django-constance==3.1.0
# via -r requirements/requirements.in
django-crispy-forms==2.1
# via
# -r requirements/requirements.in
Expand All @@ -79,6 +82,10 @@ django-maintenance-mode==0.21.1
# via -r requirements/requirements.in
django-model-utils==4.4.0
# via -r requirements/requirements.in
django-picklefield==3.1
# via
# -r requirements/requirements.in
# django-constance
django-simple-history==3.5.0
# via
# -r requirements/requirements.in
Expand Down
Loading