3 posts tagged “nitf”
Lightning Talks are among the best investments of time you can make on any Plone Conference: there's always a lot of smart people doing great things.
During the Plone Conference 2007, in Naples, Florian Schulze spoke about schemaxtender, a package that allows you to inject new fields into an Archetypes schema using an adapter. When I saw his talk, I knew I was going to use it for what I had in mind.
As I mentioned in a previous post, in La Jornada we were looking for a way to adapt Plone's standard News Item content type to:
- add new fields to it (property, section, urgency and byline)
- change fields' order among different schematas to make the edition of new content easier for the publishers
Using schemaextender to accomplish these tasks was so easy that I was really
excited when I finished. I spent about 40 hours (in fact, a little bit more after the second release) to read
Part 1 of Philip von Weitershausen's excellent book on Zope 3, to
understand the way schemaextender works, to find out how to make it work on Plone 2.5, to start using the adapted content with Smart Folders, and even to write some tests for it.
All this work is available in a product called nitf4plone in case you want to try it (be aware this is an beta release). The product works on both, Plone 2.5 and Plone 3.0.
Let's analize the code... but first, a disclaimer: don't try this on Plone 2.5.
Why? schemaextender was written to work with Archetypes version 1.5 or later (that's, Plone 3.0 and later). There's a branch to make it work with Plone 2.5 patched by Erik Rose of the WebLion Project Team at PSU, but it will never be merged into the maintenance one. If you use this branch you are on your own in the event of a bug. Also, have in mind that there's no way back on doing this and after installing schemaextender in Plone 2.5, the adapter will be available for all sites in the instance.
So, yes, do as I say, not as I did. Having warned you, let's dive a little bit into the code.
schemaextender includes 3 types of adapters:
- ISchemaExtender lets you can add new fields to a schema
- IOrderableSchemaExtender lets you add new fields and reorder them
- ISchemaModifier is a low-level hook that allows direct manipulation of the schema
You can find information and examples on all of them on the source code. As you might have expected, I decided to use IOrderableSchemaExtender.
To write the adapter, we need to declare the new fields first; let's take a look to the section field as an example:
class SectionField(ExtensionField, atapi.StringField):
"""Named section of a publication where a news object appear
"""def getDefault(self, instance):
...
return nitf.default_sectiondef Vocabulary(self, instance):
...
return atapi.DisplayList([(x, x) for x in nitf.sections])
As you can see, we need to subclass from ExtensionField and StringField; please note that it's mandatory to keep this order. ExtensionField will provide standard accessors and mutators which are not generated on the class. StringField will provide standard attributes and the widget for the field. Also we override getDefault() and Vocabulary() methods to set the default value and vocabulary.
Let's take a look to the adapter's class now:
class NITFExtender(object):
"""Adapter to add NITF fields to News Items
"""
implements(IOrderableSchemaExtender)
adapts(IATNewsItem)fields = [
...
SectionField('section',
languageIndependent=1,
enforceVocabulary=1,
required=1,
widget = atapi.SelectionWidget(
label='Section',
label_msgid='section',
description='Named section where the news object appear',
description_msgid='help_section',
i18n_domain='nitf4plone')),
...
]def __init__(self, context):
self.context = contextdef getFields(self):
return self.fieldsdef getOrder(self, original):
# we only need to change the order of the fields in Plone 2.5
if 'metadata' in original:
# first we remove the fields from whichever schemata they are
for schemata in original.keys():
if 'relatedItems' in original[schemata]:
original[schemata].remove('relatedItems')
if 'subject' in original[schemata]:
original[schemata].remove('subject')
# now we insert them where we want them to appear
idx = original['default'].index('property')
original['default'].insert(idx, 'subject')
original['metadata'].insert(0, 'relatedItems')
return original
As I mentioned, our adapter implements IOrderableSchemaExtender. In Plone 3.0 adapters can be registered locally at installation time:
sm = portal.getSiteManager()
sm.registerAdapter(NITFExtender,
(IATNewsItem,),
IOrderableSchemaExtender,
)
In Plone 2.5 we can't have local adapters and registrations aren't persistent, so we have to handle this in a different way:
Here you can see the way news items look after applying the adapter:
The code of the adapter is pretty clean and easy to understand.
Having finished it, we followed Mikko Ohtamaa's procedure to adding new fields to Smart Folders search in order to display all news articles for a given section and it worked fine.
Right now we are working on the migration of the content of our site to use the new fields; we are also preparing some templates to display the new information and some CompositePack's viewlets to use them to create the front pages in a better way.
Please let me know if you find this development interesting or if you want to participate in some way.
I want to thank all the members of the Plone community who helped me answering my questions at the #plone channel on IRC and the Product Developers forum, specially Martin Aspeli and Florian Schulze (who helped me with the schemaxtender internals and were really patient with me), Mikel Larreategui and Erik Rose (who helped me with the installer), Wichert Akkerman and Andreas Jung (who are always available answering all sort of questions on the forums).
As I mentioned previously, Plone standard News Items have not enough metadata for using them seriously in a newspaper publication.
When we started using Plone for our breaking news site, we tried to fill the gap using some fancy Web 2.0 features like tags and tag clouds. I was convinced (well, in fact I am still convinced) that online media should face the problem of organizing news in a different way. Unfortunately, the implementation of this solution was problematic from the beginning.
First, tag clouds are wild beasts and you have to learn a lot before trying to implement one (my early version of the TagCloud product proved to has a lot of flaws). Second, social bookmarking in our environment showed a lot of disadvantages like nonexistence of a controlled vocabulary, use of "unclear" tags and spelling errors.
Worst of all, publishers never liked the concept.
I also think many ordinary readers never understood the tag cloud neither because not many newspapers were using it at that time (even today, almost 2 years later, it's difficult to find tag clouds in online versions of traditional media).
At the end we just had to abandon the idea and, obviously, it was quite evident that we needed to extend the functionalities of our site to include concepts like sections and a way to indicate if a new article was more important than another.
In La Jornada we have been using NITF to store news articles for the printed edition's site since some time and it had simplified our work. We needed to bring that experience to the breaking news site.
As you can see in its documentation, NITF defines a lot of metadata to be used on the different stages of a news article life. So, the first thing I did was a mapping between Plone's metadata and NITF elements and attributes:
- Subject (nitf/head/docdata/key-list): list of keywords; holds a list of keywords about the document
- Contributors (nitf/body/body.end/tagline): a byline at the end of a story
- Creation Date (nitf/head/docdata/date.issue): date/time document was issued
- Last Modified Date (nitf/head/revision-history): information about the creative history of the document; also used as an audit trail (includes who made changes, when the changes were made, and why)
- Effective Date (nitf/head/docdata/date.release): date/time document is available to be released
- Expiration Date (nitf/head/docdata/date.expire): date/time at which the document has no validity
- Language (nitf/body/@xml:lang ): language value governed by RFC3066
- Rights (nitf/head/docdata/doc.copyright): copyright information for document header
Then, I identified what was the information we were missing:
- Property (nitf/head/tobject/tobject.property/@tobject.property.type): subject code property; includes such items as analysis, feature, and obituary. In our case we use it to differentiate news articles produced in-house from the ones written by our associates
- Section (nitf/head/pubdata/@position.section): named section of a publication where a news object appear, such as Science, Sports, Weekend, etc.
- Urgency (nitf/head/docdata/urgency/@ed-urg): is used to define the importance of a news article (1=most, 5=normal, 8=least)
- Byline (nitf/body/body.head/byline): container for byline information; it can be unstructured text or structured text with direct specification of the responsible person/entity and their title
After having this in mind, I started looking how to accomplish the task the easier way.
News articles in Plone are instances of the News Item content type: they can contain a title, a description, a body text, an image and some basic metadata. If you publish a couple of items from time to time, this is fine.
But suppose you have to publish dozens of items everyday... How do you tell your readers who they are about? What do they cover? Where do they took place? And, more important, how do you classify them? How do you organize them? How do you tell your readers which ones are newsworthy?
To solve these, and other issues, the IPTC developed XML standards to define the content and structure of news articles. NITF, NewsML and NewsCodes are among these standards and they support the classification, identification and description of a huge number of news articles characteristics.
NITF and NewsML have different uses: NITF is intended to structure independent news articles; NewsML is for the structuring of multimedia news packages. Inside a NewsML object we can have things like alternative representations of the same article to be used on different media, or different translations. NewsML can also be used to encapsulate many NITF objects to form an edition.
NewsCodes are about consistent coding of news metadata (taxonomies). NewsCodes define sets of topics to be assigned as metadata values to any object inside a news article (text, photos, graphs, audios and videos).
As you can imagine this is quite powerful. Typical uses of these standards are: in and between editorial systems, between news agencies and their customers, between publishers and news aggregators, and between news service providers and end users. Many content providers and system vendors currently support them worldwide.
If Plone could understand NITF and NewsML, it would be easy to interoperate with editorial systems and feed a whole edition of a newspaper or magazine into a website, even in different languages and formats, and including all sort of multimedia content. You could also use Plone to distribute your content to different aggregators or sell it to your customers.
If Plone could handle NewsCodes it would be easier to describe, manage, transmit and exchange news articles.
That's a lot of work, and that's what we had in mind when we started the Julius project in early 2006.