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

Issue 686 - Use timestamp instead of string of timestamp to represent image modified date #689

Merged
merged 3 commits into from
Dec 13, 2016
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
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ There's a frood who really knows where his towel is.
- Fix ``@@updatetilecontent`` view to avoid rendering outdated data.
[hvelarde]

- Fix ``TypeError`` when changing default image scale on basic tiles (fixes `#686`_).
[rodfersou]

- Fixed adding a 'more' link in list tiles.
Previously you could select an item to use as 'more' link,
but it did not stick. [maurits]
Expand Down Expand Up @@ -160,3 +163,4 @@ Previous entries can be found in the HISTORY.rst file.
.. _`#608`: https://github.com/collective/collective.cover/issues/608
.. _`#641`: https://github.com/collective/collective.cover/issues/641
.. _`#651`: https://github.com/collective/collective.cover/issues/651
.. _`#686`: https://github.com/collective/collective.cover/issues/686
4 changes: 2 additions & 2 deletions src/collective/cover/browser/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ def modified(self):
name='images',
default=None)
return base_scales and base_scales.modified()
mtime = ''
mtime = None
for k, v in self.context.data.items():
if INamedImage.providedBy(v):
mtime += self.context.data.get('{0}_mtime'.format(k), '')
mtime = self.context.data.get('{0}_mtime'.format(k), None)

return mtime

Expand Down
63 changes: 63 additions & 0 deletions src/collective/cover/tests/test_scaling.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
*** Settings ***

Resource cover.robot
Library Remote ${PLONE_URL}/RobotRemote

Suite Setup Open Test Browser
Suite Teardown Close all browsers

*** Variables ***

${basic_tile_name} = "collective.cover.basic"
${image_selector} //div[@id="content-trees"]//li[@class="ui-draggable"]/a[@data-ct-type="Image"]/span[text()='Test image']/..
${tile_selector} div.tile-container div.tile
${tile_class} = div.cover-tile

*** Test cases ***

Test Scaling
Enable Autologin as Site Administrator
Go to Homepage

Create Cover Title Description

Open Layout Tab

Add Tile ${basic_tile_name}
Save Cover Layout

Compose Cover
Open Content Chooser
Click Element link=Content tree
Drag And Drop xpath=${image_selector} css=${tile_selector}

Click Link link=View
Page Should Contain Element xpath=//img[@width=50][@height=50]

Open Layout Tab
Click Config from Tile ${tile_class}
Wait until element is visible id=buttons-cancel
Select From List css=#collective-cover-basic-image-imgsize listing 16:16
Click Button id=buttons-save
Save Cover Layout

Click Link link=View
Page Should Contain Element xpath=//img[@width=16][@height=16]

Open Layout Tab
Click Config from Tile ${tile_class}
Wait until element is visible id=buttons-cancel
Select From List css=#collective-cover-basic-image-imgsize icon 32:32
Click Button id=buttons-save
Save Cover Layout

Click Link link=View
Page Should Contain Element xpath=//img[@width=32][@height=32]


*** Keywords ***

Click Config from Tile
[arguments] ${tile}

Click Element css=${tile} .config-tile-link
35 changes: 34 additions & 1 deletion src/collective/cover/tests/test_upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,4 +587,37 @@ def setUp(self):
def test_registrations(self):
version = self.setup.getLastVersionForProfile(self.profile_id)[0]
self.assertGreaterEqual(int(version), int(self.to_version))
self.assertEqual(self._how_many_upgrades_to_do(), 1)
self.assertEqual(self._how_many_upgrades_to_do(), 2)

def test_fix_image_field_modification_time(self):
from persistent.dict import PersistentDict
title = u'Fix image field modification time'
step = self._get_upgrade_step(title)
assert step is not None

# simulate state on previous version
cover = self._create_cover('test-cover', 'Empty layout')
cover.cover_layout = (
'[{"type": "row", "children": [{"column-size": 16, "type": '
'"group", "children": [{"tile-type": '
'"collective.cover.basic", "type": "tile", "id": '
'"ca6ba6675ef145e4a569c5e410af7511"}], "roles": ["Manager"]}]}]'
)

tile = cover.get_tile('ca6ba6675ef145e4a569c5e410af7511')
obj = self.portal['my-image']
tile.populate_with_object(obj)

dmgr = ITileDataManager(tile)
old_data = dmgr.get()
old_data['image_mtime'] = repr(old_data['image_mtime'])
dmgr.annotations[dmgr.key] = PersistentDict(old_data)

data = dmgr.get()
assert isinstance(data['image_mtime'], str)

# run the upgrade step to validate the update
self._do_upgrade_step(step)

data = dmgr.get()
self.assertIsInstance(data['image_mtime'], float)
5 changes: 2 additions & 3 deletions src/collective/cover/tiles/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-

from collective.cover.tiles.base import IPersistentCoverTile
from persistent.dict import PersistentDict
from plone.namedfile.interfaces import INamedImage
Expand Down Expand Up @@ -52,9 +51,9 @@ def set(self, data):
data[k] != self.annotations[self.key][k])):
# set modification time of the image
notify(Purge(self.tile))
data[mtime_key] = repr(time.time())
data[mtime_key] = time.time()
else:
data[mtime_key] = self.annotations[self.key].get(mtime_key, '')
data[mtime_key] = self.annotations[self.key].get(mtime_key, None)

self.annotations[self.key] = PersistentDict(data)
notify(ObjectModifiedEvent(self.context))
30 changes: 30 additions & 0 deletions src/collective/cover/upgrades/v15/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
# -*- coding: utf-8 -*-
from collective.cover.interfaces import ICover
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_field_modification_time(context):
"""Fix image modification time to be float timestamp instead of string."""

covers = context.portal_catalog(object_provides=ICover.__identifier__)
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 not INamedImage.providedBy(v):
continue

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')
6 changes: 6 additions & 0 deletions src/collective/cover/upgrades/v15/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
destination="15"
profile="collective.cover:default">

<genericsetup:upgradeStep
title="Fix image field modification time"
description="Fix image modification time to be float timestamp instead of string."
handler=".fix_image_field_modification_time"
/>

<genericsetup:upgradeStep
title="Cook JS resources"
description="There were changes in the JS files, so we need to cook the resources."
Expand Down