From 772a2e735516e33bdba2c28adc616f0c4dc3adc0 Mon Sep 17 00:00:00 2001
From: Son NK <>
Date: Wed, 30 Sep 2020 12:20:18 +0200
Subject: [PATCH] add "export alias" button
---
.../templates/dashboard/setting.html | 21 +++++++++++++---
app/dashboard/views/setting.py | 25 +++++++++++++++++--
2 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/app/dashboard/templates/dashboard/setting.html b/app/dashboard/templates/dashboard/setting.html
index b9e11bea..034bd587 100644
--- a/app/dashboard/templates/dashboard/setting.html
+++ b/app/dashboard/templates/dashboard/setting.html
@@ -315,10 +315,23 @@
You can download all aliases you have created on SimpleLogin along with other data.
-
+
+
+
+
diff --git a/app/dashboard/views/setting.py b/app/dashboard/views/setting.py
index 5b0e79b2..2282285d 100644
--- a/app/dashboard/views/setting.py
+++ b/app/dashboard/views/setting.py
@@ -1,8 +1,17 @@
+import csv
import json
-from io import BytesIO
+from io import BytesIO, StringIO
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_wtf import FlaskForm
from flask_wtf.file import FileField
@@ -270,6 +279,18 @@ def setting():
mimetype="text/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)
return render_template(