etiquette/frontends/etiquette_flask/backend/endpoints/admin_endpoints.py
Ethan Dalool 4001f6f371
Use datetime objects instead of timestamps in object model.
Trying to make better use of objects in this object oriented language.
2022-07-20 19:03:26 -07:00

43 lines
1.2 KiB
Python

import flask; from flask import request
from voussoirkit import flasktools
import etiquette
from .. import common
site = common.site
session_manager = common.session_manager
####################################################################################################
@site.route('/admin')
def get_admin():
if not request.is_localhost:
flask.abort(403)
return common.render_template(request, 'admin.html')
@site.route('/admin/reload_config', methods=['POST'])
def post_reload_config():
if not request.is_localhost:
return flasktools.json_response({}, status=403)
common.P.load_config()
return flasktools.json_response({})
@site.route('/admin/dbdownload')
def get_dbdump():
if not request.is_localhost:
flask.abort(403)
with common.P.transaction:
binary = common.P.database_filepath.read('rb')
now = etiquette.helpers.now().strftime('%Y-%m-%d_%H-%M-%S')
download_as = f'etiquette {now}.db'
outgoing_headers = {
'Content-Type': 'application/octet-stream',
'Content-Disposition': f'attachment; filename*=UTF-8\'\'{download_as}',
}
return flask.Response(binary, headers=outgoing_headers)