From 75418baf06545d18353a4763a6f3ca24ea0811bd Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Tue, 9 Feb 2021 18:00:56 +0100 Subject: [PATCH] apply cachebuster for form --- owrx/form/gfx.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/owrx/form/gfx.py b/owrx/form/gfx.py index 8970f2e8..95b4e6e5 100644 --- a/owrx/form/gfx.py +++ b/owrx/form/gfx.py @@ -1,8 +1,9 @@ from abc import ABCMeta, abstractmethod from owrx.form import Input +from datetime import datetime -# TODO: cachebuster +# TODO: ability to restore the original image class ImageInput(Input, metaclass=ABCMeta): def render_input(self, value): return """ @@ -14,10 +15,14 @@ class ImageInput(Input, metaclass=ABCMeta): """.format( - id=self.id, - label=self.label, - url=self.getUrl(), - classes=" ".join(self.getImgClasses()) + id=self.id, label=self.label, url=self.cachebuster(self.getUrl()), classes=" ".join(self.getImgClasses()) + ) + + def cachebuster(self, url: str): + return "{url}{separator}cb={cachebuster}".format( + url=url, + cachebuster=datetime.now().timestamp(), + separator="&" if "?" in url else "?", ) @abstractmethod