Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use timestamp instead of string of timestamp to save image modified a…
…ttribute
- Loading branch information
Showing
7 changed files
with
109 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
from collective.cover.browser.scaling import ImageScaling | ||
from collective.cover.testing import INTEGRATION_TESTING | ||
from collective.cover.tiles.basic import BasicTile | ||
from plone import api | ||
|
||
import unittest | ||
|
||
|
||
class ImageScalingTestCase(unittest.TestCase): | ||
|
||
layer = INTEGRATION_TESTING | ||
|
||
def setUp(self): | ||
self.portal = self.layer['portal'] | ||
self.request = self.layer['request'] | ||
|
||
with api.env.adopt_roles(['Manager']): | ||
self.cover = api.content.create( | ||
self.portal, 'collective.cover.content', 'c1') | ||
|
||
self.tile = BasicTile(self.cover, self.request) | ||
self.tile.__name__ = u'collective.cover.basic' | ||
self.tile.id = u'test' | ||
|
||
obj = self.portal['my-image'] | ||
self.tile.populate_with_object(obj) | ||
|
||
self.scaling = ImageScaling(self.tile, self.request) | ||
|
||
def test_modified(self): | ||
self.assertIsInstance(self.scaling.modified(), float) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
from collective.cover.logger import logger | ||
from persistent.dict import PersistentDict | ||
from plone.namedfile.interfaces import INamedImage | ||
from plone.tiles.interfaces import ITileDataManager | ||
|
||
|
||
def fix_image_modified_date(context): | ||
"""Update all tiles to fix modified date""" | ||
|
||
covers = context.portal_catalog(portal_type='collective.cover.content') | ||
logger.info('About to update {0} objects'.format(len(covers))) | ||
for cover in covers: | ||
obj = cover.getObject() | ||
for tile_id in obj.list_tiles(): | ||
tile = obj.get_tile(tile_id) | ||
dmgr = ITileDataManager(tile) | ||
data = dmgr.get() | ||
for k, v in data.items(): | ||
if INamedImage.providedBy(v): | ||
mtime_key = '{0}_mtime'.format(k) | ||
data[mtime_key] = float(data[mtime_key]) | ||
# need to set changes directly into annotation | ||
dmgr.annotations[dmgr.key] = PersistentDict(data) | ||
msg = 'Tile {0} at {1} updated' | ||
logger.info(msg.format(tile_id, cover.getPath())) | ||
|
||
logger.info('Done') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters