-
Notifications
You must be signed in to change notification settings - Fork 7
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 #33 from simplesconsultoria/issue_32
Issue 32 - Add cover tile
- Loading branch information
Showing
22 changed files
with
295 additions
and
18 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
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,17 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone import api | ||
from sc.embedder.config import PROJECTNAME | ||
|
||
|
||
def remove_tile(portal): | ||
tiles = api.portal.get_registry_record('plone.app.tiles') | ||
if u'sc.embedder' in tiles: | ||
tiles.remove(u'sc.embedder') | ||
|
||
|
||
def uninstall(portal): | ||
remove_tile(portal) | ||
profile = 'profile-%s:uninstall' % PROJECTNAME | ||
setup_tool = api.portal.get_tool(name='portal_setup') | ||
setup_tool.runAllImportStepsFromProfile(profile) | ||
return 'Ran all uninstall steps.' |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
PROJECTNAME = 'sc.embedder' | ||
PROFILE = PROJECTNAME + ':default' |
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,7 +1,7 @@ | ||
<?xml version="1.0"?> | ||
<metadata> | ||
<version>1000</version> | ||
<version>1001</version> | ||
<dependencies> | ||
<dependency>profile-plone.app.dexterity:default</dependency> | ||
</dependencies> | ||
</metadata> | ||
</metadata> |
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,12 @@ | ||
<?xml version="1.0"?> | ||
<registry xmlns:i18n="http://xml.zope.org/namespaces/i18n" i18n:domain="plone"> | ||
<record name="plone.app.tiles"> | ||
<field type="plone.registry.field.List"> | ||
<title>Tiles</title> | ||
<value_type type="plone.registry.field.TextLine" /> | ||
</field> | ||
<value purge="false"> | ||
<element>sc.embedder</element> | ||
</value> | ||
</record> | ||
</registry> |
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,73 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone import api | ||
from sc.embedder.config import PROFILE | ||
from sc.embedder.testing import INTEGRATION_TESTING | ||
|
||
import unittest | ||
|
||
|
||
class UpgradeTestCaseBase(unittest.TestCase): | ||
|
||
layer = INTEGRATION_TESTING | ||
|
||
def setUp(self, from_version, to_version): | ||
self.portal = self.layer['portal'] | ||
self.setup = self.portal['portal_setup'] | ||
self.from_version = from_version | ||
self.to_version = to_version | ||
|
||
def _get_upgrade_step(self, title): | ||
"""Get one of the upgrade steps. | ||
:param title: [required] the title used to register the upgrade step | ||
:type obj: str | ||
""" | ||
self.setup.setLastVersionForProfile(PROFILE, self.from_version) | ||
upgrades = self.setup.listUpgrades(PROFILE) | ||
steps = [s for s in upgrades[0] if s['title'] == title] | ||
return steps[0] if steps else None | ||
|
||
def _do_upgrade_step(self, step): | ||
"""Execute an upgrade step. | ||
:param step: [required] the step we want to run | ||
:type step: str | ||
""" | ||
request = self.layer['request'] | ||
request.form['profile_id'] = PROFILE | ||
request.form['upgrades'] = [step['id']] | ||
self.setup.manage_doUpgrades(request=request) | ||
|
||
def _how_many_upgrades_to_do(self): | ||
self.setup.setLastVersionForProfile(PROFILE, self.from_version) | ||
upgrades = self.setup.listUpgrades(PROFILE) | ||
assert len(upgrades) > 0 | ||
return len(upgrades[0]) | ||
|
||
|
||
class Upgrade1000to1001TestCase(UpgradeTestCaseBase): | ||
|
||
def setUp(self): | ||
UpgradeTestCaseBase.setUp(self, u'1000', u'1001') | ||
|
||
def test_upgrade_to_1001_registrations(self): | ||
version = self.setup.getLastVersionForProfile(PROFILE)[0] | ||
self.assertGreaterEqual(int(version), int(self.to_version)) | ||
self.assertEqual(self._how_many_upgrades_to_do(), 1) | ||
|
||
def test_add_embedder_tile(self): | ||
# check if the upgrade step is registered | ||
title = u'Add embedder tile' | ||
step = self._get_upgrade_step(title) | ||
self.assertIsNotNone(step) | ||
|
||
# simulate state on previous version | ||
from sc.embedder.Extensions.Install import remove_tile | ||
remove_tile(api.portal.get()) | ||
tiles = api.portal.get_registry_record('plone.app.tiles') | ||
self.assertNotIn(u'sc.embedder', tiles) | ||
|
||
# run the upgrade step to validate the update | ||
self._do_upgrade_step(step) | ||
tiles = api.portal.get_registry_record('plone.app.tiles') | ||
self.assertIn(u'sc.embedder', tiles) |
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 @@ | ||
# -*- coding: utf-8 -*- |
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,21 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:i18n="http://namespaces.zope.org/i18n" | ||
xmlns:plone="http://namespaces.plone.org/plone" | ||
i18n_domain="sc.embedder"> | ||
|
||
<include package="plone.tiles" file="meta.zcml" /> | ||
|
||
<plone:tile | ||
name="sc.embedder" | ||
title="Embedder" | ||
description="Embedder tile, can reproduce embeded files." | ||
add_permission="cmf.ModifyPortalContent" | ||
schema=".embedder.IEmbedderTile" | ||
class=".embedder.EmbedderTile" | ||
permission="zope2.View" | ||
for="*" | ||
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,18 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:metal="http://xml.zope.org/namespaces/metal" | ||
xmlns:tal="http://xml.zope.org/namespaces/tal" | ||
xmlns:i18n="http://xml.zope.org/namespaces/i18n" | ||
i18n:domain="brasil.gov.tiles"> | ||
|
||
<body tal:define="tile_id view/id;"> | ||
<div class="video-tile" | ||
tal:attributes="id string:video-$tile_id" | ||
tal:define="results view/data;"> | ||
<div class="video-container" tal:content="structure results/embed_code"></div> | ||
<a href="" tal:content="results/title" tal:attributes="href results/url"></a> | ||
</div> | ||
<noscript> | ||
<div class="error" i18n:translate="">Your internet browser this not support JavaScript, therefore some features of the website may not be accessible.</div> | ||
</noscript> | ||
</body> | ||
</html> |
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,70 @@ | ||
# -*- coding: utf-8 -*- | ||
from collective.cover.tiles.base import IPersistentCoverTile | ||
from collective.cover.tiles.base import PersistentCoverTile | ||
from plone.tiles.interfaces import ITileDataManager | ||
from plone.uuid.interfaces import IUUID | ||
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile | ||
from sc.embedder import MessageFactory as _ | ||
from zope import schema | ||
|
||
|
||
class IEmbedderTile(IPersistentCoverTile): | ||
""" | ||
""" | ||
|
||
title = schema.TextLine( | ||
title=_(u'Title'), | ||
required=False, | ||
) | ||
|
||
embed_code = schema.TextLine( | ||
title=_(u'Videos'), | ||
required=False, | ||
readonly=True, | ||
) | ||
|
||
url = schema.TextLine( | ||
title=_(u'Videos'), | ||
required=False, | ||
readonly=True, | ||
) | ||
|
||
uuids = schema.List( | ||
title=_(u'Videos'), | ||
value_type=schema.TextLine(), | ||
required=False, | ||
readonly=True, | ||
) | ||
|
||
|
||
class EmbedderTile(PersistentCoverTile): | ||
index = ViewPageTemplateFile('embedder.pt') | ||
is_configurable = False | ||
is_editable = True | ||
limit = 1 | ||
|
||
def populate_with_object(self, obj): | ||
super(EmbedderTile, self).populate_with_object(obj) # check permission | ||
|
||
# here we should check if the embeded item has its a video | ||
# XXX | ||
if obj.portal_type in self.accepted_ct(): | ||
|
||
title = obj.Title() | ||
url = obj.absolute_url() | ||
uuid = IUUID(obj) | ||
embed = obj.embed_html | ||
data_mgr = ITileDataManager(self) | ||
data_mgr.set({'title': title, | ||
'url': url, | ||
'uuid': uuid, | ||
'embed_code': embed | ||
}) | ||
|
||
def get_uid(self, obj): | ||
return IUUID(obj) | ||
|
||
def accepted_ct(self): | ||
""" Return a list of content types accepted by the tile. | ||
""" | ||
return ['sc.embedder'] |
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 @@ | ||
# -*- coding: utf-8 -*- | ||
from sc.embedder.logger import logger | ||
from plone import api | ||
|
||
|
||
def cook_css_resources(context): | ||
"""Cook css resources.""" | ||
css_tool = api.portal.get_tool('portal_css') | ||
css_tool.cookResources() | ||
logger.info('CSS resources were cooked') | ||
|
||
|
||
def cook_javascript_resources(context): | ||
"""Cook javascript resources.""" | ||
js_tool = api.portal.get_tool('portal_javascripts') | ||
js_tool.cookResources() | ||
logger.info('Javascript resources were cooked') |
Oops, something went wrong.