Skip to content

Commit

Permalink
Merge pull request #153 from plone/fix-modified
Browse files Browse the repository at this point in the history
Fix the NamedFile modified property
  • Loading branch information
gforcada authored Oct 18, 2023
2 parents 48c5af8 + 1a75884 commit 1cd966a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/153.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix calculation of file modification time. @davisagli
2 changes: 1 addition & 1 deletion plone/namedfile/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ModifiedPropertyMixin:
@property
def modified(self):
if hasattr(self, "_modified"):
return self._modified
return self._modified / 1000
# Fall back to modification time in database.
return self._p_mtime

Expand Down
8 changes: 4 additions & 4 deletions plone/namedfile/tests/test_blobfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ def testModifiedTimeStamp(self):
image = self._makeImage()
old_timestamp = image.modified
time.sleep(1/1000) # make sure at least 1ms passes
now = DateTime()
self.assertGreater(now, DateTime(old_timestamp))
image._setData(zptlogo)
self.assertNotEqual(image.modified, old_timestamp)

def testFallBackToDatabaseModifiedTimeStamp(self):
dt = DateTime()
image = MockNamedBlobImage()
image._p_mtime = dt.millis()
image._p_mtime = int(dt)
image._modified = (dt + 1).millis()

delattr(image, "_modified")
marker = object()
self.assertEqual(marker, getattr(image, "_modified", marker))
self.assertEqual(dt.millis(), image._p_mtime)
self.assertEqual(image.modified, image._p_mtime)

def testInterface(self):
self.assertTrue(INamedBlobImage.implementedBy(NamedBlobImage))
Expand Down

0 comments on commit 1cd966a

Please sign in to comment.