# # Administrative page/endpoints for the home server. # import sys import logging import datetime import ezt from easydict import EasyDict as edict import util APP = sys.modules['__main__'].APP LOGGER = logging.getLogger(__name__) @APP.route('/admin') @APP.use_template('templates/admin.ezt') async def admin(): now = datetime.datetime.now() def format_day(t): "Format a day, given epoch seconds." d = now - (when := datetime.datetime.fromtimestamp(t)) #print('DELTA:', d, d.days) if d.days == 0: return 'today ' if d.days == 1: return 'yesterday' # Return 'DAY 01-01'. Note: same length as above. return when.strftime('%a %m-%d') def format_time(t): when = datetime.datetime.fromtimestamp(t) return when.strftime('%H:%M') logs = ( edict(day=format_day(log[0]), time=format_time(log[0]), t=log[0], action=log[1]) for log in APP.audit ) data = edict( message='message goes here', user='gstein', title='Administration', leftnav=util.build_active_leftnav('admin'), logs=tuple(logs), ) return data