From b3fb2ba7775b26ddc0c9d3f56a6b2fab0db217f9 Mon Sep 17 00:00:00 2001 From: wltb Date: Mon, 21 Apr 2014 17:54:38 +0200 Subject: [PATCH] Implement action for items in the dc extension. --- feedgen/entry.py | 4 ++-- feedgen/ext/dc.py | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/feedgen/entry.py b/feedgen/entry.py index a7e6973..3c9ed8a 100644 --- a/feedgen/entry.py +++ b/feedgen/entry.py @@ -169,7 +169,7 @@ class FeedEntry(object): if extensions: for ext in self.__extensions.values() or []: if ext.get('atom'): - entry = ext['inst'].extend_atom(entry) + ext['inst'].extend_atom(entry) return entry @@ -220,7 +220,7 @@ class FeedEntry(object): if extensions: for ext in self.__extensions.values() or []: if ext.get('rss'): - entry = ext['inst'].extend_rss(entry) + ext['inst'].extend_rss(entry) return entry diff --git a/feedgen/ext/dc.py b/feedgen/ext/dc.py index 2b3634a..cc87fa7 100644 --- a/feedgen/ext/dc.py +++ b/feedgen/ext/dc.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ''' - feedgen.ext.podcast + feedgen.ext.dc ~~~~~~~~~~~~~~~~~~~ Extends the FeedGenerator to add Dubline Core Elements to the feeds. @@ -46,7 +46,7 @@ class DcBaseExtension(BaseExtension): def extend_atom(self, atom_feed): '''Create an Atom feed xml structure containing all previously set fields. - :returns: Tuple containing the feed root element + :returns: The feed root element ''' DCELEMENTS_NS = 'http://purl.org/dc/elements/1.1/' # Replace the root element to add the new namespace @@ -426,4 +426,33 @@ class DcExtension(DcBaseExtension): class DcEntryExtension(DcBaseExtension): '''Dublin Core Elements extension for podcasts. ''' + def extend_atom(self, entry): + '''NYI. Differs from RSS Implementation? + + ''' + return entry + def extend_rss(self, item): + '''Add dc elements to a RSS item. Alters the item itself. + + :returns: The item element. + ''' + DCELEMENTS_NS = 'http://purl.org/dc/elements/1.1/' + + for elem in ['contributor', 'coverage', 'creator', 'date', 'description', + 'language', 'publisher', 'relation', 'rights', 'source', 'subject', + 'title', 'type']: + if hasattr(self, '_dcelem_%s' % elem): + for val in getattr(self, '_dcelem_%s' % elem) or []: + node = etree.SubElement(item, '{%s}%s' % (DCELEMENTS_NS,elem)) + node.text = val + + if self._dcelem_format: + node = etree.SubElement(item, '{%s}format' % DCELEMENTS_NS) + node.text = format + + if self._dcelem_identifier: + node = etree.SubElement(item, '{%s}identifier' % DCELEMENTS_NS) + node.text = identifier + + return item