Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the NamedFile modified property #153

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading