Skip to content
Snippets Groups Projects
Commit acac2646 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[ui][widgets] Refactor version fingerprinting

This ensure that fingerprint doesn't get encoded as it is
only used to ensure the latest version is served from the cache.
parent efec99a5
No related branches found
No related tags found
2 merge requests!2551.4.x,!254Refactor version fingerprinting for code mirror widgets
Pipeline #24562 passed
...@@ -125,6 +125,20 @@ class CodeMirrorJSONEncoder(json.JSONEncoder): ...@@ -125,6 +125,20 @@ class CodeMirrorJSONEncoder(json.JSONEncoder):
self.stash = {} self.stash = {}
return encoded return encoded
class FingerPrintedMedia(forms.Media):
"""Subclass that adds version fingerprinting to the Media urls
"""
def absolute_path(self, path):
"""Reimplementation to add version fingerprint to ensure file is served
for the latest version of the application
"""
abs_path = super(FingerPrintedMedia, self).absolute_path(path)
abs_path += '?v={}'.format(__version__)
return abs_path
class CodeMirrorTextarea(forms.Textarea): class CodeMirrorTextarea(forms.Textarea):
u"""Textarea widget render with `CodeMirror` u"""Textarea widget render with `CodeMirror`
...@@ -167,13 +181,8 @@ class CodeMirrorTextarea(forms.Textarea): ...@@ -167,13 +181,8 @@ class CodeMirrorTextarea(forms.Textarea):
"%s/addon/fold/foldgutter.css" % CODEMIRROR_PATH, "%s/addon/fold/foldgutter.css" % CODEMIRROR_PATH,
) )
# adds version fingerprinting to javascript/css files return FingerPrintedMedia(css={'all': css}, js=js)
js = ['%s?v=%s' % (k, __version__) for k in js]
css = ['%s?v=%s' % (k, __version__) for k in css]
return forms.Media(css={'all': css},
js=js
)
def __init__( def __init__(
self, attrs=None, mode=None, theme=None, config=None, size=None, self, attrs=None, mode=None, theme=None, config=None, size=None,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment