diff --git a/basetheme_bootstrap/templates/basetheme_bootstrap/basePasteur.html b/basetheme_bootstrap/templates/basetheme_bootstrap/basePasteur.html index 907ae081dc597125c7969559a81c5e983ec5fbac..c121f1d11e15d0112b8e6d62a23f19f37b04ef62 100644 --- a/basetheme_bootstrap/templates/basetheme_bootstrap/basePasteur.html +++ b/basetheme_bootstrap/templates/basetheme_bootstrap/basePasteur.html @@ -1,5 +1,4 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -{% load static %} {% load sstatic %} {% load basetheme_bootstrap %} {% load i18n %} @@ -19,9 +18,9 @@ <link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/10.0.0/css/bootstrap-slider.min.css"/> - <link rel="stylesheet" href="{% static '/css/bootstrap-multiselect.css' %}" type="text/css"/> - <link rel="stylesheet" href="{% static '/css/basetheme_bootstrap4_pasteur.css' %}"/> - <link rel="stylesheet" href="{% static '/css/fonts.css' %}"/> + <link rel="stylesheet" href="{% sstatic '/css/bootstrap-multiselect.css' %}" type="text/css"/> + <link rel="stylesheet" href="{% sstatic '/css/basetheme_bootstrap4_pasteur.css' %}"/> + <link rel="stylesheet" href="{% sstatic '/css/fonts.css' %}"/> {% block extra_css %}{% endblock %} </head> <body class="d-flex flex-column h-100"> @@ -187,12 +186,12 @@ <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script> <script src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script> <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.flash.min.js"></script> -<script type="text/javascript" src="{% static '/js/bootstrap-multiselect.js' %}"></script> +<script type="text/javascript" src="{% sstatic '/js/bootstrap-multiselect.js' %}"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script> <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script> <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js"></script> -<script src="{% static '/js/basetheme_bootstrap.js' %}"></script> +<script src="{% sstatic '/js/basetheme_bootstrap.js' %}"></script> {% block extra_js %}{% endblock %} </html> diff --git a/basetheme_bootstrap/templatetags/sstatic.py b/basetheme_bootstrap/templatetags/sstatic.py index 4bfe37c4f77773af84c1ee2a4868399c5b5d588c..861fbafb84a69ff1f87e5f8c82d454f7f66104a4 100644 --- a/basetheme_bootstrap/templatetags/sstatic.py +++ b/basetheme_bootstrap/templatetags/sstatic.py @@ -4,6 +4,7 @@ import string from django import template from django.conf import settings +from django.core.cache import cache # credits : https://bitbucket.org/ad3w/django-sstatic @@ -12,15 +13,27 @@ register = template.Library() @register.simple_tag def sstatic(path): + url = cache.get(path) + if url: + return url + url = compute_url_for_path(path) + cache.set(path, url, None) + return url + + +def compute_url_for_path(path): ''' Returns absolute URL to static file with versioning. ''' - full_path = os.path.join(settings.STATIC_ROOT, path[1:] if path[0] == '/' else path) try: + full_path = os.path.join(settings.STATIC_ROOT, path[1:] if path[0] == '/' else path) # Get file modification time. mtime = os.path.getmtime(full_path) return '%s%s?%s' % (settings.STATIC_URL[:-1], path, mtime) except OSError: - # Returns normal url if this file was not found in filesystem. - return '%s%s?%s' % (settings.STATIC_URL[:-1], path, ''.join( - random.choice(''.join((string.ascii_letters, string.digits))) for _ in range(32))) + pass + except TypeError: + pass + # Returns normal url if this file was not found in filesystem. + return '%s%s?%s' % (settings.STATIC_URL[:-1], path, ''.join( + random.choice(''.join((string.ascii_letters, string.digits))) for _ in range(4)))