add page modified time to the template
This commit is contained in:
parent
75f8488fc3
commit
04145e92f8
@ -1,8 +1,11 @@
|
||||
"""General page functionality."""
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
|
||||
import markdown
|
||||
from flask import Blueprint, Markup, abort, current_app as app, render_template
|
||||
from tzlocal import get_localzone
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -19,6 +22,7 @@ def display_page(path):
|
||||
try:
|
||||
with app.open_instance_resource(resolved_path, 'r') as entry_file:
|
||||
logger.debug("file '%s' found", resolved_path)
|
||||
mtime = datetime.datetime.fromtimestamp(os.path.getmtime(entry_file.name), get_localzone())
|
||||
entry = entry_file.read()
|
||||
except FileNotFoundError:
|
||||
logger.warning("requested path '%s' (resolved path '%s') not found!", path, resolved_path)
|
||||
@ -27,7 +31,7 @@ def display_page(path):
|
||||
content = Markup(md.convert(entry))
|
||||
logger.debug("file metadata: %s", md.Meta)
|
||||
title = " ".join(md.Meta.get('title')) if md.Meta.get('title') else ""
|
||||
return render_template('base.html', title=title, content=content)
|
||||
return render_template('base.html', title=title, content=content, mtime=mtime.strftime('%Y-%m-%d %H:%M:%S %Z'))
|
||||
|
||||
|
||||
def page_file_resolver(path):
|
||||
|
@ -3,3 +3,6 @@
|
||||
<section class="content">
|
||||
{{ content }}
|
||||
</section>
|
||||
<footer>
|
||||
<i>Last modified: {{ mtime }}</i>
|
||||
</footer>
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Test page views and helper methods."""
|
||||
import re
|
||||
|
||||
from incorporealcms.pages import page_file_resolver
|
||||
|
||||
|
||||
@ -36,3 +38,9 @@ def test_page_without_title_metadata(client):
|
||||
assert response.status_code == 200
|
||||
assert b'<title>incorporeal.org</title>' in response.data
|
||||
assert b'<h1>this page doesn\'t have a title!</h1>' in response.data
|
||||
|
||||
|
||||
def test_page_has_modified_timestamp(client):
|
||||
response = client.get('/')
|
||||
assert response.status_code == 200
|
||||
assert re.search(r'Last modified: ....-..-.. ..:..:.. ...', response.data.decode()) is not None
|
||||
|
Loading…
Reference in New Issue
Block a user