diff --git a/AKDashboard/templates/AKDashboard/dashboard.html b/AKDashboard/templates/AKDashboard/dashboard.html index 7086854eae943162b2939758ad026035df0ecaae..48925af37dac792918c2952f3f7a22c182563bea 100644 --- a/AKDashboard/templates/AKDashboard/dashboard.html +++ b/AKDashboard/templates/AKDashboard/dashboard.html @@ -4,14 +4,6 @@ {% load i18n %} {% load static %} -{% block imports %} - - {{ block.super }} - - <link rel="stylesheet" href="{% static 'AKDashboard/style.css' %}"> - -{% endblock %} - {% block breadcrumbs %} <li class="breadcrumb-item">AKPlanning</li> {% endblock %} diff --git a/AKDashboard/templates/AKDashboard/dashboard_event.html b/AKDashboard/templates/AKDashboard/dashboard_event.html index 4a4726a951a641b503677d81bbac49531a89105a..626ca4b0bfcb4e171bbd1883ff3393867c495ed7 100644 --- a/AKDashboard/templates/AKDashboard/dashboard_event.html +++ b/AKDashboard/templates/AKDashboard/dashboard_event.html @@ -6,14 +6,6 @@ {% load tags_AKModel %} {% load tz %} -{% block imports %} - - {{ block.super }} - - <link rel="stylesheet" href="{% static 'AKDashboard/style.css' %}"> - -{% endblock %} - {% block breadcrumbs %} <li class="breadcrumb-item"><a href="{% url 'dashboard:dashboard' %}">AKPlanning</a></li> <li class="breadcrumb-item active">{{ event }}</li> diff --git a/AKModel/templates/AKModel/user.html b/AKModel/templates/AKModel/user.html index 47ccc35a5baec32a35071394a4709e7e846f70fd..b18b0cb983346856c677effa8be8a5b1ca31c255 100644 --- a/AKModel/templates/AKModel/user.html +++ b/AKModel/templates/AKModel/user.html @@ -6,14 +6,6 @@ {% load tags_AKModel %} -{% block imports %} - - {{ block.super }} - - <link rel="stylesheet" href="{% static 'AKDashboard/style.css' %}"> - -{% endblock %} - {% block breadcrumbs %} <li class="breadcrumb-item"> {% if 'AKDashboard'|check_app_installed %} diff --git a/AKModel/templatetags/tags_AKModel.py b/AKModel/templatetags/tags_AKModel.py index 3bec0320f9f0be2c909ca9fbd758f02d59268d3c..06560dc7d056573ffed1d1825c560c99d513237e 100644 --- a/AKModel/templatetags/tags_AKModel.py +++ b/AKModel/templatetags/tags_AKModel.py @@ -1,6 +1,9 @@ from django import template from django.apps import apps 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() @@ -39,3 +42,19 @@ def wiki_owners_export(owners, event): return str(owner) 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 diff --git a/AKPlan/templates/AKPlan/plan_wall.html b/AKPlan/templates/AKPlan/plan_wall.html index 717c7ffd96d1a22e0129fa7bfb7e9c7512f0dc8f..0e20819d4774baf51689c8b0a8bad4f126ae407a 100644 --- a/AKPlan/templates/AKPlan/plan_wall.html +++ b/AKPlan/templates/AKPlan/plan_wall.html @@ -1,3 +1,4 @@ +{% load compress %} {% load static %} {% load i18n %} {% load django_bootstrap5 %} @@ -14,12 +15,17 @@ <title>{% block title %}AK Planning{% endblock %}</title> {# Load Bootstrap CSS and JavaScript as well as font awesome #} - {% bootstrap_css %} - {% bootstrap_javascript %} - <script src="{% static 'common/vendor/jquery/jquery-3.6.3.min.js' %}"></script> - {% fontawesome_6_static %} - - <link rel="stylesheet" href="{% static 'common/css/custom.css' %}"> + {% compress css %} + {% bootstrap_css %} + {% fontawesome_6_css %} + <link rel="stylesheet" href="{% static 'common/css/custom.css' %}"> + {% endcompress %} + + {% compress js %} + {% bootstrap_javascript %} + <script src="{% static 'common/vendor/jquery/jquery-3.6.3.min.js' %}"></script> + {% fontawesome_6_js %} + {% endcompress %} {% include "AKModel/load_fullcalendar.html" %} diff --git a/AKPlanning/settings.py b/AKPlanning/settings.py index 5c416d92063c84f50a4bc5ca7011f7bb47b1e872..1c306397718eab594f32d7b1a2423e9d45b3eae6 100644 --- a/AKPlanning/settings.py +++ b/AKPlanning/settings.py @@ -54,9 +54,11 @@ INSTALLED_APPS = [ 'registration', 'bootstrap_datepicker_plus', 'django_tex', + 'compressor', ] MIDDLEWARE = [ + 'django.middleware.gzip.GZipMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -162,6 +164,12 @@ STATICFILES_DIRS = ( 'static_common', ) +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'compressor.finders.CompressorFinder', +) + # Settings for Bootstrap BOOTSTRAP5 = { # Use custom CSS @@ -177,6 +185,22 @@ BOOTSTRAP5 = { FONTAWESOME_6_CSS_URL = STATIC_URL + "fontawesomefree/css/all.min.css" 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? WISHES_AS_CATEGORY = True diff --git a/AKSubmission/templates/AKSubmission/submission_overview.html b/AKSubmission/templates/AKSubmission/submission_overview.html index 43a59ed143605c4b3e5cd6798b52855928900d4d..41518c814708dbc33c84ea3665cbd716d179d876 100644 --- a/AKSubmission/templates/AKSubmission/submission_overview.html +++ b/AKSubmission/templates/AKSubmission/submission_overview.html @@ -29,11 +29,6 @@ </style> {% 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 %} {% block breadcrumbs %} diff --git a/AKSubmission/templates/AKSubmission/submit_new.html b/AKSubmission/templates/AKSubmission/submit_new.html index 1b0d94b20d38d45a1589ca8ac50f23dc7c9e5321..b2c3a2ca18b1b665cceb08131a1db71ce6ef16b1 100644 --- a/AKSubmission/templates/AKSubmission/submit_new.html +++ b/AKSubmission/templates/AKSubmission/submit_new.html @@ -9,9 +9,6 @@ {% block title %}{% trans "AKs" %}: {{ event.name }} - {% trans "New AK" %}{% endblock %} {% 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" %} <script> diff --git a/requirements.txt b/requirements.txt index edd6ea90d5ebe899d60e19400861ced434ffffb5..43194a7d775cb80054a7ca31e24bbd3e81707b35 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,5 +11,7 @@ django-debug-toolbar==3.8.1 django-bootstrap-datepicker-plus==5.0.2 django-tex==1.1.10 django-csp==3.7 +django-compressor==4.1 +django-libsass==0.9 mysqlclient==2.1.1 # for production deployment tzdata==2022.7 diff --git a/templates/base.html b/templates/base.html index 34ebb647532f87f1ebfe234f3fb075d078ae50e8..38e00fe53fc506bb1a4f0b5416c0843c97e7fe58 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,3 +1,4 @@ +{% load compress %} {% load static %} {% load i18n %} {% load django_bootstrap5 %} @@ -13,12 +14,24 @@ <title>{% block title %}AK Planning{% endblock %}</title> <!-- Load bootstrap, jquery and fontawesome--> - {% bootstrap_css %} - {% bootstrap_javascript %} - <script src="{% static 'common/vendor/jquery/jquery-3.6.3.min.js' %}"></script> - {% fontawesome_6_static %} - - <link rel="stylesheet" href="{% static 'common/css/custom.css' %}"> + {% compress 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 %} + <script src="{% static 'common/vendor/jquery/jquery-3.6.3.min.js' %}"></script> + <script src="{% static 'common/vendor/select2/select2.min.js' %}"></script> + {% fontawesome_6_js %} + {% endcompress %} <script type='text/javascript'> var changed_form = false;