Browse Source

Link to search and prev/next day logs on log pages at the top and bottom

master
JustAnotherArchivist 3 years ago
parent
commit
2757326c72
1 changed files with 9 additions and 3 deletions
  1. +9
    -3
      irclog.py

+ 9
- 3
irclog.py View File

@@ -945,6 +945,11 @@ class WebServer:
date = datetime.datetime.strptime(request.match_info['date'], '%Y-%m-%d').replace(tzinfo = datetime.timezone.utc)
dateStart = date.timestamp()
dateEnd = (date + datetime.timedelta(days = 1)).timestamp()
channelLinks = ' '.join([
f'<a href="/{html.escape(request.match_info["path"])}/search">Search</a>',
f'<a href="/{html.escape(request.match_info["path"])}/{(date - datetime.timedelta(days = 1)).strftime("%Y-%m-%d")}">Previous day</a>',
f'<a href="/{html.escape(request.match_info["path"])}/{(date + datetime.timedelta(days = 1)).strftime("%Y-%m-%d")}">Next day</a>',
])
#TODO Implement this in a better way...
fn = date.strftime('%Y-%m.log')
lines = list(self._raw_to_lines(self._file_iter_with_path(os.path.join(self.config['storage']['path'], request.match_info["path"], fn), request.match_info["path"]), filter = lambda path, ts, command, content: dateStart <= ts <= dateEnd))
@@ -953,10 +958,11 @@ class WebServer:
'<!DOCTYPE html><html lang="en">',
f'<head><title>{html.escape(self._paths[request.match_info["path"]][0])} log for {date:%Y-%m-%d}</title>{self.logStyleTag}</head>',
'<body>',
f'<a href="/{html.escape(request.match_info["path"])}/{(date - datetime.timedelta(days = 1)).strftime("%Y-%m-%d")}">Previous day</a> ',
f'<a href="/{html.escape(request.match_info["path"])}/{(date + datetime.timedelta(days = 1)).strftime("%Y-%m-%d")}">Next day</a>',
'<br /><br />',
f'<p>{channelLinks}</p>',
'<hr />',
self._render_log(lines),
'<hr />',
f'<p>{channelLinks}</p>',
'</body>',
'</html>',
]),


Loading…
Cancel
Save