-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NITF tile for collective.cover (closes #123)
- Loading branch information
Showing
8 changed files
with
192 additions
and
0 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
Loading
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
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="collective.nitf"> | ||
|
||
<include package="plone.tiles" file="meta.zcml" /> | ||
|
||
<plone:tile | ||
name="collective.nitf" | ||
title="News Article Tile" | ||
description="A tile that shows information about a News Article." | ||
icon="++resource++collective.nitf/tile-nitf.png" | ||
add_permission="cmf.ModifyPortalContent" | ||
schema=".nitf.INITFTile" | ||
class=".nitf.NITFTile" | ||
permission="zope2.View" | ||
for="*" | ||
/> | ||
|
||
</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,67 @@ | ||
<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="collective.nitf"> | ||
|
||
<body tal:define="is_empty nocall:view/is_empty; | ||
toLocalizedTime nocall:context/@@plone/toLocalizedTime"> | ||
<p tal:condition="is_empty"> | ||
Drag&drop a News Article here. | ||
</p> | ||
|
||
<div tal:condition="not:is_empty" class="nitf-basic-tile tile-content" | ||
tal:define="description view/data/description|nothing"> | ||
<tal:fields repeat="field view/get_configured_fields"> | ||
<tal:title condition="python:field['id'] == 'title'"> | ||
<h1 tal:replace="structure view/title_tag" /> | ||
</tal:title> | ||
|
||
<tal:subtitle condition="python:field['id'] == 'subtitle'"> | ||
<p tal:content="python:field['content']" class="tile-subtitle">Subtitle</p> | ||
</tal:subtitle> | ||
|
||
<div tal:condition="python:field['id'] == 'media_producer'"> | ||
<span tal:content="python:field['content']" /> | ||
</div> | ||
|
||
<tal:image | ||
condition="python:field['id'] == 'image'" | ||
define="scale python:field.get('scale', 'large'); | ||
position python:field.get('position', '');"> | ||
<a class="imag" tal:attributes="href view/getURL; | ||
title description;"> | ||
<img tal:define="scales view/@@images; | ||
thumbnail python: scales.scale('image', scale=scale);" | ||
tal:condition="thumbnail" | ||
tal:attributes="src thumbnail/url; | ||
width thumbnail/width; | ||
height thumbnail/height; | ||
class position;" /> | ||
</a> | ||
</tal:image> | ||
|
||
<tal:description condition="python:field['id'] == 'description'"> | ||
<p tal:content="python:field['content']" class="tile-description">Description</p> | ||
</tal:description> | ||
|
||
<tal:section condition="python:field['id'] == 'section'"> | ||
<p tal:content="python:field['content']" class="tile-section">Section</p> | ||
</tal:section> | ||
|
||
<tal:date condition="python:field['id'] == 'date'"> | ||
<p class="" tal:content="view/Date">May 5</p> | ||
</tal:date> | ||
|
||
<tal:subjects condition="python:field['id'] == 'subjects'"> | ||
<span metal:use-macro="context/@@tile_macros/subjects" /> | ||
</tal:subjects> | ||
|
||
<tal:last condition="repeat/field/end"> | ||
<div class="visualClear"><!-- --></div> | ||
</tal:last> | ||
</tal:fields> | ||
</div> | ||
</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,88 @@ | ||
# -*- coding: utf-8 -*- | ||
from collective.cover.tiles.basic import BasicTile | ||
from collective.cover.tiles.basic import IBasicTile | ||
from collective.cover.tiles.configuration_view import IDefaultConfigureForm | ||
from collective.nitf import _ | ||
from collective.nitf.content import INITF | ||
from plone import api | ||
from plone.autoform import directives as form | ||
from plone.tiles.interfaces import ITileDataManager | ||
from zope import schema | ||
from zope.browserpage import ViewPageTemplateFile | ||
from zope.interface import implements | ||
|
||
|
||
class INITFTile(IBasicTile): | ||
|
||
"""A tile that shows information about a News Article.""" | ||
|
||
subtitle = schema.Text( | ||
title=_(u'Subtitle'), | ||
required=False, | ||
) | ||
|
||
form.omitted('section') | ||
form.no_omit(IDefaultConfigureForm, 'section') | ||
section = schema.Text( | ||
title=_(u'Section'), | ||
required=False, | ||
) | ||
|
||
media_producer = schema.TextLine( | ||
# nitf/body/body.content/media/media-producer | ||
title=_(u'Image Rights'), | ||
required=False, | ||
) | ||
|
||
|
||
class NITFTile(BasicTile): | ||
|
||
"""A tile that shows information about a News Article.""" | ||
|
||
implements(INITFTile) | ||
|
||
index = ViewPageTemplateFile('nitf.pt') | ||
is_configurable = True | ||
is_editable = True | ||
is_droppable = True | ||
|
||
short_name = _(u'msg_short_name_nitf', u'News Article') | ||
|
||
def _accepted_ct(self): | ||
"""Return a list of content types accepted by the tile.""" | ||
return ['News Article'] | ||
|
||
def populate_with_object(self, obj): | ||
super(NITFTile, self).populate_with_object(obj) | ||
|
||
if INITF.providedBy(obj): | ||
data_mgr = ITileDataManager(self) | ||
data = data_mgr.get() | ||
data['subtitle'] = obj.subtitle | ||
data['section'] = obj.section | ||
image = obj.getImage() | ||
data['media_producer'] = image.Rights() if image is not None else '' | ||
data_mgr.set(data) | ||
|
||
def _get_field_configuration(self, field): | ||
"""Return a dict with the configuration of the field. This is a | ||
helper function to deal with the ugliness of the internal data | ||
structure. | ||
""" | ||
fields = self.get_configured_fields() | ||
return [f for f in fields if f['id'] == field][0] | ||
|
||
@property | ||
def title_tag(self): | ||
field = self._get_field_configuration('title') | ||
tag, title, href = field['htmltag'], field['content'], self.getURL() | ||
return u""" | ||
<{tag}> | ||
<a href="{href}">{title}</a> | ||
</{tag}> | ||
""".format(tag=tag, title=title, href=href) | ||
|
||
def Date(self): | ||
"""Return the date of the object, localized.""" | ||
date = super(NITFTile, self).Date() | ||
return api.portal.get_localized_time(date, long_format=True) |