Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bryan BRANCOTTE
django-basetheme-bootstrap
Commits
ff25747d
Commit
ff25747d
authored
Sep 02, 2019
by
Bryan BRANCOTTE
Browse files
keep in cache the url computed for sstatic
parent
30bc2dc6
Pipeline
#14211
passed with stage
in 29 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
basetheme_bootstrap/templates/basetheme_bootstrap/basePasteur.html
View file @
ff25747d
<!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=
"{%
s
static '/css/bootstrap-multiselect.css' %}"
type=
"text/css"
/>
<link
rel=
"stylesheet"
href=
"{%
s
static '/css/basetheme_bootstrap4_pasteur.css' %}"
/>
<link
rel=
"stylesheet"
href=
"{%
s
static '/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=
"{%
s
static '/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=
"{%
s
static '/js/basetheme_bootstrap.js' %}"
></script>
{% block extra_js %}{% endblock %}
</html>
basetheme_bootstrap/templatetags/sstatic.py
View file @
ff25747d
...
...
@@ -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
)))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment