add "export alias" button
This commit is contained in:
parent
8ed619687f
commit
772a2e7355
|
@ -315,10 +315,23 @@
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
You can download all aliases you have created on SimpleLogin along with other data.
|
You can download all aliases you have created on SimpleLogin along with other data.
|
||||||
</div>
|
</div>
|
||||||
<form method="post">
|
|
||||||
<input type="hidden" name="form-name" value="export-data">
|
<div class="d-flex">
|
||||||
<button class="btn btn-outline-info">Export Data</button>
|
<div>
|
||||||
</form>
|
<form method="post">
|
||||||
|
<input type="hidden" name="form-name" value="export-data">
|
||||||
|
<button class="btn btn-outline-info">Export Data</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="ml-5">
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="form-name" value="export-alias">
|
||||||
|
<button class="btn btn-outline-primary">Export Aliases</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
|
import csv
|
||||||
import json
|
import json
|
||||||
from io import BytesIO
|
from io import BytesIO, StringIO
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
from flask import render_template, request, redirect, url_for, flash, Response
|
from flask import (
|
||||||
|
render_template,
|
||||||
|
request,
|
||||||
|
redirect,
|
||||||
|
url_for,
|
||||||
|
flash,
|
||||||
|
Response,
|
||||||
|
make_response,
|
||||||
|
)
|
||||||
from flask_login import login_required, current_user, logout_user
|
from flask_login import login_required, current_user, logout_user
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from flask_wtf.file import FileField
|
from flask_wtf.file import FileField
|
||||||
|
@ -270,6 +279,18 @@ def setting():
|
||||||
mimetype="text/json",
|
mimetype="text/json",
|
||||||
headers={"Content-Disposition": "attachment;filename=data.json"},
|
headers={"Content-Disposition": "attachment;filename=data.json"},
|
||||||
)
|
)
|
||||||
|
elif request.form.get("form-name") == "export-alias":
|
||||||
|
data = [["alias", "note", "enabled"]]
|
||||||
|
for alias in Alias.filter_by(user_id=current_user.id).all(): # type: Alias
|
||||||
|
data.append([alias.email, alias.note, alias.enabled])
|
||||||
|
|
||||||
|
si = StringIO()
|
||||||
|
cw = csv.writer(si)
|
||||||
|
cw.writerows(data)
|
||||||
|
output = make_response(si.getvalue())
|
||||||
|
output.headers["Content-Disposition"] = "attachment; filename=aliases.csv"
|
||||||
|
output.headers["Content-type"] = "text/csv"
|
||||||
|
return output
|
||||||
|
|
||||||
manual_sub = ManualSubscription.get_by(user_id=current_user.id)
|
manual_sub = ManualSubscription.get_by(user_id=current_user.id)
|
||||||
return render_template(
|
return render_template(
|
||||||
|
|
Loading…
Reference in a new issue