Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting entry title type and using it for Atom feeds. #137

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions feedgen/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(self):
# required
self.__atom_id = None
self.__atom_title = None
self.__atom_title_type = None
self.__atom_updated = datetime.now(dateutil.tz.tzutc())

# recommended
Expand Down Expand Up @@ -106,7 +107,10 @@ def atom_entry(self, extensions=True):
raise ValueError('Required fields not set')
id = xml_elem('id', entry)
id.text = self.__atom_id
title = xml_elem('title', entry)
if self.__atom_title_type is not None:
title = xml_elem('title', entry, type=self.__atom_title_type)
else:
title = xml_elem('title', entry)
title.text = self.__atom_title
updated = xml_elem('updated', entry)
updated.text = self.__atom_updated.isoformat()
Expand Down Expand Up @@ -260,7 +264,7 @@ def rss_entry(self, extensions=True):

return entry

def title(self, title=None):
def title(self, title=None, ttype=None):
'''Get or set the title value of the entry. It should contain a human
readable title for the entry. Title is mandatory for both ATOM and RSS
and should not be blank.
Expand All @@ -271,6 +275,9 @@ def title(self, title=None):
if title is not None:
self.__atom_title = title
self.__rss_title = title
if ttype not in ('text', 'html', 'xhtml', None):
raise ValueError('title type must be text, html, or xhtml')
self.__atom_title_type = ttype
return self.__atom_title

def id(self, id=None):
Expand Down