Add /admin/dbdownload.
This commit is contained in:
parent
0e00a1e981
commit
49992f59aa
2 changed files with 21 additions and 1 deletions
|
@ -2,6 +2,8 @@ import flask; from flask import request
|
||||||
|
|
||||||
from voussoirkit import flasktools
|
from voussoirkit import flasktools
|
||||||
|
|
||||||
|
import etiquette
|
||||||
|
|
||||||
from .. import common
|
from .. import common
|
||||||
|
|
||||||
site = common.site
|
site = common.site
|
||||||
|
@ -23,3 +25,19 @@ def post_reload_config():
|
||||||
|
|
||||||
common.P.load_config()
|
common.P.load_config()
|
||||||
return flasktools.json_response({})
|
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(timestamp=False).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)
|
||||||
|
|
|
@ -21,7 +21,9 @@
|
||||||
{{header.make_header(session=session)}}
|
{{header.make_header(session=session)}}
|
||||||
<div id="content_body">
|
<div id="content_body">
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
<button id="reload_config_button" class="green_button" onclick="return reload_config_form();">Reload config file</button>
|
<h1>Admin tools</h1>
|
||||||
|
<p><button id="reload_config_button" class="green_button" onclick="return reload_config_form();">Reload config file</button></p>
|
||||||
|
<p><a href="/admin/dbdownload">Download database file</a></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue