diff --git a/src/core/templatetags/mimetype.py b/src/core/templatetags/mimetype.py new file mode 100644 index 000000000..2703490a4 --- /dev/null +++ b/src/core/templatetags/mimetype.py @@ -0,0 +1,19 @@ +from django import template + +from core.files import file_path_mime + +register = template.Library() + + +@register.filter +def get_mime(file_field): + """ + Template tag to retrieve the MIME type of an ImageField or FileField. + If the field has no path attribute application/octet-stream is returned + as the default. + + Usage: {{ request.press.favicon|get_mime }} + """ + if file_field and hasattr(file_field, 'path'): + return file_path_mime(file_field.path) + return 'application/octet-stream' diff --git a/src/templates/admin/core/base.html b/src/templates/admin/core/base.html index 3294e516f..f6461d6a4 100644 --- a/src/templates/admin/core/base.html +++ b/src/templates/admin/core/base.html @@ -24,15 +24,7 @@ } catch (e) { } {% block css %}{% endblock %} - - {% if journal.favicon %} - - {% elif request.repository.favicon %} - - {% elif press.favicon %} - - {% endif %} - + {% include "common/elements/favicons.html" %}
diff --git a/src/templates/common/elements/favicons.html b/src/templates/common/elements/favicons.html new file mode 100644 index 000000000..f7d6011c4 --- /dev/null +++ b/src/templates/common/elements/favicons.html @@ -0,0 +1,9 @@ +{% load mimetype %} + +{% if request.journal and request.journal.favicon %} + +{% elif request.repository and request.repository.favicon %} + +{% elif request.press and request.press.favicon %} + +{% endif %} \ No newline at end of file diff --git a/src/themes/OLH/templates/core/base.html b/src/themes/OLH/templates/core/base.html index c82da378a..6233bd90f 100644 --- a/src/themes/OLH/templates/core/base.html +++ b/src/themes/OLH/templates/core/base.html @@ -42,13 +42,7 @@ {% endif %} - - {% if request.journal and journal.favicon %} - - {% elif request.press.favicon %} - - {% endif %} - + {% include "common/elements/favicons.html" %} {% include "common/elements/skip_to_main_content.html" %} diff --git a/src/themes/clean/templates/core/base.html b/src/themes/clean/templates/core/base.html index ca68ada94..85adca244 100644 --- a/src/themes/clean/templates/core/base.html +++ b/src/themes/clean/templates/core/base.html @@ -16,9 +16,7 @@ - {% if journal.favicon %} - - {% endif %} + {% include "common/elements/favicons.html" %} diff --git a/src/themes/material/templates/core/base.html b/src/themes/material/templates/core/base.html index 9de2a7f37..776be3724 100644 --- a/src/themes/material/templates/core/base.html +++ b/src/themes/material/templates/core/base.html @@ -21,11 +21,7 @@ {% endif %} - {% if request.journal.favicon %} - - {% elif request.repository.favicon %} - - {% endif %} + {% include "common/elements/favicons.html" %}