Skip to content

Commit

Permalink
Implement action for items in the dc extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
wltb committed Apr 21, 2014
1 parent b5d0d4b commit b3fb2ba
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions feedgen/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def atom_entry(self, feed, extensions=True):
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

Expand Down Expand Up @@ -220,7 +220,7 @@ def rss_entry(self, feed, extensions=True):
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

Expand Down
33 changes: 31 additions & 2 deletions feedgen/ext/dc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
'''
feedgen.ext.podcast
feedgen.ext.dc
~~~~~~~~~~~~~~~~~~~
Extends the FeedGenerator to add Dubline Core Elements to the feeds.
Expand Down Expand Up @@ -46,7 +46,7 @@ def __init__(self):
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
Expand Down Expand Up @@ -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

0 comments on commit b3fb2ba

Please sign in to comment.