Implement action for items in the dc extension.

This commit is contained in:
wltb 2014-04-21 17:54:38 +02:00
parent b5d0d4ba38
commit b3fb2ba777
2 changed files with 33 additions and 4 deletions

View file

@ -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

View file

@ -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