From fb246434b46fbf67c95070304a54a191be30dee2 Mon Sep 17 00:00:00 2001 From: Jonas Carson Date: Thu, 21 Nov 2024 09:12:24 -0800 Subject: [PATCH 1/3] Update favicon for admin site. Also, because browsers will still sometimes request the favicon.ico even when it is not in use - add a redirect --- config/urls.py | 2 ++ primed/templates/admin/base_site.html | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 primed/templates/admin/base_site.html diff --git a/config/urls.py b/config/urls.py index 9b091d3f..b8d07b29 100644 --- a/config/urls.py +++ b/config/urls.py @@ -1,6 +1,7 @@ from django.conf import settings from django.conf.urls.static import static from django.contrib import admin +from django.shortcuts import redirect from django.urls import include, path from django.views import defaults as default_views from django.views.generic import TemplateView @@ -26,6 +27,7 @@ "collaborative_analysis/", include("primed.collaborative_analysis.urls", namespace="collaborative_analysis"), ), + path("favicon.ico", lambda _: redirect("static/images/favicons/primed-favicon.png", permanent=True)), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/primed/templates/admin/base_site.html b/primed/templates/admin/base_site.html new file mode 100644 index 00000000..21c0e91c --- /dev/null +++ b/primed/templates/admin/base_site.html @@ -0,0 +1,7 @@ +{% extends "admin/base_site.html" %} +{% load static %} +{% block extrahead %} + + + +{% endblock %} From 7270b00428bbdf7e642cf59c957158db760291ef Mon Sep 17 00:00:00 2001 From: Jonas Carson Date: Thu, 21 Nov 2024 09:30:27 -0800 Subject: [PATCH 2/3] Update to use a RedirectView --- config/urls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/urls.py b/config/urls.py index b8d07b29..ce11199f 100644 --- a/config/urls.py +++ b/config/urls.py @@ -1,10 +1,10 @@ from django.conf import settings from django.conf.urls.static import static from django.contrib import admin -from django.shortcuts import redirect from django.urls import include, path from django.views import defaults as default_views from django.views.generic import TemplateView +from django.views.generic.base import RedirectView urlpatterns = [ path("", TemplateView.as_view(template_name="pages/home.html"), name="home"), @@ -27,7 +27,7 @@ "collaborative_analysis/", include("primed.collaborative_analysis.urls", namespace="collaborative_analysis"), ), - path("favicon.ico", lambda _: redirect("static/images/favicons/primed-favicon.png", permanent=True)), + path("favicon.ico", RedirectView.as_view(url="/static/images/favicons/primed-favicon.png", permanent=True)), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) From c406594db5ad4370678670a2500d590dfb9d2a20 Mon Sep 17 00:00:00 2001 From: Jonas Carson Date: Thu, 21 Nov 2024 12:48:04 -0800 Subject: [PATCH 3/3] Use a better method for determining static file url. Make favicon redirect a public view --- config/settings/base.py | 1 + config/urls.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/settings/base.py b/config/settings/base.py index 3f2c24d9..7c7410a4 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -310,6 +310,7 @@ "cdsa:records:user_access", "dbgap:records:index", "dbgap:records:applications", + "favicon", ] # django-dbbackup diff --git a/config/urls.py b/config/urls.py index ce11199f..9d82035d 100644 --- a/config/urls.py +++ b/config/urls.py @@ -1,6 +1,7 @@ from django.conf import settings from django.conf.urls.static import static from django.contrib import admin +from django.templatetags.static import static as static_url_tag from django.urls import include, path from django.views import defaults as default_views from django.views.generic import TemplateView @@ -27,7 +28,11 @@ "collaborative_analysis/", include("primed.collaborative_analysis.urls", namespace="collaborative_analysis"), ), - path("favicon.ico", RedirectView.as_view(url="/static/images/favicons/primed-favicon.png", permanent=True)), + path( + "favicon.ico", + RedirectView.as_view(url=static_url_tag("images/favicons/primed-favicon.png"), permanent=True), + name="favicon", + ), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)