diff --git a/beat/web/ui/widgets.py b/beat/web/ui/widgets.py index ad67fedac945def1b19a2657475235fab2611494..0aadf7f00fb0a1743b296dfe2c8e9a34aa5cb8b3 100644 --- a/beat/web/ui/widgets.py +++ b/beat/web/ui/widgets.py @@ -125,6 +125,20 @@ class CodeMirrorJSONEncoder(json.JSONEncoder): self.stash = {} 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): u"""Textarea widget render with `CodeMirror` @@ -167,13 +181,8 @@ class CodeMirrorTextarea(forms.Textarea): "%s/addon/fold/foldgutter.css" % CODEMIRROR_PATH, ) - # adds version fingerprinting to javascript/css files - js = ['%s?v=%s' % (k, __version__) for k in js] - css = ['%s?v=%s' % (k, __version__) for k in css] + return FingerPrintedMedia(css={'all': css}, js=js) - return forms.Media(css={'all': css}, - js=js - ) def __init__( self, attrs=None, mode=None, theme=None, config=None, size=None,