Removed AUTHOR defaulting to OS User /John Doe, so both a blank or undefined (None) author is possible.

Reverted templates back to checking author object, since a None object is possible. Name could be checked for blank if required
ATOM spec states an author element should be provided, so passes a blank name if not specified
Updated unit test
This commit is contained in:
Brendan Wholihan 2012-10-26 18:20:05 +01:00
commit f7a2f8ea47
7 changed files with 18 additions and 19 deletions

View file

@ -53,11 +53,6 @@ class Page(object):
if not hasattr(self, 'author'): if not hasattr(self, 'author'):
if 'AUTHOR' in settings: if 'AUTHOR' in settings:
self.author = Author(settings['AUTHOR'], settings) self.author = Author(settings['AUTHOR'], settings)
else:
title = filename.decode('utf-8') if filename else self.title
self.author = Author(getenv('USER', 'John Doe'), settings)
logger.warning(u"Author of `{0}' unknown, assuming that his name is "
"`{1}'".format(title, self.author))
# manage languages # manage languages
self.in_default_lang = True self.in_default_lang = True
@ -120,7 +115,7 @@ class Page(object):
'slug': getattr(self, 'slug', ''), 'slug': getattr(self, 'slug', ''),
'lang': getattr(self, 'lang', 'en'), 'lang': getattr(self, 'lang', 'en'),
'date': getattr(self, 'date', datetime.now()), 'date': getattr(self, 'date', datetime.now()),
'author': self.author, 'author': getattr(self, 'author', ''),
'category': getattr(self, 'category', 'misc'), 'category': getattr(self, 'category', 'misc'),
} }

View file

@ -223,12 +223,11 @@ class ArticlesGenerator(Generator):
"""Generate Author pages.""" """Generate Author pages."""
author_template = self.get_template('author') author_template = self.get_template('author')
for aut, articles in self.authors: for aut, articles in self.authors:
if aut.name: # ignore authors with blank names dates = [article for article in self.dates if article in articles]
dates = [article for article in self.dates if article in articles] write(aut.save_as, author_template, self.context,
write(aut.save_as, author_template, self.context, author=aut, articles=articles, dates=dates,
author=aut, articles=articles, dates=dates, paginated={'articles': articles, 'dates': dates},
paginated={'articles': articles, 'dates': dates}, page_name=u'author/%s' % aut)
page_name=u'author/%s' % aut)
def generate_drafts(self, write): def generate_drafts(self, write):
"""Generate drafts pages.""" """Generate drafts pages."""
@ -313,7 +312,9 @@ class ArticlesGenerator(Generator):
for article in self.articles: for article in self.articles:
# only main articles are listed in categories, not translations # only main articles are listed in categories, not translations
self.categories[article.category].append(article) self.categories[article.category].append(article)
self.authors[article.author].append(article) # ignore blank authors as well as undefined
if hasattr(article,'author') and article.author.name != '':
self.authors[article.author].append(article)
# sort the articles by date # sort the articles by date
self.articles.sort(key=attrgetter('date'), reverse=True) self.articles.sort(key=attrgetter('date'), reverse=True)

View file

@ -3,7 +3,7 @@
{{ article.locale_date }} {{ article.locale_date }}
</abbr> </abbr>
{% if article.author.name %} {% if article.author %}
<address class="vcard author"> <address class="vcard author">
By <a class="url fn" href="{{ SITEURL }}/{{ article.author.url }}">{{ article.author }}</a> By <a class="url fn" href="{{ SITEURL }}/{{ article.author.url }}">{{ article.author }}</a>
</address> </address>

View file

@ -10,7 +10,7 @@
<abbr class="published" title="{{ article.date.isoformat() }}"> <abbr class="published" title="{{ article.date.isoformat() }}">
{{ article.locale_date }} {{ article.locale_date }}
</abbr> </abbr>
{% if article.author.name %} {% if article.author %}
<address class="vcard author"> <address class="vcard author">
By <a class="url fn" href="{{ SITEURL }}/{{ article.author.url }}">{{ article.author }}</a> By <a class="url fn" href="{{ SITEURL }}/{{ article.author.url }}">{{ article.author }}</a>
</address> </address>

View file

@ -11,7 +11,7 @@
<header> <h2 class="entry-title"><a href="{{ SITEURL }}/{{ article.url }}" rel="bookmark" title="Permalink to {{ article.title}}">{{ article.title }}</a></h2> </header> <header> <h2 class="entry-title"><a href="{{ SITEURL }}/{{ article.url }}" rel="bookmark" title="Permalink to {{ article.title}}">{{ article.title }}</a></h2> </header>
<footer class="post-info"> <footer class="post-info">
<abbr class="published" title="{{ article.date.isoformat() }}"> {{ article.locale_date }} </abbr> <abbr class="published" title="{{ article.date.isoformat() }}"> {{ article.locale_date }} </abbr>
{% if article.author.name %}<address class="vcard author">By <a class="url fn" href="{{ SITEURL }}/{{ article.author.url }}">{{ article.author }}</a></address>{% endif %} {% if article.author %}<address class="vcard author">By <a class="url fn" href="{{ SITEURL }}/{{ article.author.url }}">{{ article.author }}</a></address>{% endif %}
</footer><!-- /.post-info --> </footer><!-- /.post-info -->
<div class="entry-content"> {{ article.summary }} </div><!-- /.entry-content --> <div class="entry-content"> {{ article.summary }} </div><!-- /.entry-content -->
</article></li> </article></li>

View file

@ -43,7 +43,7 @@ class Writer(object):
item.date.date(), item.url), item.date.date(), item.url),
description=item.content, description=item.content,
categories=item.tags if hasattr(item, 'tags') else None, categories=item.tags if hasattr(item, 'tags') else None,
author_name=getattr(item, 'author', 'John Doe'), author_name=getattr(item, 'author', ''),
pubdate=set_date_tzinfo(item.date, pubdate=set_date_tzinfo(item.date,
self.settings.get('TIMEZONE', None))) self.settings.get('TIMEZONE', None)))

View file

@ -40,8 +40,11 @@ class TestPage(unittest.TestCase):
def test_mandatory_properties(self): def test_mandatory_properties(self):
"""If the title is not set, must throw an exception.""" """If the title is not set, must throw an exception."""
self.assertRaises(AttributeError, Page, 'content') page = Page('content')
page = Page(**self.page_kwargs) with self.assertRaises(NameError) as cm:
page.check_properties()
page = Page('content', metadata={'title': 'foobar'})
page.check_properties() page.check_properties()
def test_summary_from_metadata(self): def test_summary_from_metadata(self):