From 01cc07b9feaf7dafb2f4700cb98601c5bbfa1eed Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Mon, 27 Apr 2020 09:30:08 +0200 Subject: [PATCH] change the general stats: display #alias, forward, reply, block --- app/dashboard/templates/dashboard/index.html | 40 ++++++-------------- app/dashboard/views/index.py | 21 ++++------ 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index 84ac698f..7c13861a 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -22,51 +22,35 @@ {% block default_content %}
-
+
-
{{ stats.nb_alias }}
-
Aliases
+
{{ stats.nb_alias }}
+
Aliases
-
+
-
{{ stats.nb_active_alias }}
-
Active Aliases
+
{{ stats.nb_forward }}
+
Forwards
-
+
-
{{ stats.nb_forward }}
-
Forwards
+
{{ stats.nb_reply }}
+
Replies
-
+
-
{{ stats.nb_reply }}
-
Replies
-
-
-
-
-
-
-
{{ stats.nb_directory }}
-
Directories
-
-
-
-
-
-
-
{{ stats.nb_domain }}
-
Domains
+
{{ stats.nb_block }}
+
Blocks
diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index 00c0ac9d..29772e13 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -24,33 +24,26 @@ from app.models import ( @dataclass class Stats: nb_alias: int - nb_active_alias: int nb_forward: int nb_reply: int - nb_domain: int - nb_directory: int + nb_block: int def get_stats(user: User) -> Stats: nb_alias = Alias.query.filter_by(user_id=user.id).count() - nb_active_alias = Alias.query.filter_by(user_id=user.id, enabled=True).count() nb_forward = EmailLog.query.filter_by( user_id=user.id, is_reply=False, blocked=False, bounced=False ).count() nb_reply = EmailLog.query.filter_by( user_id=user.id, is_reply=True, blocked=False, bounced=False ).count() - nb_domain = CustomDomain.query.filter_by(user_id=user.id).count() - nb_directory = Directory.query.filter_by(user_id=user.id).count() + nb_block = EmailLog.query.filter_by( + user_id=user.id, is_reply=False, blocked=True, bounced=False + ).count() - data = locals() - # to keep only Stats field - data = { - k: v - for (k, v) in data.items() - if k in vars(Stats)["__dataclass_fields__"].keys() - } - return Stats(**data) + return Stats( + nb_alias=nb_alias, nb_forward=nb_forward, nb_reply=nb_reply, nb_block=nb_block + ) @dashboard_bp.route("/", methods=["GET", "POST"])