From 94877e033b37e4d226528af935f45d4119f283d6 Mon Sep 17 00:00:00 2001 From: Brendan Wholihan Date: Thu, 18 Oct 2012 19:55:00 +0100 Subject: [PATCH 1/2] So that Authors display and output can be disabled for single user sites, allow the AUTHOR setting to be set to an empty string ''. An author is needed, but was defaults to OS user, or 'John Doe'. If a blank author is provided, it generated authors/.html file, and templates display just "by " Updated generators.py and templates to ignore Authors objects which have a blank name --- pelican/generators.py | 11 ++++++----- pelican/themes/notmyidea/templates/article_infos.html | 2 +- pelican/themes/simple/templates/article.html | 2 +- pelican/themes/simple/templates/index.html | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pelican/generators.py b/pelican/generators.py index 461c8b46..3056d6f7 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -223,11 +223,12 @@ class ArticlesGenerator(Generator): """Generate Author pages.""" author_template = self.get_template('author') for aut, articles in self.authors: - dates = [article for article in self.dates if article in articles] - write(aut.save_as, author_template, self.context, - author=aut, articles=articles, dates=dates, - paginated={'articles': articles, 'dates': dates}, - page_name=u'author/%s' % aut) + if aut.name: # ignore authors with blank names + dates = [article for article in self.dates if article in articles] + write(aut.save_as, author_template, self.context, + author=aut, articles=articles, dates=dates, + paginated={'articles': articles, 'dates': dates}, + page_name=u'author/%s' % aut) def generate_drafts(self, write): """Generate drafts pages.""" diff --git a/pelican/themes/notmyidea/templates/article_infos.html b/pelican/themes/notmyidea/templates/article_infos.html index a1993a09..78326fd1 100644 --- a/pelican/themes/notmyidea/templates/article_infos.html +++ b/pelican/themes/notmyidea/templates/article_infos.html @@ -3,7 +3,7 @@ {{ article.locale_date }} - {% if article.author %} + {% if article.author.name %}
By {{ article.author }}
diff --git a/pelican/themes/simple/templates/article.html b/pelican/themes/simple/templates/article.html index 16c34266..349b3107 100644 --- a/pelican/themes/simple/templates/article.html +++ b/pelican/themes/simple/templates/article.html @@ -10,7 +10,7 @@ {{ article.locale_date }} - {% if article.author %} + {% if article.author.name %}
By {{ article.author }}
diff --git a/pelican/themes/simple/templates/index.html b/pelican/themes/simple/templates/index.html index dfdb0b45..ec278c4b 100644 --- a/pelican/themes/simple/templates/index.html +++ b/pelican/themes/simple/templates/index.html @@ -11,7 +11,7 @@

{{ article.title }}

{{ article.summary }}
From f7a2f8ea479437050af56995e5dd7767e4429b91 Mon Sep 17 00:00:00 2001 From: Brendan Wholihan Date: Fri, 26 Oct 2012 18:20:05 +0100 Subject: [PATCH 2/2] 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 --- pelican/contents.py | 7 +------ pelican/generators.py | 15 ++++++++------- .../themes/notmyidea/templates/article_infos.html | 2 +- pelican/themes/simple/templates/article.html | 2 +- pelican/themes/simple/templates/index.html | 2 +- pelican/writers.py | 2 +- tests/test_contents.py | 7 +++++-- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index b5701732..17801cc1 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -53,11 +53,6 @@ class Page(object): if not hasattr(self, 'author'): if 'AUTHOR' in 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 self.in_default_lang = True @@ -120,7 +115,7 @@ class Page(object): 'slug': getattr(self, 'slug', ''), 'lang': getattr(self, 'lang', 'en'), 'date': getattr(self, 'date', datetime.now()), - 'author': self.author, + 'author': getattr(self, 'author', ''), 'category': getattr(self, 'category', 'misc'), } diff --git a/pelican/generators.py b/pelican/generators.py index 3056d6f7..f385ea45 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -223,12 +223,11 @@ class ArticlesGenerator(Generator): """Generate Author pages.""" author_template = self.get_template('author') 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] - write(aut.save_as, author_template, self.context, - author=aut, articles=articles, dates=dates, - paginated={'articles': articles, 'dates': dates}, - page_name=u'author/%s' % aut) + dates = [article for article in self.dates if article in articles] + write(aut.save_as, author_template, self.context, + author=aut, articles=articles, dates=dates, + paginated={'articles': articles, 'dates': dates}, + page_name=u'author/%s' % aut) def generate_drafts(self, write): """Generate drafts pages.""" @@ -313,7 +312,9 @@ class ArticlesGenerator(Generator): for article in self.articles: # only main articles are listed in categories, not translations 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 self.articles.sort(key=attrgetter('date'), reverse=True) diff --git a/pelican/themes/notmyidea/templates/article_infos.html b/pelican/themes/notmyidea/templates/article_infos.html index 78326fd1..a1993a09 100644 --- a/pelican/themes/notmyidea/templates/article_infos.html +++ b/pelican/themes/notmyidea/templates/article_infos.html @@ -3,7 +3,7 @@ {{ article.locale_date }} - {% if article.author.name %} + {% if article.author %}
By {{ article.author }}
diff --git a/pelican/themes/simple/templates/article.html b/pelican/themes/simple/templates/article.html index 349b3107..16c34266 100644 --- a/pelican/themes/simple/templates/article.html +++ b/pelican/themes/simple/templates/article.html @@ -10,7 +10,7 @@ {{ article.locale_date }} - {% if article.author.name %} + {% if article.author %}
By {{ article.author }}
diff --git a/pelican/themes/simple/templates/index.html b/pelican/themes/simple/templates/index.html index ec278c4b..dfdb0b45 100644 --- a/pelican/themes/simple/templates/index.html +++ b/pelican/themes/simple/templates/index.html @@ -11,7 +11,7 @@

{{ article.title }}

{{ article.summary }}
diff --git a/pelican/writers.py b/pelican/writers.py index 65f0b338..b9ce77c4 100644 --- a/pelican/writers.py +++ b/pelican/writers.py @@ -43,7 +43,7 @@ class Writer(object): item.date.date(), item.url), description=item.content, 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, self.settings.get('TIMEZONE', None))) diff --git a/tests/test_contents.py b/tests/test_contents.py index 6b0f93ea..8683d674 100644 --- a/tests/test_contents.py +++ b/tests/test_contents.py @@ -40,8 +40,11 @@ class TestPage(unittest.TestCase): def test_mandatory_properties(self): """If the title is not set, must throw an exception.""" - self.assertRaises(AttributeError, Page, 'content') - page = Page(**self.page_kwargs) + page = Page('content') + with self.assertRaises(NameError) as cm: + page.check_properties() + + page = Page('content', metadata={'title': 'foobar'}) page.check_properties() def test_summary_from_metadata(self):