details:   https://code.tryton.org/tryton/commit/769ec2410d30
branch:    default
user:      AdriĆ  Tarroja Caubet <[email protected]>
date:      Sat Oct 11 13:27:37 2025 +0200
description:
        Add a timestamp parameter to the URLs of the product images

        Closes #11456
diffstat:

 modules/product_image/CHANGELOG            |  1 +
 modules/product_image/product.py           |  7 ++++++-
 modules/product_image/tests/test_module.py |  7 +++++--
 3 files changed, 12 insertions(+), 3 deletions(-)

diffs (58 lines):

diff -r a0b571509e75 -r 769ec2410d30 modules/product_image/CHANGELOG
--- a/modules/product_image/CHANGELOG   Sat Oct 11 10:46:03 2025 +0200
+++ b/modules/product_image/CHANGELOG   Sat Oct 11 13:27:37 2025 +0200
@@ -1,3 +1,4 @@
+* Add a timestamp parameter to the URLs of the images
 
 Version 7.6.0 - 2025-04-28
 --------------------------
diff -r a0b571509e75 -r 769ec2410d30 modules/product_image/product.py
--- a/modules/product_image/product.py  Sat Oct 11 10:46:03 2025 +0200
+++ b/modules/product_image/product.py  Sat Oct 11 13:27:37 2025 +0200
@@ -1,5 +1,6 @@
 # This file is part of Tryton.  The COPYRIGHT file at the top level of
 # this repository contains the full copyright notices and license terms.
+import base64
 import io
 import math
 from urllib.parse import quote, urlencode, urljoin
@@ -62,7 +63,11 @@
                     args['h'] = height
                 if index is not None:
                     args['i'] = index
-                url += '?' + urlencode(args)
+            timestamp = int((self.write_date or self.create_date).timestamp())
+            args['t'] = (
+                base64.urlsafe_b64encode(timestamp.to_bytes(8, 'big'))
+                .decode().rstrip('='))
+            url += '?' + urlencode(args)
             return url
 
     def get_image_url(self, _external=False, **args):
diff -r a0b571509e75 -r 769ec2410d30 modules/product_image/tests/test_module.py
--- a/modules/product_image/tests/test_module.py        Sat Oct 11 10:46:03 
2025 +0200
+++ b/modules/product_image/tests/test_module.py        Sat Oct 11 13:27:37 
2025 +0200
@@ -1,5 +1,6 @@
 # This file is part of Tryton.  The COPYRIGHT file at the top level of
 # this repository contains the full copyright notices and license terms.
+import datetime as dt
 import io
 import unittest
 import urllib.request
@@ -112,12 +113,14 @@
                 'https://picsum.photos/200').read()
             image.save()
 
+        template.write_date = dt.datetime(2025, 1, 1)  # fix timestamp
+
         self.assertRegex(
             template.get_image_url(i=2),
-            r'/product/image/CODE/.*/Template\?i=2')
+            r'^/product/image/CODE/.*/Template\?i=2&t=AAAAAGd0hYA$')
         self.assertRegex(
             template.get_image_url(s=400),
-            r'/product/image/CODE/.*/Template\?s=400')
+            r'^/product/image/CODE/.*/Template\?s=400&t=AAAAAGd0hYA$')
 
 
 del ModuleTestCase

Reply via email to