Skip to content
Snippets Groups Projects
Commit 75e723b6 authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Introduce static file compression

Add compressor and sass compiler dependencies
Introduce corresponding settings
Use compressor in templates
Move only partially used dependencies to higher level for better re-usability
Add custom tags to create css and js for fontawesome separately
This implements the first part of #162
parent 0a247a3d
No related branches found
No related tags found
No related merge requests found
...@@ -4,14 +4,6 @@ ...@@ -4,14 +4,6 @@
{% load i18n %} {% load i18n %}
{% load static %} {% load static %}
{% block imports %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'AKDashboard/style.css' %}">
{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
<li class="breadcrumb-item">AKPlanning</li> <li class="breadcrumb-item">AKPlanning</li>
{% endblock %} {% endblock %}
......
...@@ -6,14 +6,6 @@ ...@@ -6,14 +6,6 @@
{% load tags_AKModel %} {% load tags_AKModel %}
{% load tz %} {% load tz %}
{% block imports %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'AKDashboard/style.css' %}">
{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
<li class="breadcrumb-item"><a href="{% url 'dashboard:dashboard' %}">AKPlanning</a></li> <li class="breadcrumb-item"><a href="{% url 'dashboard:dashboard' %}">AKPlanning</a></li>
<li class="breadcrumb-item active">{{ event }}</li> <li class="breadcrumb-item active">{{ event }}</li>
......
...@@ -6,14 +6,6 @@ ...@@ -6,14 +6,6 @@
{% load tags_AKModel %} {% load tags_AKModel %}
{% block imports %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'AKDashboard/style.css' %}">
{% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
<li class="breadcrumb-item"> <li class="breadcrumb-item">
{% if 'AKDashboard'|check_app_installed %} {% if 'AKDashboard'|check_app_installed %}
......
from django import template from django import template
from django.apps import apps from django.apps import apps
from django.conf import settings from django.conf import settings
from django.utils.html import format_html, mark_safe, conditional_escape
from django.templatetags.static import static
from fontawesome_6.app_settings import get_css
register = template.Library() register = template.Library()
...@@ -39,3 +42,19 @@ def wiki_owners_export(owners, event): ...@@ -39,3 +42,19 @@ def wiki_owners_export(owners, event):
return str(owner) return str(owner)
return ", ".join(to_link(owner) for owner in owners.all()) return ", ".join(to_link(owner) for owner in owners.all())
css = get_css()
@register.simple_tag
def fontawesome_6_css():
return mark_safe(conditional_escape('\n').join(format_html(
'<link href="{}" rel="stylesheet" media="all">', stylesheet) for stylesheet in css))
@register.simple_tag
def fontawesome_6_js():
return mark_safe(format_html(
'<script type="text/javascript" src="{}"></script>', static('fontawesome_6/js/django-fontawesome.js')
))
\ No newline at end of file
{% load compress %}
{% load static %} {% load static %}
{% load i18n %} {% load i18n %}
{% load django_bootstrap5 %} {% load django_bootstrap5 %}
...@@ -14,12 +15,17 @@ ...@@ -14,12 +15,17 @@
<title>{% block title %}AK Planning{% endblock %}</title> <title>{% block title %}AK Planning{% endblock %}</title>
{# Load Bootstrap CSS and JavaScript as well as font awesome #} {# Load Bootstrap CSS and JavaScript as well as font awesome #}
{% compress css %}
{% bootstrap_css %} {% bootstrap_css %}
{% fontawesome_6_css %}
<link rel="stylesheet" href="{% static 'common/css/custom.css' %}">
{% endcompress %}
{% compress js %}
{% bootstrap_javascript %} {% bootstrap_javascript %}
<script src="{% static 'common/vendor/jquery/jquery-3.6.3.min.js' %}"></script> <script src="{% static 'common/vendor/jquery/jquery-3.6.3.min.js' %}"></script>
{% fontawesome_6_static %} {% fontawesome_6_js %}
{% endcompress %}
<link rel="stylesheet" href="{% static 'common/css/custom.css' %}">
{% include "AKModel/load_fullcalendar.html" %} {% include "AKModel/load_fullcalendar.html" %}
......
...@@ -54,9 +54,11 @@ INSTALLED_APPS = [ ...@@ -54,9 +54,11 @@ INSTALLED_APPS = [
'registration', 'registration',
'bootstrap_datepicker_plus', 'bootstrap_datepicker_plus',
'django_tex', 'django_tex',
'compressor',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
'django.middleware.gzip.GZipMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
...@@ -162,6 +164,12 @@ STATICFILES_DIRS = ( ...@@ -162,6 +164,12 @@ STATICFILES_DIRS = (
'static_common', 'static_common',
) )
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
# Settings for Bootstrap # Settings for Bootstrap
BOOTSTRAP5 = { BOOTSTRAP5 = {
# Use custom CSS # Use custom CSS
...@@ -177,6 +185,22 @@ BOOTSTRAP5 = { ...@@ -177,6 +185,22 @@ BOOTSTRAP5 = {
FONTAWESOME_6_CSS_URL = STATIC_URL + "fontawesomefree/css/all.min.css" FONTAWESOME_6_CSS_URL = STATIC_URL + "fontawesomefree/css/all.min.css"
FONTAWESOME_6_PREFIX = "fa" FONTAWESOME_6_PREFIX = "fa"
# Compressor and minifier config
COMPRESS_ENABLED = True
COMPRESS_CSS_HASHING_METHOD = 'content'
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'django_libsass.SassCompiler'),
)
COMPRESS_FILTERS = {
'css': [
'compressor.filters.css_default.CssAbsoluteFilter',
'compressor.filters.cssmin.rCSSMinFilter',
],
'js': [
'compressor.filters.jsmin.JSMinFilter',
]
}
# Treat wishes as seperate category in submission views? # Treat wishes as seperate category in submission views?
WISHES_AS_CATEGORY = True WISHES_AS_CATEGORY = True
......
...@@ -29,11 +29,6 @@ ...@@ -29,11 +29,6 @@
</style> </style>
{% include "AKSubmission/ak_interest_script.html" %} {% include "AKSubmission/ak_interest_script.html" %}
{% if event.active %}
<link href="{% static 'common/vendor/select2/select2.min.css' %}" rel="stylesheet" />
<script src="{% static 'common/vendor/select2/select2.min.js' %}"></script>
{% endif %}
{% endblock %} {% endblock %}
{% block breadcrumbs %} {% block breadcrumbs %}
......
...@@ -9,9 +9,6 @@ ...@@ -9,9 +9,6 @@
{% block title %}{% trans "AKs" %}: {{ event.name }} - {% trans "New AK" %}{% endblock %} {% block title %}{% trans "AKs" %}: {{ event.name }} - {% trans "New AK" %}{% endblock %}
{% block imports %} {% block imports %}
<link rel="stylesheet" href="{% static 'common/vendor/chosen-js/chosen.css' %}">
<link rel="stylesheet" href="{% static 'common/css/bootstrap-chosen.css' %}">
{% include "AKModel/load_fullcalendar_availabilities.html" %} {% include "AKModel/load_fullcalendar_availabilities.html" %}
<script> <script>
......
...@@ -11,5 +11,7 @@ django-debug-toolbar==3.8.1 ...@@ -11,5 +11,7 @@ django-debug-toolbar==3.8.1
django-bootstrap-datepicker-plus==5.0.2 django-bootstrap-datepicker-plus==5.0.2
django-tex==1.1.10 django-tex==1.1.10
django-csp==3.7 django-csp==3.7
django-compressor==4.1
django-libsass==0.9
mysqlclient==2.1.1 # for production deployment mysqlclient==2.1.1 # for production deployment
tzdata==2022.7 tzdata==2022.7
{% load compress %}
{% load static %} {% load static %}
{% load i18n %} {% load i18n %}
{% load django_bootstrap5 %} {% load django_bootstrap5 %}
...@@ -13,12 +14,24 @@ ...@@ -13,12 +14,24 @@
<title>{% block title %}AK Planning{% endblock %}</title> <title>{% block title %}AK Planning{% endblock %}</title>
<!-- Load bootstrap, jquery and fontawesome--> <!-- Load bootstrap, jquery and fontawesome-->
{% compress css %}
{% bootstrap_css %} {% bootstrap_css %}
<link rel="stylesheet" href="{% static 'common/vendor/chosen-js/chosen.css' %}">
<link rel="stylesheet" href="{% static 'common/css/bootstrap-chosen.css' %}">
{% if 'AKDashboard'|check_app_installed %}
<link rel="stylesheet" href="{% static 'AKDashboard/style.css' %}">
{% endif %}
<link href="{% static 'common/vendor/select2/select2.min.css' %}" rel="stylesheet" />
{% fontawesome_6_css %}
<link rel="stylesheet" href="{% static 'common/css/custom.css' %}">
{% endcompress %}
{% compress js %}
{% bootstrap_javascript %} {% bootstrap_javascript %}
<script src="{% static 'common/vendor/jquery/jquery-3.6.3.min.js' %}"></script> <script src="{% static 'common/vendor/jquery/jquery-3.6.3.min.js' %}"></script>
{% fontawesome_6_static %} <script src="{% static 'common/vendor/select2/select2.min.js' %}"></script>
{% fontawesome_6_js %}
<link rel="stylesheet" href="{% static 'common/css/custom.css' %}"> {% endcompress %}
<script type='text/javascript'> <script type='text/javascript'>
var changed_form = false; var changed_form = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment