Skip to content

Commit

Permalink
Merge pull request getpelican#1959 from MrSenko/default-date
Browse files Browse the repository at this point in the history
Accept string dates in DEFAULT_DATE. Fixes getpelican#1464; fixes getpelican#1476
  • Loading branch information
justinmayer committed May 24, 2016
2 parents 2ceeb88 + 3f2d89c commit d9605d0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Setting name (followed by default value, if any)
If ``'fs'``, Pelican will use the file system
timestamp information (mtime) if it can't get
date information from the metadata.
If given any other string, it will be parsed by the same method
as article metadata.
If set to a tuple object, the default datetime object will instead
be generated by passing the tuple to the
``datetime.datetime`` constructor.
Expand Down
5 changes: 4 additions & 1 deletion pelican/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,10 @@ def default_metadata(settings=None, process=None):
metadata['category'] = value
if settings.get('DEFAULT_DATE', None) and \
settings['DEFAULT_DATE'] != 'fs':
metadata['date'] = SafeDatetime(*settings['DEFAULT_DATE'])
if isinstance(settings['DEFAULT_DATE'], six.string_types):
metadata['date'] = get_date(settings['DEFAULT_DATE'])
else:
metadata['date'] = SafeDatetime(*settings['DEFAULT_DATE'])
return metadata


Expand Down
9 changes: 9 additions & 0 deletions pelican/tests/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,15 @@ def test_article_with_multiple_authors_list(self):

self.assertDictHasSubset(page.metadata, expected)

def test_default_date_formats(self):
tuple_date = self.read_file(path='article.rst',
DEFAULT_DATE=(2012, 5, 1))
string_date = self.read_file(path='article.rst',
DEFAULT_DATE='2012-05-01')

self.assertEqual(tuple_date.metadata['date'],
string_date.metadata['date'])


@unittest.skipUnless(readers.Markdown, "markdown isn't installed")
class MdReaderTest(ReaderTest):
Expand Down

0 comments on commit d9605d0

Please sign in to comment.