Add period_num var for period_archives template

This makes it easier to create templates that are language-agnostic
or need extra processing for the date period.
This commit is contained in:
Petr Viktorin 2020-12-29 19:22:37 +01:00 committed by Justin Mayer
commit 487da3550b
3 changed files with 7 additions and 0 deletions

View file

@ -327,6 +327,8 @@ period A tuple of the form (`year`, `month`, `day`) that
given year. It contains both `year` and `month`
if the time period is over years and months and
so on.
period_num A tuple of the form (``year``, ``month``, ``day``),
as in ``period``, except all values are numbers.
=================== ===================================================

View file

@ -511,6 +511,7 @@ class ArticlesGenerator(CachingGenerator):
if key == period_date_key['year']:
context["period"] = (_period,)
context["period_num"] = (_period,)
else:
month_name = calendar.month_name[_period[1]]
if key == period_date_key['month']:
@ -520,6 +521,7 @@ class ArticlesGenerator(CachingGenerator):
context["period"] = (_period[0],
month_name,
_period[2])
context["period_num"] = tuple(_period)
write(save_as, template, context, articles=articles,
dates=archive, template_name='period_archives',

View file

@ -413,6 +413,7 @@ class TestArticlesGenerator(unittest.TestCase):
self.assertEqual(len(dates), 1)
# among other things it must have at least been called with this
context["period"] = (1970,)
context["period_num"] = (1970,)
write.assert_called_with("posts/1970/index.html",
generator.get_template("period_archives"),
context, blog=True, articles=articles,
@ -437,6 +438,7 @@ class TestArticlesGenerator(unittest.TestCase):
if d.date.year == 1970 and d.date.month == 1]
self.assertEqual(len(dates), 1)
context["period"] = (1970, "January")
context["period_num"] = (1970, 1)
# among other things it must have at least been called with this
write.assert_called_with("posts/1970/Jan/index.html",
generator.get_template("period_archives"),
@ -470,6 +472,7 @@ class TestArticlesGenerator(unittest.TestCase):
]
self.assertEqual(len(dates), 1)
context["period"] = (1970, "January", 1)
context["period_num"] = (1970, 1, 1)
# among other things it must have at least been called with this
write.assert_called_with("posts/1970/Jan/01/index.html",
generator.get_template("period_archives"),