-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #457 from collective/refresh-behavior
Add behavior to enable reloading the current page after a certain amount of time
- Loading branch information
Showing
10 changed files
with
142 additions
and
3 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Empty file.
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,17 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:i18n="http://namespaces.zope.org/i18n" | ||
xmlns:plone="http://namespaces.plone.org/plone" | ||
i18n_domain="collective.cover"> | ||
|
||
<include package="plone.behavior" file="meta.zcml" /> | ||
|
||
<plone:behavior | ||
title="Page refresh" | ||
description="Reload the current page after a certain amount of time." | ||
provides="collective.cover.behaviors.interfaces.IRefresh" | ||
for="collective.cover.interfaces.ICover" | ||
i18n:attributes="title; description" | ||
/> | ||
|
||
</configure> |
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,34 @@ | ||
# coding: utf-8 | ||
from collective.cover import _ | ||
from plone.directives import form | ||
from plone.supermodel import model | ||
from zope import schema | ||
from zope.interface import alsoProvides | ||
from zope.interface import Invalid | ||
|
||
|
||
class IRefresh(model.Schema): | ||
|
||
"""Reload the current page after a certain amount of time.""" | ||
|
||
model.fieldset('settings', fields=['enable_refresh', 'ttl']) | ||
|
||
enable_refresh = schema.Bool( | ||
title=_(u'Enable refresh'), | ||
description=_(u'Enable refresh of the current page.'), | ||
default=False, | ||
) | ||
|
||
ttl = schema.Int( | ||
title=_(u'Time to live'), | ||
description=_(u'Number of seconds after which to reload the current page.',), | ||
default=300, | ||
) | ||
|
||
alsoProvides(IRefresh, form.IFormFieldProvider) | ||
|
||
|
||
@form.validator(field=IRefresh['ttl']) | ||
def validate_ttl(value): | ||
if value <= 0: | ||
raise Invalid(_(u'Value must be greater than zero.')) |
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
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,57 @@ | ||
# -*- coding: utf-8 -*- | ||
from collective.cover.behaviors.interfaces import IRefresh | ||
from collective.cover.interfaces import ICoverLayer | ||
from collective.cover.testing import INTEGRATION_TESTING | ||
from plone import api | ||
from plone.behavior.interfaces import IBehavior | ||
from plone.dexterity.interfaces import IDexterityFTI | ||
from plone.dexterity.schema import SchemaInvalidatedEvent | ||
from zope.component import queryUtility | ||
from zope.event import notify | ||
from zope.interface import alsoProvides | ||
|
||
import unittest | ||
|
||
|
||
class RefreshBehaviorTestCase(unittest.TestCase): | ||
|
||
layer = INTEGRATION_TESTING | ||
|
||
def _enable_refresh_behavior(self): | ||
fti = queryUtility(IDexterityFTI, name='collective.cover.content') | ||
behaviors = list(fti.behaviors) | ||
behaviors.append(IRefresh.__identifier__) | ||
fti.behaviors = tuple(behaviors) | ||
# invalidate schema cache | ||
notify(SchemaInvalidatedEvent('collective.cover.content')) | ||
|
||
def _disable_refresh_behavior(self): | ||
fti = queryUtility(IDexterityFTI, name='collective.cover.content') | ||
behaviors = list(fti.behaviors) | ||
behaviors.remove(IRefresh.__identifier__) | ||
fti.behaviors = tuple(behaviors) | ||
# invalidate schema cache | ||
notify(SchemaInvalidatedEvent('collective.cover.content')) | ||
|
||
def setUp(self): | ||
self.portal = self.layer['portal'] | ||
self.request = self.layer['request'] | ||
alsoProvides(self.request, ICoverLayer) | ||
with api.env.adopt_roles(['Manager']): | ||
self.cover = api.content.create( | ||
self.portal, 'collective.cover.content', 'c1') | ||
|
||
def test_refresh_registration(self): | ||
registration = queryUtility(IBehavior, name=IRefresh.__identifier__) | ||
self.assertIsNotNone(registration) | ||
|
||
def test_refresh_behavior(self): | ||
view = api.content.get_view(u'view', self.cover, self.request) | ||
self.assertNotIn('<meta http-equiv="refresh" content="300" />', view()) | ||
self._enable_refresh_behavior() | ||
self.cover.enable_refresh = True | ||
self.assertIn('<meta http-equiv="refresh" content="300" />', view()) | ||
self.cover.ttl = 5 | ||
self.assertIn('<meta http-equiv="refresh" content="5" />', view()) | ||
self._disable_refresh_behavior() | ||
self.assertNotIn('<meta http-equiv="refresh" content="5" />', view()) |