Skip to content

Commit

Permalink
Add NITF tile for collective.cover (closes #123)
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed May 13, 2015
1 parent 94abbb5 commit 0f0f07d
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 0 deletions.
7 changes: 7 additions & 0 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extends =

package-name = collective.nitf
package-extras = [test]
eggs = collective.cover

parts +=
code-analysis
Expand Down Expand Up @@ -66,6 +67,12 @@ plone.app.querystring = 1.2.5
plone.recipe.codeanalysis = 2.0b1
# use latest version of setuptools
setuptools =
# collective.cover version pinnings
collective.js.bootstrap = 2.3.1.1
plone.app.blocks = 1.1.1
plone.app.drafts = 1.0a2
plone.app.tiles = 1.0.1
plone.tiles = 1.2

[zopepy]
recipe = zc.recipe.egg
Expand Down
2 changes: 2 additions & 0 deletions src/collective/nitf/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:five="http://namespaces.zope.org/five"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="collective.nitf">

<five:registerPackage package="." />
Expand All @@ -15,6 +16,7 @@
<include package=".behaviors" />
<include package=".browser" />
<include package=".portlets" />
<include package=".tiles" zcml:condition="installed collective.cover" />
<include package=".upgrades" />

<permission
Expand Down
6 changes: 6 additions & 0 deletions src/collective/nitf/profiles/default/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@
<value key="group" i18n:translate="">NITF</value>
</records>

<record name="plone.app.tiles">
<value purge="false">
<element>collective.nitf</element>
</value>
</record>

</registry>
Binary file added src/collective/nitf/static/tile-nitf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/collective/nitf/tiles/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
21 changes: 21 additions & 0 deletions src/collective/nitf/tiles/configure.zcml
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>
67 changes: 67 additions & 0 deletions src/collective/nitf/tiles/nitf.pt
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&amp;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>
88 changes: 88 additions & 0 deletions src/collective/nitf/tiles/nitf.py
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)

0 comments on commit 0f0f07d

Please sign in to comment.